@@ -15,8 +15,38 @@ use mem;
15
15
use sys:: backtrace:: BacktraceContext ;
16
16
use sys:: backtrace:: StackWalkVariant ;
17
17
use sys:: c;
18
+ use sys:: dynamic_lib:: DynamicLibrary ;
18
19
use sys_common:: backtrace:: Frame ;
19
20
21
+
22
+ // Structs holding printing functions and loaders for them
23
+ // Two versions depending on whether dbghelp.dll has StackWalkEx or not
24
+ // (the former being in newer Windows versions, the older being in Win7 and before)
25
+ pub struct PrintingFnsEx {
26
+ resolve_symname : SymFromInlineContextFn ,
27
+ sym_get_line : SymGetLineFromInlineContextFn ,
28
+ }
29
+ pub struct PrintingFns64 {
30
+ resolve_symname : SymFromAddrFn ,
31
+ sym_get_line : SymGetLineFromAddr64Fn ,
32
+ }
33
+
34
+ pub fn load_printing_fns_ex ( dbghelp : & DynamicLibrary ) -> io:: Result < PrintingFnsEx > {
35
+ Ok ( PrintingFnsEx {
36
+ resolve_symname : sym ! ( dbghelp, "SymFromInlineContext" ,
37
+ SymFromInlineContextFn ) ?,
38
+ sym_get_line : sym ! ( dbghelp, "SymGetLineFromInlineContext" ,
39
+ SymGetLineFromInlineContextFn ) ?,
40
+ } )
41
+ }
42
+ pub fn load_printing_fns_64 ( dbghelp : & DynamicLibrary ) -> io:: Result < PrintingFns64 > {
43
+ Ok ( PrintingFns64 {
44
+ resolve_symname : sym ! ( dbghelp, "SymFromAddr" , SymFromAddrFn ) ?,
45
+ sym_get_line : sym ! ( dbghelp, "SymGetLineFromAddr64" ,
46
+ SymGetLineFromAddr64Fn ) ?,
47
+ } )
48
+ }
49
+
20
50
type SymFromInlineContextFn =
21
51
unsafe extern "system" fn ( c:: HANDLE , u64 , c:: ULONG , * mut u64 , * mut c:: SYMBOL_INFO ) -> c:: BOOL ;
22
52
type SymGetLineFromInlineContextFn = unsafe extern "system" fn (
@@ -39,14 +69,11 @@ where
39
69
F : FnOnce ( Option < & str > ) -> io:: Result < ( ) > ,
40
70
{
41
71
match context. StackWalkVariant {
42
- StackWalkVariant :: StackWalkEx => {
43
- let SymFromInlineContext =
44
- sym ! ( & context. dbghelp, "SymFromInlineContext" , SymFromInlineContextFn ) ?;
45
- resolve_symname_from_inline_context ( SymFromInlineContext , frame, callback, context)
72
+ StackWalkVariant :: StackWalkEx ( _, ref fns) => {
73
+ resolve_symname_from_inline_context ( fns. resolve_symname , frame, callback, context)
46
74
} ,
47
- StackWalkVariant :: StackWalk64 => {
48
- let SymFromAddr = sym ! ( & context. dbghelp, "SymFromAddr" , SymFromAddrFn ) ?;
49
- resolve_symname_from_addr ( SymFromAddr , frame, callback, context)
75
+ StackWalkVariant :: StackWalk64 ( _, ref fns) => {
76
+ resolve_symname_from_addr ( fns. resolve_symname , frame, callback, context)
50
77
}
51
78
}
52
79
}
@@ -134,20 +161,10 @@ where
134
161
F : FnMut ( & [ u8 ] , u32 ) -> io:: Result < ( ) > ,
135
162
{
136
163
match context. StackWalkVariant {
137
- StackWalkVariant :: StackWalkEx => {
138
- let SymGetLineFromInlineContext =
139
- sym ! ( & context. dbghelp, "SymGetLineFromInlineContext" ,
140
- SymGetLineFromInlineContextFn ) ?;
141
- foreach_symbol_fileline_ex ( SymGetLineFromInlineContext ,
142
- frame, f, context)
143
- } ,
144
- StackWalkVariant :: StackWalk64 => {
145
- let SymGetLineFromAddr64 =
146
- sym ! ( & context. dbghelp, "SymGetLineFromAddr64" ,
147
- SymGetLineFromAddr64Fn ) ?;
148
- foreach_symbol_fileline_64 ( SymGetLineFromAddr64 ,
149
- frame, f, context)
150
- }
164
+ StackWalkVariant :: StackWalkEx ( _, ref fns) =>
165
+ foreach_symbol_fileline_ex ( fns. sym_get_line , frame, f, context) ,
166
+ StackWalkVariant :: StackWalk64 ( _, ref fns) =>
167
+ foreach_symbol_fileline_64 ( fns. sym_get_line , frame, f, context) ,
151
168
}
152
169
}
153
170
0 commit comments