Skip to content

Commit 2fb8a19

Browse files
committed
Offset by one in libbacktrace on Windows too
1 parent 6f6276e commit 2fb8a19

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/symbolize/libbacktrace.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,19 @@ unsafe fn init_state() -> *mut bt::backtrace_state {
408408
}
409409

410410
pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
411-
let symaddr = what.address_or_ip();
411+
let mut symaddr = what.address_or_ip() as usize;
412+
413+
// It's sort of unclear why this is necessary, but it appears that the ip
414+
// values from stack traces are typically the instruction *after* the call
415+
// that's the actual stack trace. Symbolizing this on Windows causes the
416+
// filename/line number to be one ahead and perhaps into the void if it's
417+
// near the end of the function. Apparently on Unix though it's roughly fine
418+
// in that the filename/line number turn out alright. For now just try to
419+
// get good backtraces with this, and hopefully one day we can figure out
420+
// why the `-=1` is here.
421+
if cfg!(windows) && symaddr > 0 {
422+
symaddr -= 1;
423+
}
412424

413425
// backtrace errors are currently swept under the rug
414426
let state = init_state();
@@ -423,7 +435,7 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
423435
// Note that we do this since `syminfo` will consult the symbol table,
424436
// finding symbol names even if there's no debug information in the binary.
425437
let mut syminfo_state = SyminfoState {
426-
pc: symaddr as usize,
438+
pc: symaddr,
427439
cb: cb,
428440
};
429441
bt::backtrace_syminfo(

0 commit comments

Comments
 (0)