Reputation: 47739
I'm trying to add some crash logging to an app, and I have a signal
handler set up to catch the standard "fatal" signals. What "cause" information (if any) can I practically/simply collect in the signal handler for logging?
(I've spent about 2 hours Googling stuff, but most of what i find is for other environments and is too complex to be reliable. I'm looking for what's simple to do, specifically in an iOS environment.)
(I already have an Objective-C exception handler to catch Objective-C exceptions.)
Upvotes: 3
Views: 1229
Reputation: 15339
Please don't do this. It is incredibly hard to do proper and safe crash reporting, as highlighted by Landon Fuller here: http://landonf.bikemonkey.org/code/objc/Reliable_Crash_Reporting.20110912.html
In a nutshell: you may only use async safe code when the app crashed, so calling any Objective-C method is not safe by default!
Rather use an existing crash reporting library like PLCrashReporter or some other library or service that already exist: https://code.google.com/p/plcrashreporter/
Upvotes: 3
Reputation: 3937
You can get the stack trace with this:
+ (NSArray *)backtrace {
void* callstack[128];
int frames = backtrace(callstack, 128);
char **strs = backtrace_symbols(callstack, frames);
int i;
NSMutableArray *backtrace = [NSMutableArray arrayWithCapacity:frames];
for (i = 0; i < XXX; i++) {
[backtrace addObject:[NSString stringWithUTF8String:strs[i]]];
}
free(strs);
return backtrace;
}
Upvotes: 2