Skip to content

Use correct base address and update comment #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/backtrace/dbghelp64.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
//! Backtrace strategy for MSVC platforms.
//! Backtrace strategy for MSVC `x86_64` and `aarch64` platforms.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it's used also for gnu and gnullvm:

} else if #[cfg(
any(
all(
unix,
not(target_os = "emscripten"),
not(all(target_os = "ios", target_arch = "arm")),
not(all(target_os = "nto", target_env = "nto70")),
),
all(
target_env = "sgx",
target_vendor = "fortanix",
),
)
)] {

Also confirmed here: msys2/MINGW-packages#20651 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey it was like that when I got here 😅

But yes, that should just say Windows. I guess it was once MSVC only.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I just wanted to point out a preexisting issue.

//!
//! 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)]

Expand Down Expand Up @@ -100,6 +91,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());
Expand All @@ -109,7 +102,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {

let frame = super::Frame {
inner: Frame {
base_address: fn_entry.cast::<c_void>(),
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"))]
Expand Down