in Other Sources/Crash Demo/main.m [139:190]
int main (int argc, char *argv[]) {
@autoreleasepool {
NSError *error = nil;
/*
* Standalone "logic" tests aren't supported by XCTest when targeting an actual iOS device; instead,
* they require a host application under which the tests will run.
*
* The DemoCrash application serves as a test host; we simply look for the existence of the XCTest framework
* and assume that, should it be available, we're running as a test harness.
*/
#if TARGET_OS_IPHONE
if (NSClassFromString(@"XCTestCase") != nil) {
return UIApplicationMain(argc, argv, nil, @"DemoCrashAppDelegate");
}
#endif /* TARGET_IPHONE_OS */
/* Configure our reporter */
PLCrashReporterSignalHandlerType signalHandlerType =
#if !TARGET_OS_TV
PLCrashReporterSignalHandlerTypeMach;
#else
PLCrashReporterSignalHandlerTypeBSD;
#endif
PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType: signalHandlerType
symbolicationStrategy: PLCrashReporterSymbolicationStrategyAll];
PLCrashReporter *reporter = [[PLCrashReporter alloc] initWithConfiguration: config];
/* Save any existing crash report. */
save_crash_report(reporter);
if (debugger_should_exit()) {
NSLog(@"The demo crash app should be run without a debugger present. Exiting ...");
return 0;
}
/* Set up post-crash callbacks */
PLCrashReporterCallbacks cb = {
.version = 0,
.context = (void *) 0xABABABAB,
.handleSignal = post_crash_callback
};
[reporter setCrashCallbacks: &cb];
/* Enable the crash reporter */
if (![reporter enableCrashReporterAndReturnError: &error]) {
NSLog(@"Could not enable crash reporter: %@", error);
}
/* Add another stack frame */
stackFrame();
}
}