From 046ae76acc4710957354d96c1d1df59b640e9437 Mon Sep 17 00:00:00 2001 From: peter23 Date: Sat, 14 Sep 2024 02:53:33 +0300 Subject: [PATCH] Show additional info about Windows exception --- backward.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backward.hpp b/backward.hpp index 670aa45..1310640 100644 --- a/backward.hpp +++ b/backward.hpp @@ -4426,7 +4426,14 @@ class SignalHandling { abort(); } + static EXCEPTION_RECORD &exc_rec() { + static EXCEPTION_RECORD data{0}; + return data; + } + NOINLINE static LONG WINAPI crash_handler(EXCEPTION_POINTERS *info) { + exc_rec() = *(info->ExceptionRecord); + // The exception info supplies a trace from exactly where the issue was, // no need to skip records crash_handler(0, info->ContextRecord); @@ -4460,6 +4467,17 @@ class SignalHandling { } static void handle_stacktrace(int skip_frames = 0) { + if(exc_rec().ExceptionCode || exc_rec().ExceptionAddress) { + std::cerr << "EXCEPTION 0x" << std::hex << exc_rec().ExceptionCode << " @ 0x" << std::hex << exc_rec().ExceptionAddress << std::dec << std::endl; + if(exc_rec().NumberParameters) { + std::cerr << "Exception params: "; + for(auto i = 0; i < exc_rec().NumberParameters; i++) { + std::cerr << "#" << i << "=0x" << std::hex << exc_rec().ExceptionInformation[i] << std::dec << " "; + } + std::cerr << std::endl; + } + } + // printer creates the TraceResolver, which can supply us a machine type // for stack walking. Without this, StackTrace can only guess using some // macros.