Getting a useful stack trace from NSException#callStackReturnAddresses
Its always been a little painful when you get an exception and the debugger decides not to cooperate, leaving you with something like:

Thanks!
As far as I could work out, traditional methods of grabbing a symbolic stack trace don’t work on the iPhone. (If I am remembering right, I don’t think NSStackTraceKey exists in UIKit.)
A little while ago I hacked the GTMStackTrace from google-toolbox-for-mac, to lookup the symbolic stack trace from the call stack return addresses (NSException#callStackReturnAddresses introduced in 10.5) and print it out using NSSetUncaughtExceptionHandler. Life has been a little bit easier ever since. Thankfully, the awesome people who work on GTM added it in themselves (see GTMStackTrace.h#61). Here is how you might set it up, in main.m:
For me, DEBUG is set in GCC_PREPROCESSOR_DEFINITIONS via the awesome GTM xcconfg files, which you should also be using. Hopefully, you should get a trace that looks like:
And the source of the exception usually starts around the 5th line.
December 30th, 2008 at 10:11 pm
Hi,
This would be great! How can I get GTM set up in my iPhone app (with as small a footprint as possible please).
Thanks
January 11th, 2009 at 7:47 pm
[...] Hanford posted a great example of using the Google Toolbox for Mac to print human readable stack [...]
January 30th, 2009 at 9:20 pm
Actually, atos works for the iPhone, at least when you have a debug binary of your app.
For those times when the debugger doesn’t play nice, you can use the cryptic stack trace: take the lower addresses (usually, as in the example above, those that are five or six digits long) that actually correspond to your symbols (as opposed to the system functions that are using much higher addresses), convert to hex and run atos with ‘-arch armv6′ on the debug executable (found in build/Debug-iphoneos).
January 31st, 2009 at 12:17 am
Oh right on. Yeah I guess I was referring to how you can’t use NSTask in an iphone project, and the advantage of running with the GTMStackTrace stuff is that you can have it automatically dump the trace instead of having to manually run atos after the fact.
July 10th, 2009 at 12:31 pm
Works great. Really.
August 12th, 2009 at 2:06 pm
[...] I had more information about this stack trace!” – come back here and follow the link to: GTM stacktrace information. Its a guide to using Google Toolbox for Mac. This is the same toolbox that provides a simpler [...]