Linux signal handling debug code

This commit is contained in:
Kevin Tew 2011-03-25 13:48:27 -06:00
parent 40847f51b1
commit ef200b3e7e

View File

@ -23,16 +23,38 @@
#endif #endif
#if WAIT_FOR_GDB #if WAIT_FOR_GDB
static void launchgdb() { void launchgdb() {
pid_t pid = getpid(); {
char inbuffer[10]; pid_t pid = getpid();
fprintf(stderr, "pid # %i run gdb\nsudo gdb ./racket3m %i\nor kill process.\n", pid, pid);
fflush(stderr);
}
fprintf(stderr, "pid # %i run gdb \"gdb ./racket3m %i\" or kill process.\n", pid, pid); pid_t fpid = fork();
fflush(stderr); if (fpid == 0) // child
{
char _pidstr[20];
char *pidstr = (char*) _pidstr;
snprintf(pidstr, 20, "%i", getpid());
execl("/usr/bin/bash", "rgdb", pidstr);
}
else if (fpid < 0) // failed to fork
{
printf("Failed to fork\n");
exit(1);
}
else // parent
{
kill(getpid(), SIGSTOP);
}
while(read(fileno(stdin), inbuffer, 10) <= 0){ kill(getpid(), SIGSTOP);
if(errno != EINTR){ {
fprintf(stderr, "Error detected %i\n", errno); char inbuffer[10];
while(read(fileno(stdin), inbuffer, 10) <= 0){
if(errno != EINTR){
fprintf(stderr, "Error detected %i\n", errno);
}
} }
} }
} }
@ -90,6 +112,9 @@ void fault_handler(int sn, struct siginfo *si, void *ctx)
else { else {
printf("SIGSEGV ???? SI_CODE %i fault on %p\n", c, p); printf("SIGSEGV ???? SI_CODE %i fault on %p\n", c, p);
} }
#if WAIT_FOR_GDB
launchgdb();
#endif
abort(); abort();
} }
# define NEED_SIGSTACK # define NEED_SIGSTACK