Reputation: 183
I've created some example code to demonstrate my problem.
- (void) test {
void (^handler)(void) = ^ {
NSArray *test = [NSArray array];
[test objectAtIndex: 5];
};
handler = [handler copy];
dispatch_async(dispatch_get_main_queue(), handler);
}
When I call the test method I don't get a stack trace. The debugger just stops at main.m and has this line highlighted
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([FantasyUniversalAppDelegate class]));
If I remove the dispatch_async and just call handler(); then I do get a stack trace. Can some one explain why this is and is there a way to get a more descriptive stack trace?
Right now I am using Flurry to show me crashes but the crashes it is showing me isn't very useful because I get a very non-descriptive stack trace (which is symbolicated). It looks like this:
Thread: Unknown Name
0 libsystem_kernel.dylib 0x3a224eb4 mach_msg_trap + 20
1 CoreFoundation 0x32067045 __CFRunLoopServiceMachPort + 129
2 CoreFoundation 0x32065d5f __CFRunLoopRun + 815
3 CoreFoundation 0x31fd8ebd CFRunLoopRunSpecific + 357
4 CoreFoundation 0x31fd8d49 CFRunLoopRunInMode + 105
5 GraphicsServices 0x35b9c2eb GSEventRunModal + 75
6 UIKit 0x33eee301 UIApplicationMain + 1121
7 IOSTestApp 0x00025d7b main (main.m:14)
Upvotes: 3
Views: 645
Reputation: 4915
You could wrap your code in a
@try {
NSArray *test = [NSArray array];
[test objectAtIndex: 5];
}
@catch {
// Get the stack track for the current thread
NSArray *stacktrace = [NSThread callStackSymbols];
// Do something with the symbols
}
all within the block that you are dispatching. Though I'm sure there is a much nicer way!
Upvotes: 0