Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No stack trace from NSAssert

IIRC, this normally works. But recently I've noticed that NSAssert…() isn't giving me stack traces, or at least, not useful ones:

2012-02-26 14:41:19.283 MyApp[3299:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '…'
*** First throw call stack:
(0x33cc58bf 0x353e11e5 0x33cc57b9 0x317583b3 0x78423 0x76e35 0x77dbf 0x217dd 0x12c63 0x3178a943 0x33c99a63 0x33c996c9 0x33c9829f 0x33c1b4dd 0x33c1b3a5 0x3585bfcd 0x34d60743 0xde87 0x30dc)
terminate called throwing an exception(gdb) bt
#0  0x3629232c in __pthread_kill ()
#1  0x34b3ef5a in pthread_kill ()
#2  0x34b37fea in abort ()
#3  0x35fe9f6a in abort_message ()
#4  0x35fe734c in default_terminate ()
#5  0x353e12e2 in _objc_terminate ()
#6  0x35fe73c4 in safe_handler_caller ()
#7  0x35fe7450 in std::terminate ()
#8  0x35fe8824 in __cxa_rethrow ()
#9  0x353e1234 in objc_exception_rethrow ()
#10 0x33c1b544 in CFRunLoopRunSpecific ()
#11 0x33c1b3a4 in CFRunLoopRunInMode ()
#12 0x3585bfcc in GSEventRunModal ()
#13 0x34d60742 in UIApplicationMain ()
#14 0x0000de86 in main (argc=1, argv=0x2fdffaa4) at …/main.mm:18
(gdb) 

I read somewhere that using an iOS deployment target that Xcode doesn't have symbols for causes this, and I did change the setting recently from 4.0 to 4.3. However, changing it back makes no difference.

OTOH, assert(…) works as expected.

Why isn't Xcode providing a proper navigable stack trace when NSAssert…() fails?

like image 428
Marcelo Cantos Avatar asked Feb 26 '12 03:02

Marcelo Cantos


1 Answers

I'm not sure why this is, but, if you set an exception breakpoint the breakpoint seems to stop execution early enough to see a useful backtrace. Once the breakpoint is hit bt in the console works as expected.

enter image description here

Make sure you don't check the "Automatically continue after evaluating" box. That seems to result in a useless backtrace like the one you posted.

You could also use NSSetUncaughtExceptionHandler() to set a logging callback function as described here.

like image 148
NJones Avatar answered Sep 30 '22 14:09

NJones