43 lines · c
1#include "attach.h"2#include <stdio.h>3#include <string.h>4#include <unistd.h>5 6int 7main (int argc, char **argv)8{9 lldb_enable_attach();10 11 int do_crash = 0;12 int do_wait = 0;13 14 int idx;15 for (idx = 1; idx < argc; idx++)16 {17 if (strcmp(argv[idx], "CRASH") == 0)18 do_crash = 1;19 if (strcmp(argv[idx], "WAIT") == 0)20 do_wait = 1;21 }22 printf("PID: %d END\n", getpid());23 24 if (do_wait)25 {26 int keep_waiting = 1;27 while (keep_waiting)28 {29 printf ("Waiting\n");30 sleep(1); // Stop here to unset keep_waiting31 }32 }33 34 if (do_crash)35 {36 char *touch_me_not = (char *) 0;37 printf ("About to crash.\n");38 touch_me_not[0] = 'a';39 }40 printf ("Got there on time and it did not crash.\n");41 return 0;42}43