--- a/src/crashcatcher.cpp Fri Oct 18 21:52:09 2013 +0300 +++ b/src/crashcatcher.cpp Fri Oct 18 22:07:26 2013 +0300 @@ -27,58 +27,54 @@ // ============================================================================= // ----------------------------------------------------------------------------- -static void handleSignal (int sig) -{ printf ("caught signal %d\n", sig); +static void handleCrash (int sig) +{ printf ("%s: crashed with signal %d, launching gdb\n", __func__, sig); if (g_crashCatcherActive) { printf ("caught signal while crash catcher is active!\n"); return; } - if (g_signalsToCatch.indexOf (sig) != -1) - { const pid_t pid = getpid(); - QProcess proc; - QTemporaryFile commandsFile; + const pid_t pid = getpid(); + QProcess proc; + QTemporaryFile commandsFile; - g_crashCatcherActive = true; - printf ("%s: crashed with signal %d, launching gdb\n", __func__, sig); + g_crashCatcherActive = true; - if (commandsFile.open()) - { commandsFile.write (fmt ("attach %1\n", pid).toLocal8Bit()); - commandsFile.write (str ("backtrace full\n").toLocal8Bit()); - commandsFile.write (str ("detach\n").toLocal8Bit()); - commandsFile.write (str ("quit").toLocal8Bit()); - commandsFile.flush(); - commandsFile.close(); - } + if (commandsFile.open()) + { commandsFile.write (fmt ("attach %1\n", pid).toLocal8Bit()); + commandsFile.write (str ("backtrace full\n").toLocal8Bit()); + commandsFile.write (str ("detach\n").toLocal8Bit()); + commandsFile.write (str ("quit").toLocal8Bit()); + commandsFile.flush(); + commandsFile.close(); + } - QStringList args ({"-x", commandsFile.fileName()}); + QStringList args ({"-x", commandsFile.fileName()}); - proc.start ("gdb", args); + proc.start ("gdb", args); - // Linux doesn't allow ptrace to be used on anything but direct child processes - // so we need to use prctl to register an exception to this to allow GDB attach to us. - // We need to do this now and no earlier because only now we actually know GDB's PID. - prctl (PR_SET_PTRACER, proc.pid(), 0, 0, 0); + // Linux doesn't allow ptrace to be used on anything but direct child processes + // so we need to use prctl to register an exception to this to allow GDB attach to us. + // We need to do this now and no earlier because only now we actually know GDB's PID. + prctl (PR_SET_PTRACER, proc.pid(), 0, 0, 0); - proc.waitForFinished (5000); - str output = QString (proc.readAllStandardOutput()); - str err = QString (proc.readAllStandardError()); + proc.waitForFinished (1000); + str output = QString (proc.readAllStandardOutput()); + str err = QString (proc.readAllStandardError()); - bombBox (fmt ("<h3>Program crashed with signal %1</h3>\n\n" - "%2" - "<p><b>GDB <tt>stdout</tt>:</b></p><pre>%3</pre>\n" - "<p><b>GDB <tt>stderr</tt>:</b></p><pre>%4</pre>", - sig, (!g_assertionFailure.isEmpty()) ? g_assertionFailure : "", output, err)); - exit (137); - } + bombBox (fmt ("<h3>Program crashed with signal %1</h3>\n\n" + "%2" + "<p><b>GDB <tt>stdout</tt>:</b></p><pre>%3</pre>\n" + "<p><b>GDB <tt>stderr</tt>:</b></p><pre>%4</pre>", + sig, (!g_assertionFailure.isEmpty()) ? g_assertionFailure : "", output, err)); } // ============================================================================= // ----------------------------------------------------------------------------- void initCrashCatcher() { struct sigaction sighandler; - sighandler.sa_handler = &handleSignal; + sighandler.sa_handler = &handleCrash; sighandler.sa_flags = 0; sigemptyset (&sighandler.sa_mask);