Debugging trick to dump call stack of current thread

June 20, 2013

Although an app crash will generate a stack trace, it can be helpful to view the call stack while an app is running.

The following code will display an array of strings representing the call stack for the current thread.

NSLog(@"%@",[NSThread callStackSymbols]);

The output will show the call stack as follows:

0   Sandbox                             0x00002251 -[SandboxViewController buttonPressed:] + 65
1   libobjc.A.dylib                     0x0192a705 -[NSObject performSelector:withObject:withObject:] + 77
2   UIKit                               0x0085e2c0 -[UIApplication sendAction:to:from:forEvent:] + 96
3   UIKit                               0x0085e258 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
4   UIKit                               0x0091f021 -[UIControl sendAction:to:forEvent:] + 66
5   UIKit                               0x0091f57f -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 578
6   UIKit                               0x0091e6e8 -[UIControl touchesEnded:withEvent:] + 546
7   UIKit                               0x0088dcef -[UIWindow _sendTouchesForEvent:] + 846
8   UIKit                               0x0088df02 -[UIWindow sendEvent:] + 273
9   UIKit                               0x0086bd4a -[UIApplication sendEvent:] + 436
...