[plcrashreporter] push by landon.j.fuller@gmail.com - Add a hackish workaround to simplify executing DemoCrash on a device.... on 2013-02-21 16:25 GMT

14 views
Skip to first unread message

codesite...@google.com

unread,
Feb 21, 2013, 11:26:03 AM2/21/13
to plcrashrepo...@googlegroups.com
Revision: 2dd862ce049e
Author: Landon Fuller <lan...@plausible.coop>
Date: Thu Feb 21 08:24:19 2013
Log: Add a hackish workaround to simplify executing DemoCrash on a
device.

On iOS 6.x, when using Xcode 4, returning *immediately* from main()
while a debugger is attached will cause an immediate launchd respawn of the
application without the debugger enabled.

This is not documented anywhere, and certainly occurs entirely by accident.
That said, it's enormously useful when performing integration tests on
signal/exception
handlers, as it means we can use the standard Xcode build+run functionality
without having
the debugger catch our signals (thus requiring that we manually relaunch
the app after it has
installed).

This may break at any point in the future, in which case we can remove it
and go back
to the old, annoying, and slow approach of manually relaunching the
application. Or,
perhaps Apple will bless us with the ability to run applications without
the debugger
enabled.

http://code.google.com/p/plcrashreporter/source/detail?r=2dd862ce049e

Modified:
/Source/Crash Demo/main.m

=======================================
--- /Source/Crash Demo/main.m Thu Sep 15 12:30:20 2011
+++ /Source/Crash Demo/main.m Thu Feb 21 08:24:19 2013
@@ -29,6 +29,9 @@
#import <Foundation/Foundation.h>
#import "CrashReporter.h"

+#import <sys/types.h>
+#import <sys/sysctl.h>
+
/* A custom post-crash callback */
void post_crash_callback (siginfo_t *info, ucontext_t *uap, void *context)
{
// this is not async-safe, but this is a test implementation
@@ -72,11 +75,58 @@
NSLog(@"Saved crash report to: %@", outputPath);
#endif
}
+
+
+/*
+ * On iOS 6.x, when using Xcode 4, returning *immediately* from main()
+ * while a debugger is attached will cause an immediate launchd respawn of
the
+ * application without the debugger enabled.
+ *
+ * This is not documented anywhere, and certainly occurs entirely by
accident.
+ * That said, it's enormously useful when performing integration tests on
signal/exception
+ * handlers, as it means we can use the standard Xcode build+run
functionality without having
+ * the debugger catch our signals (thus requiring that we manually
relaunch the app after it has
+ * installed).
+ *
+ * This may break at any point in the future, in which case we can remove
it and go back
+ * to the old, annoying, and slow approach of manually relaunching the
application. Or,
+ * perhaps Apple will bless us with the ability to run applications
without the debugger
+ * enabled.
+ */
+static bool debugger_should_exit (void) {
+#if !TARGET_OS_IPHONE
+ return false;
+#endif
+
+ struct kinfo_proc info;
+ size_t info_size = sizeof(info);
+ int name[4];
+
+ name[0] = CTL_KERN;
+ name[1] = KERN_PROC;
+ name[2] = KERN_PROC_PID;
+ name[3] = getpid();
+
+ if (sysctl(name, 4, &info, &info_size, NULL, 0) == -1) {
+ NSLog(@"sysctl() failed: %s", strerror(errno));
+ return false;
+ }
+
+ if ((info.kp_proc.p_flag & P_TRACED) != 0)
+ return true;
+
+ return false;
+}

int main (int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSError *error = nil;

+ if (debugger_should_exit()) {
+ NSLog(@"The demo crash app should be run without a debugger
present. Exiting ...");
+ return 0;
+ }
+
/* Save any existing crash report. */
save_crash_report();

Reply all
Reply to author
Forward
0 new messages