From 81b2e46df1e75d5c29cf4e23baa5f9bd2e47173f Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:13:48 -0400 Subject: [PATCH] Support stackwalk64 for 32-bit x86 --- src/unwind/unwind_with_dbghelp.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/unwind/unwind_with_dbghelp.cpp b/src/unwind/unwind_with_dbghelp.cpp index 7474c4b..a85ba52 100644 --- a/src/unwind/unwind_with_dbghelp.cpp +++ b/src/unwind/unwind_with_dbghelp.cpp @@ -32,9 +32,10 @@ namespace detail { // GetThreadContext cannot be used on the current thread. // RtlCaptureContext doesn't work on i386 CONTEXT context; - #ifdef _M_IX86 + #if defined(_M_IX86) || defined(__i386__) ZeroMemory(&context, sizeof(CONTEXT)); context.ContextFlags = CONTEXT_CONTROL; + #if IS_MSVC __asm { label: mov [context.Ebp], ebp; @@ -43,6 +44,18 @@ namespace detail { mov [context.Eip], eax; } #else + asm( + "label:\n\t" + "mov{l %%ebp, %[cEbp] | %[cEbp], ebp};\n\t" + "mov{l %%esp, %[cEsp] | %[cEsp], esp};\n\t" + "mov{l $label, %%eax | eax, label};\n\t" + "mov{l %%eax, %[cEip] | %[cEip], eax};\n\t" + : [cEbp] "=r" (context.Ebp), + [cEsp] "=r" (context.Esp), + [cEip] "=r" (context.Eip) + ); + #endif + #else RtlCaptureContext(&context); #endif // Setup current frame