From 7c58af92cd856096151d6fe9da6a6bb62537164e Mon Sep 17 00:00:00 2001 From: faumaray Date: Mon, 22 Jun 2026 21:27:00 +0300 Subject: [PATCH] Install a Void::Stacktrace crash handler at plugin init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ts3plugin_init() sets a std::terminate handler that captures and prints a symbolized stack trace (with source snippets) before aborting — useful for diagnosing crashes in the hot-reloadable plugin. Link Void::Stacktrace. Co-Authored-By: Claude Opus 4.8 --- CMakeLists.txt | 3 ++- src/Plugin.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14cc008..5c972fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,14 @@ target_compile_definitions(EchoionPlugin PUBLIC PLUGIN=1) # - ApiOpaque (OpaqueHandle for type-safe void*) # - ApiPluginInterface (IPluginInterface to implement) # - ApiCoreInterface (ICoreInterface to call Core - decoupled) -target_link_libraries(EchoionPlugin PRIVATE +target_link_libraries(EchoionPlugin PRIVATE Echoion::ApiBase Echoion::ApiPlugin Echoion::ApiOpaque Echoion::ApiPluginInterface Echoion::ApiLogger Echoion::ApiCoreInterface + Void::Stacktrace ) find_package(dylib CONFIG REQUIRED) diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 1f669ab..7fca35f 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -3,6 +3,7 @@ #include "echoion/plugin/PluginInterface.hpp" #include "teamspeak/public_errors.h" #include +#include #include #include #include @@ -254,6 +255,21 @@ namespace Echoion::Plugin TS3_PLUGIN_API int ts3plugin_init() { std::cout << "[Echoion] Plugin init started" << std::endl; + + // Install a terminate handler that dumps a symbolized stack trace + // (with source snippets) before the process dies — invaluable for + // diagnosing crashes in a hot-reloadable plugin. + static std::once_flag terminateOnce; + std::call_once(terminateOnce, [] { + std::set_terminate([] { + std::cerr << "[Echoion] FATAL: std::terminate — stack trace:\n"; + const auto frames = Void::Stacktrace::capture_stacktrace(); + std::cerr << Void::Stacktrace::format_stacktrace(frames) + << std::endl; + std::abort(); + }); + }); + g_deferredInitThread = std::jthread(deferredInitialization); return 0; }