Wednesday, September 16, 2009

Palm Pre - First Pass in Debugging

The Palm® Pre was introduced a couple of months ago with much fanfare and touted easy development via HTML, Javascript, and CSS. This, of course, meant that the number of potential developers was much higher than for something like the iPhone. This piqued my interest as well as it being the underdog to the already established iPhone. I had a few questions at this point. What kind of development environment did it have? As a fellow Rogue, the first step is to head to the developer.palm.com page and get the SDK. The product is just too new to get any kind of reliable answers on the ease of development for this platform.

There are a few tools needed before doing much. I don’t use IDE’s in general but I did download Eclipse. It simply made life easier in launching my test application.   (I decided to use Windows rather than Linux since my Linux version is pretty old on my laptop and I don’t want to change it just for this.) The best resource is simply to go to developer.palm.com and grab the SDK and all the tools/plugins, etc. You’ll need ssh - I use putty which you can get from www.chiark.greenend.org.uk. Set the host to 127.0.0.1, port to 5522 and a dos command window will popup. In here you login as root with no password (just hit enter).  The tool novacom can be used as well to issue commands.  This comes with the SDK.

Log into the emulator - login name: root, no password.  There are a couple of tools to use; the Palm Debugger - a gdb-style debugger creatively called ‘debug’ and the debug log output. Palm’s developer site has details on the usage of the debug tool. The file ‘/var/log/messages’ contains the debug output or simply use tail -f /var/log/messages to see them scroll by as it is running. Log output is highly valuable but since this is Javascript, you may not get any output if there is an error in the code.

Using the Palm Debugger was less than satisfying. Getting output for simple errors with no information on finding those errors is almost worse than nothing at all. Almost. For instance, leaving an else off of an if statement gets you this (at least in my case):
Uncaught: SyntaxError: Unexpected token else - (empty stack)
This is a clue as to what’s happening. In a small program, it would be trivial but in a larger program, it’s almost no help. However, when the debugger is running, the output in /var/log/messages does contain the necessary info the find the error.

2009-09-15T06:02:54.138411Z [3581] qemux86 user.err LunaSysMgr: {LunaSysMgrJS} com.yourapp.compass: Uncaught SyntaxError: Unexpected token else, file:///var/usr/palm/applications/com.yourapp.compass/app/assistants/compass-assistant.js:29

I certainly hope Palm puts some development into the debugger. Tab completion, easy breakpoints rather than full path, and output that is complete would be a good start. Your application source resides in /var/usr/palm/applications. You’ll need to get a full path to the script then line number to issue a breakpoint. Some commands like list won’t put out any info until you hit a breakpoint. There aren’t many commands but enough to do the job. You’ll probably find yourself relying on logging rather than the debugger as I did.

The Inspector requires a few flags to be set and is rather finicky to use. To set it up, first run the emulator then Eclipse and open your project. Under the run menu, select Debug Configurations and make sure ‘Inspectable’ is selected.  I would enable 'Mojo Debugging' as well.  Alternatively, you can run the command line. 



The -i in the command turns on the Inspectable flag while the rest of the command turns on Mojo debugging.  Save and run the debug configuration. At this point, you can run the Inspector. Here is a sample of what it looks like.



The emulator reset a number of times while trying to use the Inspector.  There are notes on the Palm developer site about it crashing while trying to use it. You can modify elements as well if you don't mind the occasional detrimental effects forcing a relaunch.  I found between the crashing and long delays in views that it just wasn't all that useful.

In summary, the Pre looks interesting as a platform and might even be easy to develop on if the tools were better. For now, if you can do your development outside of the device, you’ll be much better off.  The documentation is light and spread out so it does take a bit of effort to get going on it.  This gets easier pretty quickly.  Of course, the Palm webOS book offers a good start. It’s certainly worth getting to help bootstrap applications although not required by any means.

The Software Rogue - http://thesoftwarerogue.blogspot.com

No comments:

Post a Comment