From 6aa60b548c9f16a495e3724082134a7f787a3bdb Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Fri, 26 Apr 2024 13:54:51 +0200 Subject: [PATCH] Pass MSVC exception through SetUnhandledExceptionFilter This restores ability to chain std::set_terminate handlers on Windows by passing MSVC C++ runtime exceptions using their 0xE06D7363 system code back to original handler that will later call backward-cpp's terminator. Without this other std::set_terminate handlers were blocked when using backward-cpp. --- backward.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backward.hpp b/backward.hpp index 670aa45..8f5a8c2 100644 --- a/backward.hpp +++ b/backward.hpp @@ -4333,8 +4333,7 @@ class SignalHandling { } cv().notify_one(); }) { - SetUnhandledExceptionFilter(crash_handler); - + *prev_exception_filter_ptr() = SetUnhandledExceptionFilter(crash_handler); signal(SIGABRT, signal_handler); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); @@ -4364,6 +4363,11 @@ class SignalHandling { return &data; } + static LPTOP_LEVEL_EXCEPTION_FILTER *prev_exception_filter_ptr() { + static LPTOP_LEVEL_EXCEPTION_FILTER prev_exception_filter; + return &prev_exception_filter; + } + enum class crash_status { running, crashed, normal_exit, ending }; static crash_status &crashed() { @@ -4427,6 +4431,11 @@ class SignalHandling { } NOINLINE static LONG WINAPI crash_handler(EXCEPTION_POINTERS *info) { + // Pass-through MSVC exceptions + if ((*prev_exception_filter_ptr()) != nullptr && + info->ExceptionRecord->ExceptionCode == 0xE06D7363) { + return (*prev_exception_filter_ptr())(info); + } // The exception info supplies a trace from exactly where the issue was, // no need to skip records crash_handler(0, info->ContextRecord);