]> git.proxmox.com Git - cargo.git/blob - vendor/backtrace/src/symbolize/dladdr_resolve.rs
New upstream version 0.37.0
[cargo.git] / vendor / backtrace / src / symbolize / dladdr_resolve.rs
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 core::ffi::c_void;
18 use crate::types::BytesOrWideString;
19 use crate::symbolize::{dladdr, SymbolName, ResolveWhat};
20
21 pub struct Symbol(dladdr::Symbol);
22
23 impl Symbol {
24 pub fn name(&self) -> Option<SymbolName> {
25 self.0.name()
26 }
27
28 pub fn addr(&self) -> Option<*mut c_void> {
29 self.0.addr()
30 }
31
32 pub fn filename_raw(&self) -> Option<BytesOrWideString> {
33 self.0.filename_raw()
34 }
35
36 #[cfg(feature = "std")]
37 pub fn filename(&self) -> Option<&::std::path::Path> {
38 self.0.filename()
39 }
40
41 pub fn lineno(&self) -> Option<u32> {
42 self.0.lineno()
43 }
44 }
45
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 {
49 inner: Symbol(sym),
50 })
51 });
52 }