From 701754445d9e8a126ccff7fa321b23814f549266 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 25 Mar 2024 15:25:56 +0000 Subject: [PATCH 1/2] Use correct base address --- src/backtrace/dbghelp64.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index d3ae06df..52c9fc11 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -100,6 +100,8 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { // Call `RtlVirtualUnwind` to find the previous stack frame, walking until we hit ip = 0. while context.ip() != 0 { + // The base address of the module containing the function will be stored here + // when RtlLookupFunctionEntry returns successfully. let mut base = 0; let fn_entry = RtlLookupFunctionEntry(context.ip(), &mut base, ptr::null_mut()); @@ -109,7 +111,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { let frame = super::Frame { inner: Frame { - base_address: fn_entry.cast::(), + base_address: base as *mut c_void, ip: context.ip() as *mut c_void, sp: context.sp() as *mut c_void, #[cfg(not(target_env = "gnu"))] From 69c7cca4a7ad824dfdbcf9e980d69554be139ff9 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 25 Mar 2024 15:30:19 +0000 Subject: [PATCH 2/2] Update dbghelp64 comment --- src/backtrace/dbghelp64.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index 52c9fc11..9e7c9a0d 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -1,19 +1,10 @@ -//! Backtrace strategy for MSVC platforms. +//! Backtrace strategy for MSVC `x86_64` and `aarch64` platforms. //! -//! This module contains the ability to capture a backtrace on MSVC using one -//! of three possible methods. For `x86_64` and `aarch64`, we use `RtlVirtualUnwind` -//! to walk the stack one frame at a time. This function is much faster than using +//! This module contains the ability to capture a backtrace on MSVC using +//! `RtlVirtualUnwind` to walk the stack one frame at a time. This function is much faster than using //! `dbghelp!StackWalk*` because it does not load debug info to report inlined frames. //! We still report inlined frames during symbolization by consulting the appropriate //! `dbghelp` functions. -//! -//! For all other platforms, primarily `i686`, the `StackWalkEx` function is used if -//! possible, but not all systems have that. Failing that the `StackWalk64` function -//! is used instead. Note that `StackWalkEx` is favored because it handles debuginfo -//! internally and returns inline frame information. -//! -//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs` -//! for more information about that. #![allow(bad_style)]