Skip to content

Commit

Permalink
Fix panic in backtrace symbolication on win7
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
roblabla committed Nov 21, 2023
1 parent aa0a5e2 commit 3021657
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
14 changes: 13 additions & 1 deletion src/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod dbghelp {
use crate::windows::*;
pub use winapi::um::dbghelp::{
StackWalk64, StackWalkEx, SymFunctionTableAccess64, SymGetModuleBase64, SymGetOptions,
SymInitializeW, SymSetOptions,
SymInitializeW, SymSetOptions, SymFromAddrW, SymGetLineFromAddrW64
};

extern "system" {
Expand Down Expand Up @@ -233,6 +233,18 @@ dbghelp! {
CurContext: LPDWORD,
CurFrameIndex: LPDWORD
) -> BOOL;
fn SymFromAddrW(
hProcess: HANDLE,
Address: DWORD64,
Displacement: PDWORD64,
Symbol: PSYMBOL_INFOW
) -> BOOL;
fn SymGetLineFromAddrW64(
hProcess: HANDLE,
dwAddr: DWORD64,
pdwDisplacement: PDWORD,
Line: PIMAGEHLP_LINEW64
) -> BOOL;
}
}

Expand Down
28 changes: 19 additions & 9 deletions src/symbolize/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ unsafe fn resolve_with_inline(

let (inlined_frame_count, inline_context) = if let Some(ic) = inline_context {
(0, ic)
} else if (*dbghelp.dbghelp()).SymAddrIncludeInlineTrace().is_none() {
(0, 0)
} else {
let mut inlined_frame_count = dbghelp.SymAddrIncludeInlineTrace()(current_process, addr);

Expand Down Expand Up @@ -129,17 +131,25 @@ unsafe fn resolve_with_inline(
for inline_context in inline_context..last_inline_context {
do_resolve(
|info| {
dbghelp.SymFromInlineContextW()(current_process, addr, inline_context, &mut 0, info)
if (*dbghelp.dbghelp()).SymFromInlineContextW().is_some() {
dbghelp.SymFromInlineContextW()(current_process, addr, inline_context, &mut 0, info)
} else {
dbghelp.SymFromAddrW()(current_process, addr, &mut 0, info)
}
},
|line| {
dbghelp.SymGetLineFromInlineContextW()(
current_process,
addr,
inline_context,
0,
&mut 0,
line,
)
if (*dbghelp.dbghelp()).SymGetLineFromInlineContextW().is_some() {
dbghelp.SymGetLineFromInlineContextW()(
current_process,
addr,
inline_context,
0,
&mut 0,
line,
)
} else {
dbghelp.SymGetLineFromAddrW64()(current_process, addr, &mut 0, line)
}
},
cb,
);
Expand Down

0 comments on commit 3021657

Please sign in to comment.