Skip to content

std::rt::backtrace: Fix symbol names on Windows #17425

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions src/libstd/rt/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ mod imp {
static IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200;
static IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664;

#[repr(C, packed)]
#[repr(C)]
struct SYMBOL_INFO {
SizeOfStruct: libc::c_ulong,
TypeIndex: libc::c_ulong,
Expand Down Expand Up @@ -983,8 +983,10 @@ mod imp {
try!(write!(w, " {:2}: {:#2$x}", i, addr, super::HEX_WIDTH));
let mut info: SYMBOL_INFO = unsafe { intrinsics::init() };
info.MaxNameLen = MAX_SYM_NAME as libc::c_ulong;
info.SizeOfStruct = (mem::size_of::<SYMBOL_INFO>() -
info.Name.len() + 1) as libc::c_ulong;
// the struct size in C. the value is different to
// `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81)
// due to struct alignment.
info.SizeOfStruct = 88;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks future-proof ¯_(ツ)_/¯

let align = align_of_val(&info) - 1;
info.SizeOfStruct = (size_of_val(&info) - MAX_SYM_NAME + 1 + align) & !align;


let mut displacement = 0u64;
let ret = SymFromAddr(process, addr as u64, &mut displacement,
Expand Down