From 18f8f1c2c8f7d835b5fcf068c6e7d30bf7c1315e Mon Sep 17 00:00:00 2001 From: iSolo Date: Wed, 10 Apr 2024 18:59:15 +0300 Subject: [PATCH] Use RtlCaptureStackBackTrace instead of StackWalk64 in case of missing context --- backward.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backward.hpp b/backward.hpp index 670aa45..53259af 100644 --- a/backward.hpp +++ b/backward.hpp @@ -1136,6 +1136,15 @@ class StackTraceImpl : public StackTraceImplHolder { void *error_addr = nullptr) { set_context(static_cast(context)); set_error_addr(error_addr); + + if (!context) { + _stacktrace.resize(depth); + const WORD capturedFrames = RtlCaptureStackBackTrace( + 0, static_cast(depth), _stacktrace.data(), NULL); + _stacktrace.resize(capturedFrames); + return capturedFrames; + } + CONTEXT localCtx; // used when no context is provided if (depth == 0) {