1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 use libc
::{c_ulong, c_int, c_char, c_void}
;
17 use sys
::dynamic_lib
::DynamicLibrary
;
18 use sys_common
::backtrace
::{output, output_fileline}
;
21 unsafe extern "system" fn(c
::HANDLE
, u64, *mut u64,
22 *mut c
::SYMBOL_INFO
) -> c
::BOOL
;
23 type SymGetLineFromAddr64Fn
=
24 unsafe extern "system" fn(c
::HANDLE
, u64, *mut u32,
25 *mut c
::IMAGEHLP_LINE64
) -> c
::BOOL
;
27 pub fn print(w
: &mut Write
,
31 dbghelp
: &DynamicLibrary
)
34 let SymFromAddr
= sym
!(dbghelp
, "SymFromAddr", SymFromAddrFn
);
35 let SymGetLineFromAddr64
= sym
!(dbghelp
,
36 "SymGetLineFromAddr64",
37 SymGetLineFromAddr64Fn
);
39 let mut info
: c
::SYMBOL_INFO
= mem
::zeroed();
40 info
.MaxNameLen
= c
::MAX_SYM_NAME
as c_ulong
;
41 // the struct size in C. the value is different to
42 // `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81)
43 // due to struct alignment.
44 info
.SizeOfStruct
= 88;
46 let mut displacement
= 0u64;
47 let ret
= SymFromAddr(process
, addr
, &mut displacement
, &mut info
);
49 let name
= if ret
== c
::TRUE
{
50 let ptr
= info
.Name
.as_ptr() as *const c_char
;
51 Some(CStr
::from_ptr(ptr
).to_bytes())
56 output(w
, i
, addr
as usize as *mut c_void
, name
)?
;
58 // Now find out the filename and line number
59 let mut line
: c
::IMAGEHLP_LINE64
= mem
::zeroed();
60 line
.SizeOfStruct
= ::mem
::size_of
::<c
::IMAGEHLP_LINE64
>() as u32;
62 let mut displacement
= 0u32;
63 let ret
= SymGetLineFromAddr64(process
, addr
, &mut displacement
, &mut line
);
66 CStr
::from_ptr(line
.Filename
).to_bytes(),
67 line
.LineNumber
as c_int
,