[commit: ghc] master: Signals: Print backtrace on SIGUSR2 (40cbf9a)

git at git.haskell.org git at git.haskell.org
Sat Oct 17 14:49:13 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/40cbf9aaa16fd263c54e159a4bda3a5682720041/ghc

>---------------------------------------------------------------

commit 40cbf9aaa16fd263c54e159a4bda3a5682720041
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Oct 17 16:45:26 2015 +0200

    Signals: Print backtrace on SIGUSR2
    
    This uses the backtrace support introduced in D1196 to provide
    backtraces from Haskell processes when SIGUSR2 is thrown.
    
    Test Plan: Need to add a test.
    
    Reviewers: scpmw, simonmar, Tarrasch, austin
    
    Reviewed By: austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1197


>---------------------------------------------------------------

40cbf9aaa16fd263c54e159a4bda3a5682720041
 rts/posix/Signals.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/rts/posix/Signals.c b/rts/posix/Signals.c
index a2fa07f..88d1856 100644
--- a/rts/posix/Signals.c
+++ b/rts/posix/Signals.c
@@ -15,6 +15,7 @@
 #include "RtsUtils.h"
 #include "Prelude.h"
 #include "Stable.h"
+#include "Libdw.h"
 
 #ifdef alpha_HOST_ARCH
 # if defined(linux_HOST_OS)
@@ -526,6 +527,25 @@ shutdown_handler(int sig STG_UNUSED)
 }
 
 /* -----------------------------------------------------------------------------
+ * SIGUSR2 handler.
+ *
+ * We try to give the user an indication of what we are currently doing
+ * in response to SIGUSR2.
+ * -------------------------------------------------------------------------- */
+static void
+backtrace_handler(int sig STG_UNUSED)
+{
+#ifdef USE_LIBDW
+    LibDwSession *session = libdw_init();
+    Backtrace *bt = libdw_get_backtrace(session);
+    libdw_print_backtrace(session, stderr, bt);
+    backtrace_free(bt);
+#else
+    fprintf(stderr, "This build does not support backtraces.\n");
+#endif
+}
+
+/* -----------------------------------------------------------------------------
  * An empty signal handler, currently used for SIGPIPE
  * -------------------------------------------------------------------------- */
 static void
@@ -670,6 +690,16 @@ initDefaultHandlers(void)
         sysErrorBelch("warning: failed to install SIGPIPE handler");
     }
 
+#ifdef USE_LIBDW
+    // Print a backtrace on SIGUSR2
+    action.sa_handler = backtrace_handler;
+    sigemptyset(&action.sa_mask);
+    action.sa_flags = 0;
+    if (sigaction(SIGUSR2, &action, &oact) != 0) {
+        sysErrorBelch("warning: failed to install SIGUSR2 handler");
+    }
+#endif
+
     set_sigtstp_action(rtsTrue);
 }
 



More information about the ghc-commits mailing list