1 // Copyright 2014-2015 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 //! Symbolication strategy using `dladdr`
12 //!
13 //! The `dladdr` API is available on most Unix implementations but it's quite
14 //! basic, not handling inline frame information at all. Since it's so prevalent
15 //! though we have an option to use it!
16 
17 use crate::symbolize::{dladdr, ResolveWhat, SymbolName};
18 use crate::types::BytesOrWideString;
19 use core::ffi::c_void;
20 
21 pub struct Symbol<'a>(dladdr::Symbol<'a>);
22 
23 impl Symbol<'_> {
name(&self) -> Option<SymbolName>24     pub fn name(&self) -> Option<SymbolName> {
25         self.0.name()
26     }
27 
addr(&self) -> Option<*mut c_void>28     pub fn addr(&self) -> Option<*mut c_void> {
29         self.0.addr()
30     }
31 
filename_raw(&self) -> Option<BytesOrWideString>32     pub fn filename_raw(&self) -> Option<BytesOrWideString> {
33         self.0.filename_raw()
34     }
35 
36     #[cfg(feature = "std")]
filename(&self) -> Option<&::std::path::Path>37     pub fn filename(&self) -> Option<&::std::path::Path> {
38         self.0.filename()
39     }
40 
lineno(&self) -> Option<u32>41     pub fn lineno(&self) -> Option<u32> {
42         self.0.lineno()
43     }
44 }
45 
resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol))46 pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
47     dladdr::resolve(what.address_or_ip(), &mut |sym| {
48         cb(&super::Symbol { inner: Symbol(sym) })
49     });
50 }
51