Skip to content

Commit 852b3f9

Browse files
committed
Revert "Slightly refactor stackwalk64 capture frames implementation"
This reverts commit cbd5454.
1 parent cbd5454 commit 852b3f9

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

src/unwind/unwind.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88

99
#ifdef CPPTRACE_UNWIND_WITH_DBGHELP
10+
#define UNWIND_MAY_NEED_CONTEXT_RECORD
1011
#define WIN32_LEAN_AND_MEAN
1112
#include <windows.h>
1213
#endif

src/unwind/unwind_with_dbghelp.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@ namespace detail {
2323
#pragma warning(push)
2424
#pragma warning(disable: 4740) // warning C4740: flow in or out of inline asm code suppresses global optimization
2525
#endif
26-
void capture_context(CONTEXT& context) {
27-
#if defined(_M_IX86) || defined(__i386__)
28-
context.ContextFlags = CONTEXT_CONTROL;
29-
#if IS_MSVC
30-
__asm {
31-
label:
32-
mov [context.Ebp], ebp;
33-
mov [context.Esp], esp;
34-
mov eax, [label];
35-
mov [context.Eip], eax;
36-
}
37-
#else
38-
asm(
39-
"label:\n\t"
40-
"mov{l %%ebp, %[cEbp] | %[cEbp], ebp};\n\t"
41-
"mov{l %%esp, %[cEsp] | %[cEsp], esp};\n\t"
42-
"mov{l $label, %%eax | eax, OFFSET label};\n\t"
43-
"mov{l %%eax, %[cEip] | %[cEip], eax};\n\t"
44-
: [cEbp] "=r" (context.Ebp),
45-
[cEsp] "=r" (context.Esp),
46-
[cEip] "=r" (context.Eip)
47-
);
48-
#endif
49-
#else
50-
RtlCaptureContext(&context);
51-
#endif
52-
}
53-
5426
CPPTRACE_FORCE_NO_INLINE
5527
std::vector<frame_ptr> capture_frames(
5628
std::size_t skip,
@@ -68,7 +40,31 @@ namespace detail {
6840
if(exception_pointers) {
6941
context = *exception_pointers->ContextRecord;
7042
} else {
71-
capture_context(context);
43+
#if defined(_M_IX86) || defined(__i386__)
44+
context.ContextFlags = CONTEXT_CONTROL;
45+
#if IS_MSVC
46+
__asm {
47+
label:
48+
mov [context.Ebp], ebp;
49+
mov [context.Esp], esp;
50+
mov eax, [label];
51+
mov [context.Eip], eax;
52+
}
53+
#else
54+
asm(
55+
"label:\n\t"
56+
"mov{l %%ebp, %[cEbp] | %[cEbp], ebp};\n\t"
57+
"mov{l %%esp, %[cEsp] | %[cEsp], esp};\n\t"
58+
"mov{l $label, %%eax | eax, OFFSET label};\n\t"
59+
"mov{l %%eax, %[cEip] | %[cEip], eax};\n\t"
60+
: [cEbp] "=r" (context.Ebp),
61+
[cEsp] "=r" (context.Esp),
62+
[cEip] "=r" (context.Eip)
63+
);
64+
#endif
65+
#else
66+
RtlCaptureContext(&context);
67+
#endif
7268
}
7369
// Setup current frame
7470
STACKFRAME64 frame;
@@ -108,6 +104,11 @@ namespace detail {
108104

109105
// Dbghelp is is single-threaded, so acquire a lock.
110106
auto lock = get_dbghelp_lock();
107+
// For some reason SymInitialize must be called before StackWalk64
108+
// Note that the code assumes that
109+
// SymInitialize( GetCurrentProcess(), NULL, TRUE ) has
110+
// already been called.
111+
//
111112
auto syminit_info = ensure_syminit();
112113
HANDLE thread = GetCurrentThread();
113114
while(trace.size() < max_depth) {

0 commit comments

Comments
 (0)