From 2554645a86359ec4cf805c8dee0e347b802776e0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 10 Sep 2015 00:10:28 +0200 Subject: Stacktrace printing on crash --- synchronizer/main.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'synchronizer') diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index db74960..e9c17e7 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp @@ -21,13 +21,40 @@ #include #include +#include #include "listener.h" #include "log.h" void crashHandler(int sig) { std::fprintf(stderr, "Error: signal %d\n", sig); - std::system("exec xterm -e gdb -p \"$PPID\""); + + QString s; + void *trace[256]; + int n = backtrace( trace, 256 ); + if ( n ) { + char **strings = backtrace_symbols( trace, n ); + + s = QLatin1String( "[\n" ); + + for ( int i = 0; i < n; ++i ) { + s += QString::number( i ) + + QLatin1String( ": " ) + + QLatin1String( strings[i] ) + QLatin1String( "\n" ); + } + s += QLatin1String( "]\n" ); + std::fprintf(stderr, "Backtrace: %s\n", s.toLatin1().data()); + + if ( strings ) { + free( strings ); + } + + } + + std::system("exec gdb -p \"$PPID\" -ex \"thread apply all bt\""); + //This only works if we actually have xterm and X11 available + // std::system("exec xterm -e gdb -p \"$PPID\""); + std::abort(); } -- cgit v1.2.3