Skip to content

Commit

Permalink
Fix build errors on thumbv7a-*-windows-msvc targets
Browse files Browse the repository at this point in the history
Resolves: rust-lang#572
  • Loading branch information
kleisauke committed Nov 4, 2023
1 parent e9da96e commit 0329af0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions src/backtrace/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,21 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
Some(StackWalkEx) => {
let mut stack_frame_ex: STACKFRAME_EX = mem::zeroed();
stack_frame_ex.StackFrameSize = mem::size_of::<STACKFRAME_EX>() as DWORD;
stack_frame_ex.AddrPC.Offset = context.0.Eip as u64;

cfg_if::cfg_if! {
if #[cfg(target_arch = "x86")] {
stack_frame_ex.AddrPC.Offset = context.0.Eip as u64;
stack_frame_ex.AddrStack.Offset = context.0.Esp as u64;
stack_frame_ex.AddrFrame.Offset = context.0.Ebp as u64;
} else {
stack_frame_ex.AddrPC.Offset = context.0.Pc as u64;
stack_frame_ex.AddrStack.Offset = context.0.Sp as u64;
stack_frame_ex.AddrFrame.Offset = context.0.R11 as u64;
}
}

stack_frame_ex.AddrPC.Mode = AddrModeFlat;
stack_frame_ex.AddrStack.Offset = context.0.Esp as u64;
stack_frame_ex.AddrStack.Mode = AddrModeFlat;
stack_frame_ex.AddrFrame.Offset = context.0.Ebp as u64;
stack_frame_ex.AddrFrame.Mode = AddrModeFlat;

while StackWalkEx(
Expand Down Expand Up @@ -205,11 +215,21 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
}
None => {
let mut stack_frame64: STACKFRAME64 = mem::zeroed();
stack_frame64.AddrPC.Offset = context.0.Eip as u64;

cfg_if::cfg_if! {
if #[cfg(target_arch = "x86")] {
stack_frame64.AddrPC.Offset = context.0.Eip as u64;
stack_frame64.AddrStack.Offset = context.0.Esp as u64;
stack_frame64.AddrFrame.Offset = context.0.Ebp as u64;
} else {
stack_frame64.AddrPC.Offset = context.0.Pc as u64;
stack_frame64.AddrStack.Offset = context.0.Sp as u64;
stack_frame64.AddrFrame.Offset = context.0.R11 as u64;
}
}

stack_frame64.AddrPC.Mode = AddrModeFlat;
stack_frame64.AddrStack.Offset = context.0.Esp as u64;
stack_frame64.AddrStack.Mode = AddrModeFlat;
stack_frame64.AddrFrame.Offset = context.0.Ebp as u64;
stack_frame64.AddrFrame.Mode = AddrModeFlat;

while dbghelp.StackWalk64()(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod lock {

#[cfg(all(
windows,
any(target_env = "msvc", all(target_env = "gnu", target_arch = "x86")),
any(target_env = "msvc", all(target_env = "gnu", any(target_arch = "x86", target_arch = "arm"))),
not(target_vendor = "uwp")
))]
mod dbghelp;
Expand Down

0 comments on commit 0329af0

Please sign in to comment.