Skip to content

Commit adc9f5c

Browse files
authored
Correct base address and update dbghelp64 comment (#604)
I've been staring at the code a lot lately but somehow missed that we're returning the wrong thing for the module base. It *probably* works out ok because a) most things only care that the pointer points to something within the right module and b) backtrace doesn't use it. I added a comment because apparently I need the obvious pointed out to me. Also while I'm at it I updated a 64-bit comment to remove the stuff commenting on 32-bit code (which is now in another file).
1 parent eabeb5e commit adc9f5c

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/backtrace/dbghelp64.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
//! Backtrace strategy for MSVC platforms.
1+
//! Backtrace strategy for MSVC `x86_64` and `aarch64` platforms.
22
//!
3-
//! This module contains the ability to capture a backtrace on MSVC using one
4-
//! of three possible methods. For `x86_64` and `aarch64`, we use `RtlVirtualUnwind`
5-
//! to walk the stack one frame at a time. This function is much faster than using
3+
//! This module contains the ability to capture a backtrace on MSVC using
4+
//! `RtlVirtualUnwind` to walk the stack one frame at a time. This function is much faster than using
65
//! `dbghelp!StackWalk*` because it does not load debug info to report inlined frames.
76
//! We still report inlined frames during symbolization by consulting the appropriate
87
//! `dbghelp` functions.
9-
//!
10-
//! For all other platforms, primarily `i686`, the `StackWalkEx` function is used if
11-
//! possible, but not all systems have that. Failing that the `StackWalk64` function
12-
//! is used instead. Note that `StackWalkEx` is favored because it handles debuginfo
13-
//! internally and returns inline frame information.
14-
//!
15-
//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs`
16-
//! for more information about that.
178
189
#![allow(bad_style)]
1910

@@ -100,6 +91,8 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
10091

10192
// Call `RtlVirtualUnwind` to find the previous stack frame, walking until we hit ip = 0.
10293
while context.ip() != 0 {
94+
// The base address of the module containing the function will be stored here
95+
// when RtlLookupFunctionEntry returns successfully.
10396
let mut base = 0;
10497

10598
let fn_entry = RtlLookupFunctionEntry(context.ip(), &mut base, ptr::null_mut());
@@ -109,7 +102,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
109102

110103
let frame = super::Frame {
111104
inner: Frame {
112-
base_address: fn_entry.cast::<c_void>(),
105+
base_address: base as *mut c_void,
113106
ip: context.ip() as *mut c_void,
114107
sp: context.sp() as *mut c_void,
115108
#[cfg(not(target_env = "gnu"))]

0 commit comments

Comments
 (0)