From 3d1384331f8fc933e2fa58849afd1a5ea114ce52 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 8 Apr 2020 13:05:47 +0300 Subject: [PATCH] feat: print stack trace in case of SIGSEGV and SIGABRT We print stack trace using boost::stacktrace::stacktrace() which is not the safest way to do it in a signal handler however it gives us more info if compared to safe call. xibosignage#184 --- player/CMakeLists.txt | 11 +++++++++-- player/main.cpp | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/player/CMakeLists.txt b/player/CMakeLists.txt index 00a2be816..f0c21e278 100644 --- a/player/CMakeLists.txt +++ b/player/CMakeLists.txt @@ -16,10 +16,15 @@ set(CMAKE_TESTS_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests/) add_compile_options( -static-libstdc++ -pthread -Wall -Wno-parentheses -Wno-cast-function-type -W -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings "$<$:-O2>" - "$<$:-g;-O0>" + "$<$:-g3;-O0>" ) -add_compile_definitions(BOOST_THREAD_PROVIDES_FUTURE BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION) +add_compile_definitions( + BOOST_THREAD_PROVIDES_FUTURE + BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION + BOOST_STACKTRACE_USE_ADDR2LINE + BOOST_STACKTRACE_USE_BACKTRACE +) option(SNAP_BUILD "Use SNAP environment during build" OFF) if(SNAP_BUILD) @@ -47,6 +52,8 @@ target_link_libraries(${PROJECT_NAME} config control system + dl + backtrace ) configure_file(ui.glade ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ui.glade COPYONLY) diff --git a/player/main.cpp b/player/main.cpp index de9d291c8..c15366763 100644 --- a/player/main.cpp +++ b/player/main.cpp @@ -1,9 +1,28 @@ #include "XiboApp.hpp" - #include "common/logger/Logging.hpp" +#include +#include +#include + +/* DISCLAIMER + * Boost provide boost::stacktrace::stacktrace::safe_dump_to which statisfies the signal-safety + * requirements, however, it gives very unuseful stacktrace without function names/lines. So we + * decide to go with unsafe stacktrace taking into account we call it in SIGSEGV and SIGABRT + * signal handlers which are already the indicators of fatal error + */ +void signalStacktraceHandler(int signum) +{ + signal(signum, SIG_DFL); + std::cout << boost::stacktrace::stacktrace() << std::endl; + raise(signum); +} + int main(int /*argc*/, char** /*argv*/) { + signal(SIGSEGV, &signalStacktraceHandler); + signal(SIGABRT, &signalStacktraceHandler); + try { auto&& app = XiboApp::create("org.gtkmm.xibo");