PlayBook: debug trace() statements


Posted:   |  More posts about PlayBook debugging AIR

When debugging AIR apps in the PlayBook simulator, you build your app using the -debug option to the amxmlc compiler... or your IDE does it for you. With that flag, and appropriate options passed to blackberry-airpackager (specifically -target bar-debug) and blackberry-deploy (-debugHost X.X.X.X), your app will attempt to connect to the debugger running at the specified address, and among other useful things you'll be able to see the output of your trace() calls.

But what if you decide to cancel the debug session, or just never start it, and only then find a problem with your app? You might have to restart, this time connecting to the debugger. This is never a good situation, and you'll be lucky if you can reproduce the problem.

Fortunately, if the app was compiled with the debug flag, and if you included the -devMode option when you packaged, your trace() output is available anyway.

First, connect using SSH. Change directories with cd /accounts/1000/appdata, then type ls to list the subfolders. Find the one for your app and change into it with another cd command.

The -devMode option is what allows you to do this, as without it the sandbox is protected from other users, including the one you've connected with ("devuser"). With this option the app is installed under one of six special user groups, named dev0 through dev5, and devuser is a member of each of those groups. (Note the devMode bug which may interfere with this if you have installed more than 6 apps using -devMode.)

In the app sandbox there are several subfolders. Three of them, data/, logs/ and tmp/ are created when the app is installed, while four symlinks (app, db, pps, shared) are created the first time the app is launched.

The output of the trace() calls is recorded in the file logs/air-trace, provided you used -debug when compiling. (If you did not, those statements are stripped out, taking up no space or CPU time in "release mode" apps.)

The best way to view the file for a running app is this command (with the dollar sign being the command line prompt, so don't type it):

$ tail -f air-trace
XMLList:
extensionsDeviceBundledDirectory is null
app:/META-INF/AIR/extensions
Extensions to load: 0

The next four lines shown are the output I see with my own app. I assume you'll see the same, as those are not from my own trace() calls.

If you want more help on the tail command, type use tail. Note above that I've used the -f option, which makes tail stay running so it shows new lines as they are appended by your app. Hit Ctrl-C to get back to the prompt. Note also that if you exit the app and restart it, tail doesn't notice that a new air-trace file has been created so it won't switch to it automatically and you won't see any more output until you run tail again.

If your app has crashed and you just want to see the full file contents, use cat air-trace to dump it to the console. You could also use sftp or scp to transfer the file to your host machine.

Comments powered by Disqus