8

Xcode / objective c does not really print a useful stack trace. My app crashes somewhere, and the damn thing gives me only numbers like 45353453, 34524323, 6745345353, 457634524234. Not useful at all.

So I want to make a NSLog(); on the beginning of EVERY method I have in my entire app. But maybe there's a simpler way to just find out the real stack trace, humanly readable? Not only on app launch or crash, but all the time, on every activity that happens? Would help debugging a lot.

  • you can follow the stack trace in the debugger, it should take you to the last method call before the crash i think – Daniel Sep 03 '09 at 14:51
  • No, the debugger information is not really helpful. –  Sep 03 '09 at 15:08
  • 1
    Why is the debugger information not helpful? If you start your application in the debugger, and it crashes, the debugger should present a nice stack trace that you can step back through to see each called line. If your application is halting on an exception, see alex_c's answer for how to debug that. – Brad Larson Sep 03 '09 at 15:56

3 Answers3

5

Something like this might be helpful to you as well


@implementation UIApplication (MyCategory)

+ (void)logStackTrace {
    @try {
        [[NSException exceptionWithName:@"Stack Trace" reason:@"Testing" userInfo:nil] raise];
    }
    @catch (NSException *e) {
        NSLog(@"%@", [e callStackSymbols]);
    }
}

@end
Brian Westphal
  • 6,058
  • 4
  • 24
  • 20
3

Add a global breakpoint for objc_exception_throw, then you can get a useful stack trace in the debugger.

How to add a breakpoint to objc_exception_throw?

Community
  • 1
  • 1
alex_c
  • 2,058
  • 2
  • 26
  • 34
1

There really isn't a way to do this reliably from within the app. If your app is crashing and not giving symbols, it sounds like your running a stripped release version and not the debug version?

If you have the unstripped version sitting around, you can correlate between those numbers and the actual name of the stack frame using the atos command (see man atos in Terminal or search for atos in Xcode's documentation or Google).

You probably don't want to log the stack of every method call. The volume of information would quickly become overwhelming. And it shouldn't be a mystery as to why most of the methods in your app are being called (though it will take a while to understand why the interface between UIKit and your app works the way it does).

bbum
  • 162,346
  • 23
  • 271
  • 359