You Are Here:

Community: Developer Discussion Boards

#1 Old How do you debug stand-alone apps? - 2006-11-05, 05:01

Join Date: Oct 2006
Posts: 12
sjh
Offline
Registered User
How do people here debug stand-alone apps? I have an app that is a whole tree of files, so running it as a script is out. I build and run it as a sis, but when it dies I don't get to see the stack trace. Is there some trick to turn on the ability to see errors from the python interpreter?

-Seth
Reply With Quote

#2 Old Re: How do you debug stand-alone apps? - 2006-11-05, 09:53

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
To mimick a stack trace of the Python Script Shell, enclose your stand-alone program in a construct similar to this:

Code:
# Exception harness for "Python for S60" stand-alone programs

try:
    # Actual program is here.
    1 / 0
except:
    import sys
    import traceback
    import e32
    import appuifw
    appuifw.app.screen = "normal"               # Restore screen to normal size.
    appuifw.app.focus = None                    # Disable focus callback.
    body = appuifw.Text()
    appuifw.app.body = body                     # Create and use a text control.
    exitlock = e32.Ao_lock()
    def exithandler(): exitlock.signal()
    appuifw.app.exit_key_handler = exithandler  # Override softkey handler.
    appuifw.app.menu = [(u"Exit", exithandler)] # Override application menu.
    body.set(unicode("\n".join(traceback.format_exception(*sys.exc_info()))))
    exitlock.wait()                             # Wait for exit key press.
    appuifw.app.set_exit()
Reply With Quote

#3 Old Re: How do you debug stand-alone apps? - 2006-11-07, 20:04

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
One option is to use file logger utility, see this post for details: http://discussion.forum.nokia.com/fo...57&postcount=3
Reply With Quote

#4 Old Re: How do you debug stand-alone apps? - 2008-05-07, 00:20

Join Date: Feb 2004
Posts: 155
Location: Budapest, Hungary, Europe
tote_b5's Avatar
tote_b5
Offline
Forum Nokia Champion
I have a slightly different problem: my PyS60 stand-alone app doesn't start at all. The application was assembled using Ensymble and it contains Python scripts as well as embedded SIS files. I've just added logging support to it and I'm afraid it's just that that causes it to malfunction.

Since logging does not work I cannot debug it. Now how shall I interpret jethro.fn's sentence: "...enclose your stand-alone program in a construct similar to this"? What to enclose? My stand-alone app naturally contains a default.py file, but it contains other files, too. Again, what to enclose? And am I right when I assume that I'll be unable to see any output? In which application's context would it be displayed (mine is crashing)?

Thanks,

Tote
Reply With Quote

#5 Old Re: How do you debug stand-alone apps? - 2008-05-07, 05:18

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Technically you should put the exception harness around the code in your main .py file (the one that is used to create the sis file using Ensymble's py2sis) if you have just one such file. At least I think so...

And if you haven't already, see this article. It might help a bit.
Reply With Quote

#6 Old Re: How do you debug stand-alone apps? - 2008-05-07, 10:14

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by tote_b5 View Post
I have a slightly different problem: my PyS60 stand-alone app doesn't start at all. The application was assembled using Ensymble and it contains Python scripts as well as embedded SIS files. I've just added logging support to it and I'm afraid it's just that that causes it to malfunction.

Since logging does not work I cannot debug it. Now how shall I interpret jethro.fn's sentence: "...enclose your stand-alone program in a construct similar to this"? What to enclose? My stand-alone app naturally contains a default.py file, but it contains other files, too. Again, what to enclose? And am I right when I assume that I'll be unable to see any output? In which application's context would it be displayed (mine is crashing)?

Thanks,

Tote
hi everybody
the method suggested by jethro.fn is a nice one and the best way which work for me is the exception harness method which is best ported in the wiki
have a look at that


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#7 Old Re: How do you debug stand-alone apps? - 2008-05-07, 11:24

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by sjh View Post
How do people here debug stand-alone apps? I have an app that is a whole tree of files, so running it as a script is out. I build and run it as a sis, but when it dies I don't get to see the stack trace. Is there some trick to turn on the ability to see errors from the python interpreter?
I have used tracing on hardware. Creates a huge log file, but it's worth the trouble. As an example of how to enable tracing, please download my Random Test and look inside. It's not too long and code should be pretty self-documenting.

I'll rewrite it later,

--jouni
Reply With Quote

#8 Old Re: How do you debug stand-alone apps? - 2008-05-07, 23:33

Join Date: Feb 2004
Posts: 155
Location: Budapest, Hungary, Europe
tote_b5's Avatar
tote_b5
Offline
Forum Nokia Champion
Okay, I spotted it! I used multi-line comments (triple apostrophes/quotes) at the beginning of a function and that confused everything. After removing it (and only that part!) my program now works.

The thing is that I couldn't debug it at all in the traditional way: couldn't show a dialog, write anything to file, nothing. The biggest problem was that my program went crazy at the very beginning of the execution, I guess there must be a validator somewhere "who" decides if a Python script is syntactically correct or not. Mine wasn't.

So everybody, please learn from my mistake! I would be happier if I hadn't wasted couple of hours struggling to find this pity error.

Cheers,

Tote
Reply With Quote

#9 Old Re: How do you debug stand-alone apps? - 2008-05-08, 08:09

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by tote_b5 View Post
The thing is that I couldn't debug it at all in the traditional way: couldn't show a dialog, write anything to file, nothing. The biggest problem was that my program went crazy at the very beginning of the execution, I guess there must be a validator somewhere "who" decides if a Python script is syntactically correct or not.
That's called Static Code Analysis, one of my favorites

Short version:

- Install python 2.5
- Install pylint
- Run pylint on command line to check your PyS60 script
- Fix the errors and warnings, I mean really do it
- Redefine rule set by first writing defaults on file and then editing that

I'll write tutorial one of these days, but I'm using it and it works.

Cheers,

--jouni
Reply With Quote

#10 Old Re: How do you debug stand-alone apps? - 2008-05-08, 09:58

Join Date: Feb 2004
Posts: 155
Location: Budapest, Hungary, Europe
tote_b5's Avatar
tote_b5
Offline
Forum Nokia Champion
Quote:
Originally Posted by JOM View Post
That's called Static Code Analysis, one of my favorites

Short version:

- Install python 2.5
- Install pylint
- Run pylint on command line to check your PyS60 script
- Fix the errors and warnings, I mean really do it
- Redefine rule set by first writing defaults on file and then editing that

I'll write tutorial one of these days, but I'm using it and it works.

Cheers,

--jouni
Looking forward to the tutorial, Jouni! And thanks for the tip, I will check it out soon!

Btw, is the following URL for pylint correct: http://www.logilab.org/857 ?

Tote
Reply With Quote

#11 Old Re: How do you debug stand-alone apps? - 2008-05-09, 00:21

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by tote_b5 View Post
Btw, is the following URL for pylint correct: http://www.logilab.org/857 ?
Seems to be, don't forget to install the dependencies first. Easy install didn't work for me, had to do it all manually.

Good luck,

--jouni
Reply With Quote

#12 Old Re: How do you debug stand-alone apps? - 2008-05-09, 23:02

Join Date: Jul 2007
Posts: 4
Sean94
Offline
Registered User
I debug using appuifw.query.
sys.stderr=lambda x: appuifw.query(x, "query")
Reply With Quote

#13 Old Re: How do you debug stand-alone apps? - 2008-05-11, 22:19

Join Date: Jan 2007
Posts: 135
Location: Oulu, Finland
GameDude
Offline
Regular Contributor
I just checked in my serial logging tool, LogMan. Check it out from:
http://code.google.com/p/logman-for-symbian/

Announcement is here.

LogMan is a logging service running on Symbian phone intended for debugging tasks. The service allows one to send messages through a USB serial connection to PC. Other serial connection methods should work also, but are not supported. Infrared(IrComm), for example. On Symbian simulator, the messages are also logged to %TEMP%\epocwind.out by using RDebug logger.

Code:
How to use 'print' with LogMan.
===============================

import sys, pylogman
l = pylogman.LogMan()
l.Connect()
# Replace standard output with LogMan's write method.
sys.stdout.write = l.write

print "Hello!" # 'Hello' is sent to PC
Exceptions are sent automatically to PC and all debug logging is shown in real-time... which is quite nice
Last edited by GameDude : 2008-05-13 at 09:45. Reason: Added announcement link
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
How to debug console application with CW3.1 and 3rd edition ? 3rdparty Mobile Java Tools & SDKs 0 2006-02-01 18:40
set apps to be run background manually Rx-lee General Symbian C++ 2 2004-09-14 09:58
WAP upload / Content-Type header is lost at WAP gateway rabai Symbian Networking & Messaging 2 2004-02-24 12:59
using th debug monitor evertse General Symbian C++ 0 2003-10-22 09:24
WAP Push Support in Series 60 Devices yorgens General Browsing 3 2003-06-11 09:20

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia