]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys/windows/printing/msvc.rs
Move away from hash to the same rust naming schema
[rustc.git] / src / libstd / sys / windows / printing / msvc.rs
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.
4 //
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.
10
11 use sys_common::backtrace::{output, output_fileline};
12 use ffi::CStr;
13 use dynamic_lib::DynamicLibrary;
14 use super::{SymFromAddrFn, SymGetLineFromAddr64Fn, SYMBOL_INFO, MAX_SYM_NAME, IMAGEHLP_LINE64};
15 use io;
16 use io::prelude::*;
17 use intrinsics;
18 use libc;
19
20 pub fn print(w: &mut Write, i: isize, addr: u64, dbghelp: &DynamicLibrary, process: libc::HANDLE)
21 -> io::Result<()> {
22 let SymFromAddr = sym!(dbghelp, "SymFromAddr", SymFromAddrFn);
23 let SymGetLineFromAddr64 = sym!(dbghelp, "SymGetLineFromAddr64", SymGetLineFromAddr64Fn);
24
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;
31
32 let mut displacement = 0u64;
33 let ret = SymFromAddr(process, addr, &mut displacement, &mut info);
34
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() })
38 } else {
39 None
40 };
41
42 try!(output(w, i, addr as usize as *mut libc::c_void, name));
43
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;
47
48 let mut displacement = 0u32;
49 let ret = SymGetLineFromAddr64(process, addr, &mut displacement, &mut line);
50 if ret == libc::TRUE {
51 output_fileline(w,
52 unsafe { CStr::from_ptr(line.Filename).to_bytes() },
53 line.LineNumber as libc::c_int,
54 false)
55 } else {
56 Ok(())
57 }
58 }