summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-10-28 23:25:18 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-10-28 23:25:18 +0000
commit6d9b5684fdb40ec4b64ef88e03e9ba8224483266 (patch)
tree6ebbce633ab2b7f9e656ecca2c1095c61beb15cf /mplayer.c
parent7bbf1acf5eafc072a573b5caea74be0d811801b1 (diff)
downloadmpv-6d9b5684fdb40ec4b64ef88e03e9ba8224483266.tar.bz2
mpv-6d9b5684fdb40ec4b64ef88e03e9ba8224483266.tar.xz
Allow attaching gdb on crash automatically.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13795 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/mplayer.c b/mplayer.c
index eb6613965e..c3e8ce3318 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -504,8 +504,16 @@ static void child_sighandler(int x){
}
#endif
+#ifdef CRASH_DEBUG
+static char *prog_path;
+static int crash_debug = 0;
+#endif
+
static void exit_sighandler(int x){
static int sig_count=0;
+#ifdef CRASH_DEBUG
+ if (!crash_debug || x != SIGTRAP)
+#endif
++sig_count;
if(inited_flags==0 && sig_count>1) exit(1);
if(sig_count==5)
@@ -527,7 +535,7 @@ static void exit_sighandler(int x){
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 @@ static void exit_sighandler(int x){
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
default:
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
+#ifdef CRASH_DEBUG
+ if (crash_debug) {
+ int gdb_pid;
+ char spid[20];
+ snprintf(spid, 19, "%i", getpid());
+ spid[19] = 0;
+ mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
+ gdb_pid = fork();
+ mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
+ if (gdb_pid == 0) { // We are the child
+ if (execlp("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);
}
@@ -1202,6 +1230,9 @@ current_module = NULL;
signal(SIGCHLD,child_sighandler);
#endif
+#ifdef CRASH_DEBUG
+ prog_path = argv[0];
+#endif
//========= Catch terminate signals: ================
// terminate requests:
signal(SIGTERM,exit_sighandler); // kill
@@ -1217,6 +1248,10 @@ current_module = NULL;
signal(SIGILL,exit_sighandler); // illegal instruction
signal(SIGFPE,exit_sighandler); // floating point exc.
signal(SIGABRT,exit_sighandler); // abort()
+#ifdef CRASH_DEBUG
+ if (crash_debug)
+ signal(SIGTRAP,exit_sighandler);
+#endif
#endif
#ifdef HAVE_NEW_GUI