Imported Upstream version 2.6.0p2
[debian/amanda] / common-src / debug.c
index a6de4154c5efcf350f3bd7a5947649e7c8e7e06c..ed036e48599056208a027e9fa3a55d9455ee5e32 100644 (file)
 #include "timestamp.h"
 #include "conffile.h"
 
+#ifdef HAVE_GLIBC_BACKTRACE
+#include <execinfo.h>
+#endif
+
 /* Minimum file descriptor on which to keep the debug file.  This is intended
  * to keep the descriptor "out of the way" of other processing.  It's not clear
  * that this is required any longer, but it doesn't hurt anything.
@@ -159,6 +163,16 @@ debug_logging_handler(const gchar *log_domain G_GNUC_UNUSED,
            fflush(stderr);
        }
 
+#ifdef HAVE_GLIBC_BACKTRACE
+       /* try logging a traceback to the debug log */
+       if (db_fd != -1) {
+           void *stack[32];
+           int naddrs;
+           naddrs = backtrace(stack, sizeof(stack)/sizeof(*stack));
+           backtrace_symbols_fd(stack, naddrs, db_fd);
+       }
+#endif
+
        /* we're done */
        if (log_level & G_LOG_LEVEL_CRITICAL)
            exit(error_exit_status);