How to print or see method call stack in xcode?

When you hit a breakpoint, select the Debug navigator in the navigator area (left side of the window):

debug navigator

The Debug navigator shows you a stack trace for each thread in your app. It shows you essentially the same information you get from gdb's backtrace command, but omits the return addresses (which normally aren't very helpful). Use the controls at the bottom of the navigator to hide or show all threads and to change the adjust the number of stack frames shown. I've got the slider set in the middle of its range in the image above, and the Debug navigator is omitting stack frames 2-18, which are all calls from one framework method to another, i.e. not my stuff.

Xcode 4 should be set up to display the Debug navigator automatically when you're debugging, but if not you can configure it to do so by going to Xcode->Behaviors->Edit Behaviors.... Then select the Run Pauses item from the list and set it to Show navigator Debug Navigator.


You can print the stack trace in the NSLog by

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

EDIT: Swift code

println("Stack trace: %@", NSThread.callStackSymbols())

You can set a breakpoint (or pause app) and from gdb debugger write "backtrace".

You should see stack:

(gdb) backtrace
#0  0x9022f7fe in mach_msg_trap ()
#1  0x9022ecdc in mach_msg ()
#2  0x022a310a in __CFRunLoopServiceMachPort ()
#3  0x02206550 in __CFRunLoopRun ()
#4  0x02205d84 in CFRunLoopRunSpecific ()
#5  0x02205c9b in CFRunLoopRunInMode ()
#6  0x024617d8 in GSEventRunModal ()
#7  0x0246188a in GSEventRun ()
#8  0x00c0ca16 in UIApplicationMain ()
#9  0x0000270d in main (argc=1, argv=0xbfeff550) at /Users/.........m:14