Can I get a stack trace for un-handled (Objective) C++ exceptions? Can I get a stack trace for un-handled (Objective) C++ exceptions? xcode xcode

Can I get a stack trace for un-handled (Objective) C++ exceptions?


You can quickly establish a break on all C++ throw conditions in Xcode:

  • cmd+6
  • "+" button -> Add Exception Breakpoint
    • C++ -> std::out_of_range
    • On Throw

Update

If you have a lot of them tho filter out, you may prefer to:

  • Create a Symbolic Breakpoint
  • Symbol = __cxa_throw (may vary by std library)
  • Action > Debugger Command = bt
  • Automatically continue after eval = On

The bt command logs the backtrace. Configured this way, it will automatically continue.

So, this will just log the backtrace of every thrown exception - when your program terminates due to an unhandled exception, the clues will be among the final logged backtraces (often the last, unless the library rethrows).


In the app I get to debug with many c++ exceptions, I leave the "Catch C++ Exceptions on Throw" off until I get to the point in the app where it will throw the exception, then I turn that option on and usually the next exception that is thrown is what I'm looking for. This will break a few levels deeper than where the error is, but the stack is intact so you can figure out what is going on.


Check PLCrashReporter. We use it with our application (which relies heavily on C++) and it produces stack traces even for the C++ code.

The only problem you might have is when using assembly routines which were not written natively for iOS (Apple's compiler is using R7 to hold the stack frame for tracing back symbols which is not according to official ARM EBI)