HelloMoon
HelloMoon

Reputation:

Easy way to print current stack trace of an app?

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.

Upvotes: 8

Views: 5578

Answers (3)

Brian Westphal
Brian Westphal

Reputation: 6305

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

Upvotes: 5

alex_c
alex_c

Reputation: 2046

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?

Upvotes: 3

bbum
bbum

Reputation: 162712

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).

Upvotes: 1

Related Questions