From 9f7064676c238585713144d9b52b8aa789eb9fd0 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 15:01:41 +0200 Subject: Get rid of boost dependency for stacktraces --- src/main.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index fe1a9ee3..f4484f94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,15 +40,48 @@ QQmlDebuggingEnabler enabler; #endif -#if defined(Q_OS_LINUX) -#include +#if HAVE_BACKTRACE_SYMBOLS_FD #include +#include +#include +#include void stacktraceHandler(int signum) { std::signal(signum, SIG_DFL); - boost::stacktrace::safe_dump_to("./nheko-backtrace.dump"); + + // boost::stacktrace::safe_dump_to("./nheko-backtrace.dump"); + + // see + // https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes/77336#77336 + void *array[50]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, 50); + + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", signum); + backtrace_symbols_fd(array, size, STDERR_FILENO); + + int file = ::open("/tmp/nheko-crash.dump", + O_CREAT | O_WRONLY | O_TRUNC +#if defined(S_IWUSR) && defined(S_IRUSR) + , + S_IWUSR | S_IRUSR +#elif defined(S_IWRITE) && defined(S_IREAD) + , + S_IWRITE | S_IREAD +#endif + ); + if (file != -1) { + constexpr char header[] = "Error: signal\n"; + write(file, header, std::size(header) - 1); + backtrace_symbols_fd(array, size, file); + close(file); + } + std::raise(SIGABRT); } -- cgit 1.5.1 From 66e69d7f2b8568c304bdc280d15f543e49d1721c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 15:28:44 +0200 Subject: Ignore return value of write() in signal handler --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index f4484f94..29e93d49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,8 +76,8 @@ stacktraceHandler(int signum) #endif ); if (file != -1) { - constexpr char header[] = "Error: signal\n"; - write(file, header, std::size(header) - 1); + constexpr char header[] = "Error: signal\n"; + [[maybe_unused]] auto ret = write(file, header, std::size(header) - 1); backtrace_symbols_fd(array, size, file); close(file); } -- cgit 1.5.1 From 478c3b3e0b19d0b9a97542a9b91ca5329fbd5425 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 7 Jul 2021 00:26:03 -0400 Subject: Fix Backtrace define error for Windows --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 29e93d49..bb6f946b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,6 +40,7 @@ QQmlDebuggingEnabler enabler; #endif +#if !defined(Q_OS_WINDOWS) #if HAVE_BACKTRACE_SYMBOLS_FD #include #include @@ -92,6 +93,7 @@ registerSignalHandlers() std::signal(SIGABRT, &stacktraceHandler); } +#endif #else // No implementation for systems with no stacktrace support. -- cgit 1.5.1 From 82088fa0d7746308aa0fe5be73a5a6a24cec27ac Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 7 Jul 2021 09:48:13 -0400 Subject: Fix cmake template define issue --- cmake/nheko.h | 4 +--- src/main.cpp | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src/main.cpp') diff --git a/cmake/nheko.h b/cmake/nheko.h index c2329917..ae28aea9 100644 --- a/cmake/nheko.h +++ b/cmake/nheko.h @@ -4,6 +4,4 @@ constexpr auto build_os = "${CMAKE_HOST_SYSTEM_NAME}"; constexpr auto enable_debug_log = ${SPDLOG_DEBUG_ON}; } -// clang-format off -#define HAVE_BACKTRACE_SYMBOLS_FD ${HAVE_BACKTRACE_SYMBOLS_FD} -// clang-format on +# cmakedefine01 HAVE_BACKTRACE_SYMBOLS_FD diff --git a/src/main.cpp b/src/main.cpp index bb6f946b..29e93d49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,6 @@ QQmlDebuggingEnabler enabler; #endif -#if !defined(Q_OS_WINDOWS) #if HAVE_BACKTRACE_SYMBOLS_FD #include #include @@ -93,7 +92,6 @@ registerSignalHandlers() std::signal(SIGABRT, &stacktraceHandler); } -#endif #else // No implementation for systems with no stacktrace support. -- cgit 1.5.1