Get rid of boost dependency for stacktraces

This commit is contained in:
Nicolas Werner 2021-06-30 15:01:41 +02:00
parent a2c4d0875c
commit 9f7064676c
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 48 additions and 7 deletions

View file

@ -265,7 +265,10 @@ set(PROJECT_VERSION ${CPACK_PACKAGE_VERSION})
message(STATUS "Version: ${PROJECT_VERSION}") message(STATUS "Version: ${PROJECT_VERSION}")
cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME) cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME)
set(BUILD_USER $ENV{USER})
include(CheckSymbolExists)
check_symbol_exists(backtrace_symbols_fd "execinfo.h" HAVE_BACKTRACE_SYMBOLS_FD)
configure_file(cmake/nheko.h config/nheko.h) configure_file(cmake/nheko.h config/nheko.h)
@ -607,6 +610,10 @@ if(WIN32)
target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601) target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601)
else() else()
add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS}) add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS})
if (HAVE_BACKTRACE_SYMBOLS_FD AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
set_target_properties(nheko PROPERTIES ENABLE_EXPORTS ON)
endif()
endif() endif()
if(APPLE) if(APPLE)

View file

@ -1,6 +1,9 @@
namespace nheko { namespace nheko {
constexpr auto version = "${PROJECT_VERSION}"; constexpr auto version = "${PROJECT_VERSION}";
constexpr auto build_user = "${BUILD_USER}@${BUILD_HOST}";
constexpr auto build_os = "${CMAKE_HOST_SYSTEM_NAME}"; constexpr auto build_os = "${CMAKE_HOST_SYSTEM_NAME}";
constexpr auto enable_debug_log = ${SPDLOG_DEBUG_ON}; constexpr auto enable_debug_log = ${SPDLOG_DEBUG_ON};
} }
// clang-format off
#define HAVE_BACKTRACE_SYMBOLS_FD ${HAVE_BACKTRACE_SYMBOLS_FD}
// clang-format on

View file

@ -4,8 +4,6 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <memory> #include <memory>
#include <mtx/events.hpp> #include <mtx/events.hpp>
#include <mtx/events/encrypted.hpp> #include <mtx/events/encrypted.hpp>

View file

@ -40,15 +40,48 @@
QQmlDebuggingEnabler enabler; QQmlDebuggingEnabler enabler;
#endif #endif
#if defined(Q_OS_LINUX) #if HAVE_BACKTRACE_SYMBOLS_FD
#include <boost/stacktrace.hpp>
#include <csignal> #include <csignal>
#include <execinfo.h>
#include <fcntl.h>
#include <unistd.h>
void void
stacktraceHandler(int signum) stacktraceHandler(int signum)
{ {
std::signal(signum, SIG_DFL); 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); std::raise(SIGABRT);
} }