[MPlayer-dev-eng] [PATCH] automatic gdb attaching
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon Oct 18 21:48:06 CEST 2004
Hi,
the attached patch will try to attach gdb on receiving an "excpetional"
signal. You can also trigger this by sending a SIGTRAP (might be useful
for debugging hangs).
The main purpose of this is helping in debugging rare bugs. So you can
just go about playing your files, and if that bug occurs you can right
start developing ;-).
Of course, the code should not be enabled by default as it currently is,
and the gdb path should probably be detected by configure as well...
Please commment...
Greetings,
Reimar Döffinger
-------------- next part --------------
--- mplayer.c 2004-10-14 13:20:33.000000000 +0200
+++ mplayer.c 2004-10-18 20:17:43.083659577 +0200
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
+#define CRASH_DEBUG
#ifdef WIN32
#define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
@@ -504,8 +505,15 @@
}
#endif
+#ifdef CRASH_DEBUG
+static char *prog_path;
+#endif
+
static void exit_sighandler(int x){
static int sig_count=0;
+#ifdef CRASH_DEBUG
+ if (x != SIGTRAP)
+#endif
++sig_count;
if(inited_flags==0 && sig_count>1) exit(1);
if(sig_count==5)
@@ -527,7 +535,7 @@
mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
current_module?current_module:mp_gettext("unknown")
);
- if(sig_count==1)
+ if(sig_count<=1)
switch(x){
case SIGINT:
case SIGQUIT:
@@ -545,6 +553,26 @@
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
default:
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
+#ifdef CRASH_DEBUG
+ {
+ int gdb_pid;
+ char spid[20];
+ snprintf(spid, 19, "%i", getpid());
+ spid[19] = 0;
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, "Forking...\n");
+ gdb_pid = fork();
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, "Forked...\n");
+ if (gdb_pid == 0) { // We are the child
+ if (execl("/usr/bin/gdb", "gdb", prog_path, spid, NULL) == -1)
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
+ } else if (gdb_pid < 0)
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
+ else {
+ waitpid(gdb_pid, NULL, 0);
+ }
+ if (x == SIGTRAP) return;
+ }
+#endif
}
exit_player(NULL);
}
@@ -1200,6 +1228,9 @@
signal(SIGCHLD,child_sighandler);
#endif
+#ifdef CRASH_DEBUG
+ prog_path = argv[0];
+#endif
//========= Catch terminate signals: ================
// terminate requests:
signal(SIGTERM,exit_sighandler); // kill
@@ -1215,6 +1246,9 @@
signal(SIGILL,exit_sighandler); // illegal instruction
signal(SIGFPE,exit_sighandler); // floating point exc.
signal(SIGABRT,exit_sighandler); // abort()
+#ifdef CRASH_DEBUG
+ signal(SIGTRAP,exit_sighandler);
+#endif
#endif
#ifdef HAVE_NEW_GUI
More information about the MPlayer-dev-eng
mailing list