Wednesday, August 19, 2009

Invaluable iPhone debugging help in the Xcode Organizer

Debugging is never much fun. Fortunately, most of the time you can run your program when it's attached to the debugger and get a detailed view into what's going on. Even when the debugger isn't able to give you a good window into the problem, the iPhone SDK provides the uber-handy NSLog() function to do good old fashioned printf()-style debugging.

Sometimes you need to test your code on a real device that's detached from your development system because you're testing out in the field or you're working with the External Accessory Framework and you need use the 30 pin connector to talk to the accessory. Fortunately the Xcode Organizer provides you with some help here.
You've no doubt used the Summary tab to set up your development devices. There's a few more goodies here you might not have noticed (I hadn't until recently). The Crash Logs tab, while not as informative as the debugger, can at least show you the call stack at the time your app crashes, along with method names, file names and line numbers.
The crash log information can be a bit overwhelming if you're not used to it, but it's worth spending a few minutes looking closely at it if you're trying to diagnose a crash.

The Console tab can be just as confusing at first, but shows you not only the NSLog() output from your app but handy system messages as well.
The Console seems to only store a couple of hundred log messages, so don't go crazy with NSLog(), but it can be incredibly handy in narrowing down or confirming the cause of a crash when your device is not connected to Xcode.

No comments: