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.
11 use sys_common
::backtrace
::{output, output_fileline}
;
13 use dynamic_lib
::DynamicLibrary
;
14 use super::{SymFromAddrFn, SymGetLineFromAddr64Fn, SYMBOL_INFO, MAX_SYM_NAME, IMAGEHLP_LINE64}
;
20 pub fn print(w
: &mut Write
, i
: isize, addr
: u64, dbghelp
: &DynamicLibrary
, process
: libc
::HANDLE
)
22 let SymFromAddr
= sym
!(dbghelp
, "SymFromAddr", SymFromAddrFn
);
23 let SymGetLineFromAddr64
= sym
!(dbghelp
, "SymGetLineFromAddr64", SymGetLineFromAddr64Fn
);
25 let mut info
: SYMBOL_INFO
= unsafe { intrinsics::init() }
;
26 info
.MaxNameLen
= MAX_SYM_NAME
as libc
::c_ulong
;
27 // the struct size in C. the value is different to
28 // `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81)
29 // due to struct alignment.
30 info
.SizeOfStruct
= 88;
32 let mut displacement
= 0u64;
33 let ret
= SymFromAddr(process
, addr
, &mut displacement
, &mut info
);
35 let name
= if ret
== libc
::TRUE
{
36 let ptr
= info
.Name
.as_ptr() as *const libc
::c_char
;
37 Some(unsafe { CStr::from_ptr(ptr).to_bytes() }
)
42 try
!(output(w
, i
, addr
as usize as *mut libc
::c_void
, name
));
44 // Now find out the filename and line number
45 let mut line
: IMAGEHLP_LINE64
= unsafe { intrinsics::init() }
;
46 line
.SizeOfStruct
= ::mem
::size_of
::<IMAGEHLP_LINE64
>() as u32;
48 let mut displacement
= 0u32;
49 let ret
= SymGetLineFromAddr64(process
, addr
, &mut displacement
, &mut line
);
50 if ret
== libc
::TRUE
{
52 unsafe { CStr::from_ptr(line.Filename).to_bytes() }
,
53 line
.LineNumber
as libc
::c_int
,