@@ -23,6 +23,34 @@ 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
+
26
54
CPPTRACE_FORCE_NO_INLINE
27
55
std::vector<frame_ptr> capture_frames (
28
56
std::size_t skip,
@@ -40,31 +68,7 @@ namespace detail {
40
68
if (exception_pointers) {
41
69
context = *exception_pointers->ContextRecord ;
42
70
} else {
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
71
+ capture_context (context);
68
72
}
69
73
// Setup current frame
70
74
STACKFRAME64 frame;
@@ -104,11 +108,6 @@ namespace detail {
104
108
105
109
// Dbghelp is is single-threaded, so acquire a lock.
106
110
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
- //
112
111
auto syminit_info = ensure_syminit ();
113
112
HANDLE thread = GetCurrentThread ();
114
113
while (trace.size () < max_depth) {
0 commit comments