@@ -23,34 +23,6 @@ namespace detail {
23
23
#pragma warning(push)
24
24
#pragma warning(disable: 4740) // warning C4740: flow in or out of inline asm code suppresses global optimization
25
25
#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
-
54
26
CPPTRACE_FORCE_NO_INLINE
55
27
std::vector<frame_ptr> capture_frames (
56
28
std::size_t skip,
@@ -68,7 +40,31 @@ namespace detail {
68
40
if (exception_pointers) {
69
41
context = *exception_pointers->ContextRecord ;
70
42
} 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
72
68
}
73
69
// Setup current frame
74
70
STACKFRAME64 frame;
@@ -108,6 +104,11 @@ namespace detail {
108
104
109
105
// Dbghelp is is single-threaded, so acquire a lock.
110
106
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
+ //
111
112
auto syminit_info = ensure_syminit ();
112
113
HANDLE thread = GetCurrentThread ();
113
114
while (trace.size () < max_depth) {
0 commit comments