- added Chris's crashcatcher improvements.

SVN r3071 (trunk)
This commit is contained in:
Christoph Oelckers 2010-12-21 14:15:19 +00:00
parent f6c1f359e1
commit e27179afd0

View file

@ -97,8 +97,7 @@ static void gdb_info(pid_t pid)
strcpy(respfile, "gdb-respfile-XXXXXX"); strcpy(respfile, "gdb-respfile-XXXXXX");
if((fd = mkstemp(respfile)) >= 0 && (f = fdopen(fd, "w"))) if((fd = mkstemp(respfile)) >= 0 && (f = fdopen(fd, "w")))
{ {
fprintf(f, "signal SIGCHLD\n" fprintf(f, "shell echo \"\"\n"
"shell echo \"\"\n"
"shell echo \"* Loaded Libraries\"\n" "shell echo \"* Loaded Libraries\"\n"
"info sharedlibrary\n" "info sharedlibrary\n"
"shell echo \"\"\n" "shell echo \"\"\n"
@ -115,36 +114,8 @@ static void gdb_info(pid_t pid)
"x/x $eip-3\nx/x $eip\n" "x/x $eip-3\nx/x $eip\n"
"shell echo \"\"\n" "shell echo \"\"\n"
"shell echo \"* Backtrace\"\n" "shell echo \"* Backtrace\"\n"
"backtrace full\n" "thread apply all backtrace full\n"
#if 0 /* This sorta works to print out the core, but is too slow and skips 0's.. */ "detach\n"
"shell echo \"\"\n"
"shell echo \"* Stack\"\n"
"set var $_sp = $esp\n"
"while $_sp <= $ebp - 12\n"
" printf \"%%08x: \", $_sp\n"
" set var $_i = $_sp\n"
" while $_i < $_sp + 16\n"
" printf \"%%08x \", {int} $_i\n"
" set $_i += 4\n"
" end\n"
" set var $_i = $_sp\n"
" while $_i < $_sp + 16\n"
" printf \"%%c\", {int} $_i\n"
" set ++$_i\n"
" end\n"
" set var $_sp += 16\n"
" printf \"\\n\"\n"
"end\n"
"if $_sp <= $ebp\n"
" printf \"%%08x: \", $esp\n"
" while $_sp <= $ebp\n"
" printf \"%%08x \", {int} $_i\n"
" set $_sp += 4\n"
" end\n"
" printf \"\\n\"\n"
"end\n"
#endif
"kill\n"
"quit\n"); "quit\n");
fclose(f); fclose(f);
@ -152,8 +123,8 @@ static void gdb_info(pid_t pid)
snprintf(buf, sizeof(buf), "gdb --quiet --batch --command=%s --pid=%i", respfile, pid); snprintf(buf, sizeof(buf), "gdb --quiet --batch --command=%s --pid=%i", respfile, pid);
printf("Executing: %s\n", buf); printf("Executing: %s\n", buf);
fflush(stdout); fflush(stdout);
system(buf);
system(buf);
/* Clean up */ /* Clean up */
remove(respfile); remove(respfile);
} }
@ -168,6 +139,7 @@ static void gdb_info(pid_t pid)
printf("Could not create gdb command file\n"); printf("Could not create gdb command file\n");
} }
fflush(stdout); fflush(stdout);
kill(pid, SIGKILL);
} }
@ -267,8 +239,8 @@ static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
/* Make sure the effective uid is the real uid */ /* Make sure the effective uid is the real uid */
if (getuid() != geteuid()) if (getuid() != geteuid())
{ {
fprintf(stderr, "%s (signal %i)\ngetuid() does not match geteuid().\n", sigdesc, signum); raise(signum);
_exit(-1); return;
} }
#endif #endif
@ -325,48 +297,18 @@ static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
} }
gdb_info(pid); gdb_info(pid);
#if 0 /* Why won't this work? */
if(ucontext)
{
unsigned char *ptr = ucontext->uc_stack.ss_sp;
size_t len;
fprintf(f, "\n* Stack\n");
for(len = ucontext->uc_stack.ss_size/4;len > 0; len -= 4)
{
fprintf(f, "0x%08x:", (int)ptr);
for(i = 0;i < ((len < 4) ? len : 4);++i)
{
fprintf(f, " %02x%02x%02x%02x", ptr[i*4 + 0], ptr[i*4 + 1],
ptr[i*4 + 2], ptr[i*4 + 3]);
}
fputc(' ', f);
fflush(f);
for(i = 0;i < ((len < 4) ? len : 4);++i)
{
fprintf(f, "%c", *(ptr++));
fprintf(f, "%c", *(ptr++));
fprintf(f, "%c", *(ptr++));
fprintf(f, "%c", *(ptr++));
}
fputc('\n', f);
fflush(f);
}
}
#endif
if(f != stderr) if(f != stderr)
{ {
fclose(f); fclose(f);
#if (defined __unix__) #if (defined __unix__)
if(cc_logfile) if(cc_logfile)
{ {
char buf[256]; char buf[512];
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
"if (which gxmessage > /dev/null 2>&1);" "if (which gxmessage > /dev/null 2>&1) ; then\n"
"then gxmessage -buttons \"Damn it:0\" -center -title \"Very Fatal Error\" -file %s;" " gxmessage -buttons \"Damn it:0\" -center -title \"Very Fatal Error\" -file %s\n"
"elif (which xmessage > /dev/null 2>&1);" "elif (which xmessage > /dev/null 2>&1) ; then\n"
"then xmessage -buttons \"Damn it:0\" -center -file %s -geometry 600x400;" " xmessage -buttons \"Damn it:0\" -center -file %s -geometry 600x400\n"
"fi", cc_logfile, cc_logfile); "fi", cc_logfile, cc_logfile);
system(buf); system(buf);
} }
@ -376,8 +318,8 @@ static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
_exit(0); _exit(0);
default: default:
/* Wait and let the child attach gdb */ /* Wait indefinitely; we'll be killed when gdb is done */
waitpid(dbg_pid, NULL, 0); while(1) usleep(1000000);
} }
} }
@ -388,12 +330,13 @@ int cc_install_handlers(int num_signals, int *signals, const char *logfile, int
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = crash_catcher; sa.sa_sigaction = crash_catcher;
#if !defined(__FreeBSD__) && !defined(__APPLE__) #ifdef SA_ONESHOT
sa.sa_flags = SA_ONESHOT | SA_NODEFER | SA_SIGINFO; sa.sa_flags = SA_ONESHOT | SA_NODEFER | SA_SIGINFO;
#else #else
sa.sa_flags = SA_NODEFER | SA_SIGINFO; sa.sa_flags = SA_NODEFER | SA_SIGINFO;
#endif #endif
sigemptyset(&sa.sa_mask);
cc_logfile = logfile; cc_logfile = logfile;
cc_user_info = user_info; cc_user_info = user_info;