diff options
| author | Richard Diamond <wichard@vitalitystudios.com> | 2015-08-19 23:55:50 -0500 |
|---|---|---|
| committer | Richard Diamond <wichard@vitalitystudios.com> | 2015-08-20 15:20:55 -0500 |
| commit | 7925c7972ee6f3ea08b90dba32a8eafe5bd71792 (patch) | |
| tree | ffd74ccc1dcd737e57955a3a341affdca558cecf /src/libstd/sys/unix/backtrace/printing/dladdr.rs | |
| parent | aca2057ed5fb7af3f8905b2bc01f72fa001c35c8 (diff) | |
| download | rust-7925c7972ee6f3ea08b90dba32a8eafe5bd71792.tar.gz rust-7925c7972ee6f3ea08b90dba32a8eafe5bd71792.zip | |
Refactor unix backtracing. NFC.
Diffstat (limited to 'src/libstd/sys/unix/backtrace/printing/dladdr.rs')
| -rw-r--r-- | src/libstd/sys/unix/backtrace/printing/dladdr.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/backtrace/printing/dladdr.rs b/src/libstd/sys/unix/backtrace/printing/dladdr.rs new file mode 100644 index 00000000000..fc7894a97b0 --- /dev/null +++ b/src/libstd/sys/unix/backtrace/printing/dladdr.rs @@ -0,0 +1,35 @@ +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void, + _symaddr: *mut libc::c_void) -> io::Result<()> { + use sys::backtrace::{output}; + use intrinsics; + #[repr(C)] + struct Dl_info { + dli_fname: *const libc::c_char, + dli_fbase: *mut libc::c_void, + dli_sname: *const libc::c_char, + dli_saddr: *mut libc::c_void, + } + extern { + fn dladdr(addr: *const libc::c_void, + info: *mut Dl_info) -> libc::c_int; + } + + let mut info: Dl_info = unsafe { intrinsics::init() }; + if unsafe { dladdr(addr, &mut info) == 0 } { + output(w, idx,addr, None) + } else { + output(w, idx, addr, Some(unsafe { + CStr::from_ptr(info.dli_sname).to_bytes() + })) + } +} |
