From 70296dde9a4237ec07adbffae2a4acf40fc8bf6a Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 19 Apr 2015 19:39:05 +0200 Subject: [PATCH] Simple stack trace for singla handler (unix only) --- servatrice/src/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/servatrice/src/main.cpp b/servatrice/src/main.cpp index 6c29e8be..22048ca0 100644 --- a/servatrice/src/main.cpp +++ b/servatrice/src/main.cpp @@ -33,8 +33,12 @@ #include #ifdef Q_OS_UNIX #include +#include +#include #endif +#define SIGSEGV_TRACE_LINES 40 + RNG_Abstract *rng; ServerLogger *logger; QThread *loggerThread; @@ -129,6 +133,16 @@ void myMessageOutput2(QtMsgType /*type*/, const QMessageLogContext &, const QStr #ifdef Q_OS_UNIX void sigSegvHandler(int sig) { + void *array[SIGSEGV_TRACE_LINES]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, SIGSEGV_TRACE_LINES); + + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", sig); + backtrace_symbols_fd(array, size, STDERR_FILENO); + if (sig == SIGSEGV) logger->logMessage("CRASH: SIGSEGV"); else if (sig == SIGABRT)