Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C stack trace

After using a NSAssert() that throws a NSInternalInconsistencyException exception in an Objective-C application running on an iPad device (compiled in debug mode), I get something similar to:

2012-05-27 02:31:36.830 appname[10821:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'reason'
*** First throw call stack:
(0x3800788f 0x33338259 0x38007789 0x371f13a3 0x791a1 0x79555 0x79e03 0x7a44d 0x798d3 0x737fd 0x30e19c8b 0x30e18461 0x30e0ae87 0x30e7b7d5 0x30e18e6d 0x30e127dd 0x30de0ac3 0x30de0567 0x30ddff3b 0x3644122b 0x37fdb523 0x37fdb4c5 0x37fda313 0x37f5d4a5 0x37f5d36d 0x30e1186b 0x30e0ecd5 0x7343f 0x733e4)
terminate called throwing an exception

How can I find a useful stack trace, one that gives me at least a simple list of all the functions that were called until the exception was thrown?

Xcode doesn't help either:

bt in lldb shows:

(lldb) bt
* thread #1: tid = 0x1c03, 0x30c6832c libsystem_kernel.dylib`__pthread_kill + 8, stop reason = signal SIGABRT
    frame #0: 0x30c6832c libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x331f920e libsystem_c.dylib`pthread_kill + 54
    frame #2: 0x331f229e libsystem_c.dylib`abort + 94
    frame #3: 0x37682f6a libc++abi.dylib`abort_message + 46
    frame #4: 0x3768034c libc++abi.dylib`_ZL17default_terminatev + 24
    frame #5: 0x33338356 libobjc.A.dylib`_objc_terminate + 146
    frame #6: 0x376803c4 libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 76
    frame #7: 0x37680450 libc++abi.dylib`std::terminate() + 20
    frame #8: 0x37681824 libc++abi.dylib`__cxa_rethrow + 88
    frame #9: 0x333382a8 libobjc.A.dylib`objc_exception_rethrow + 12
    frame #10: 0x37f5d50c CoreFoundation`CFRunLoopRunSpecific + 404
    frame #11: 0x37f5d36c CoreFoundation`CFRunLoopRunInMode + 104
    frame #12: 0x30e1186a UIKit`-[UIApplication _run] + 550
    frame #13: 0x30e0ecd4 UIKit`UIApplicationMain + 1080
    frame #14: 0x0007343e appname`main + 86 at main.m:5

This is better, but still not very useful. I still don't know what led to the exception being thrown.

like image 710
rid Avatar asked May 26 '12 23:05

rid


1 Answers

A couple of useful things:

  1. If you're running your app out of Xcode, add an exception breakpoint. In the breakpoint navigator (command-6) hit the '+' at the very bottom left to add. This will pause execution on the line that throws the exception and allow you to inspect the current scope, stack, etc.

  2. If you're using gdb, use bt to print the backtrace

  3. If you're using lldb, use thread backtrace instead

like image 136
Sean Avatar answered Oct 18 '22 06:10

Sean