From 804f01b1628292a2953c907fa670ac59784ee53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Mon, 14 Dec 2015 22:58:31 +0100 Subject: [PATCH] Add backtrace after segfault. --- main.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index a31b416..4780797 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,24 @@ #include #include +#include + +/* + * Code from http://stackoverflow.com/a/77336/5419223 + */ +static void sigsegv_handler(int sig) { + constexpr int STACK_DEPTH = 10; + void *array[STACK_DEPTH]; + + size_t size = backtrace(array, STACK_DEPTH); + + fprintf(stderr, "ERROR: signal %d:\n", sig); + backtrace_symbols_fd(array, size, STDERR_FILENO); + exit(1); +} + int main(int argc, char *argv[]) { + signal(SIGSEGV, sigsegv_handler); log4cpp::Appender *appender1 = new log4cpp::OstreamAppender("console", &std::cout); log4cpp::PatternLayout layout; @@ -51,14 +68,14 @@ int main(int argc, char *argv[]) { _1, _2, _3, _4); mumbleCommunicator.onIncomingChannelState = std::bind( - &mumble::MumbleChannelJoiner::checkChannel, - &mumbleChannelJoiner, - _1, _2); + &mumble::MumbleChannelJoiner::checkChannel, + &mumbleChannelJoiner, + _1, _2); mumbleCommunicator.onServerSync = std::bind( - &mumble::MumbleChannelJoiner::maybeJoinChannel, - &mumbleChannelJoiner, - &mumbleCommunicator); + &mumble::MumbleChannelJoiner::maybeJoinChannel, + &mumbleChannelJoiner, + &mumbleCommunicator); mumbleCommunicator.connect(