Skip to content

Commit bcaf946

Browse files
committed
Fix panic in backtrace symbolication on win7
Since #569 was merged, symbolication of backtraces would panic on Windows 7, due to using symbols that do not exist in the version of dbghelp.dll that ships there (Windows 7 ships with dbghelp.dll version 6.1, but the symbols were only added in version 6.2). This commit checks for the presence of the newer symbols, and if they are not found, falls back to the old resolution method.
1 parent aa0a5e2 commit bcaf946

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/dbghelp.rs

+12
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ dbghelp! {
233233
CurContext: LPDWORD,
234234
CurFrameIndex: LPDWORD
235235
) -> BOOL;
236+
fn SymFromAddrW(
237+
hProcess: HANDLE,
238+
Address: DWORD64,
239+
Displacement: PDWORD64,
240+
Symbol: PSYMBOL_INFOW
241+
) -> BOOL;
242+
fn SymGetLineFromAddrW64(
243+
hProcess: HANDLE,
244+
dwAddr: DWORD64,
245+
pdwDisplacement: PDWORD,
246+
Line: PIMAGEHLP_LINEW64
247+
) -> BOOL;
236248
}
237249
}
238250

src/symbolize/dbghelp.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ unsafe fn resolve_with_inline(
9898

9999
let (inlined_frame_count, inline_context) = if let Some(ic) = inline_context {
100100
(0, ic)
101+
} else if (*dbghelp.dbghelp()).SymAddrIncludeInlineTrace().is_none() {
102+
(0, 0)
101103
} else {
102104
let mut inlined_frame_count = dbghelp.SymAddrIncludeInlineTrace()(current_process, addr);
103105

@@ -129,17 +131,25 @@ unsafe fn resolve_with_inline(
129131
for inline_context in inline_context..last_inline_context {
130132
do_resolve(
131133
|info| {
132-
dbghelp.SymFromInlineContextW()(current_process, addr, inline_context, &mut 0, info)
134+
if (*dbghelp.dbghelp()).SymFromInlineContextW().is_some() {
135+
dbghelp.SymFromInlineContextW()(current_process, addr, inline_context, &mut 0, info)
136+
} else {
137+
dbghelp.SymFromAddrW()(current_process, addr, &mut 0, info)
138+
}
133139
},
134140
|line| {
135-
dbghelp.SymGetLineFromInlineContextW()(
136-
current_process,
137-
addr,
138-
inline_context,
139-
0,
140-
&mut 0,
141-
line,
142-
)
141+
if (*dbghelp.dbghelp()).SymGetLineFromInlineContextW().is_some() {
142+
dbghelp.SymGetLineFromInlineContextW()(
143+
current_process,
144+
addr,
145+
inline_context,
146+
0,
147+
&mut 0,
148+
line,
149+
)
150+
} else {
151+
dbghelp.SymGetLineFromAddrW64()(current_process, addr, &mut 0, line)
152+
}
143153
},
144154
cb,
145155
);

0 commit comments

Comments
 (0)