Skip to content

More improvements to gimli support #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ rustc-serialize = { version = "0.3", optional = true }
cpp_demangle = { default-features = false, version = "0.2.3", optional = true }

# Optional dependencies enabled through the `gimli-symbolize` feature
addr2line = { version = "0.9.0", optional = true, default-features = false, features = ['std', 'std-object'] }
addr2line = { version = "0.9.0", optional = true, default-features = false, features = ['std'] }
findshlibs = { version = "0.5.0", optional = true }
memmap = { version = "0.7.0", optional = true }
goblin = { version = "0.0.22", optional = true, default-features = false, features = ['std'] }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.3", optional = true }
goblin = { version = "0.0.22", optional = true, default-features = false, features = ['pe32', 'pe64'] }
[target.'cfg(target_os = "macos")'.dependencies]
goblin = { version = "0.0.22", optional = true, default-features = false, features = ['mach32', 'mach64'] }
[target.'cfg(not(any(target_os = "macos", windows)))'.dependencies]
goblin = { version = "0.0.22", optional = true, default-features = false, features = ['elf32', 'elf64'] }

# Each feature controls the two phases of finding a backtrace: getting a
# backtrace and then resolving instruction pointers to symbols. The default
Expand Down Expand Up @@ -92,7 +98,7 @@ kernel32 = []
libbacktrace = ["backtrace-sys"]
dladdr = []
coresymbolication = []
gimli-symbolize = ["addr2line", "findshlibs", "memmap"]
gimli-symbolize = ["addr2line", "findshlibs", "memmap", "goblin"]

#=======================================
# Methods of serialization
Expand Down
6 changes: 3 additions & 3 deletions src/symbolize/coresymbolication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ const CSREF_NULL: CSTypeRef = CSTypeRef {
cpp_obj: 0 as *const c_void,
};

pub enum Symbol {
pub enum Symbol<'a> {
Core {
path: *const c_char,
lineno: u32,
name: *const c_char,
addr: *mut c_void,
},
Dladdr(dladdr::Symbol),
Dladdr(dladdr::Symbol<'a>),
}

impl Symbol {
impl Symbol<'_> {
pub fn name(&self) -> Option<SymbolName> {
let name = match *self {
Symbol::Core { name, .. } => name,
Expand Down
7 changes: 5 additions & 2 deletions src/symbolize/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ use crate::windows::*;
use crate::SymbolName;
use core::char;
use core::ffi::c_void;
use core::marker;
use core::mem;
use core::slice;

// Store an OsString on std so we can provide the symbol name and filename.
pub struct Symbol {
pub struct Symbol<'a> {
name: *const [u8],
addr: *mut c_void,
line: Option<u32>,
Expand All @@ -48,9 +49,10 @@ pub struct Symbol {
_filename_cache: Option<::std::ffi::OsString>,
#[cfg(not(feature = "std"))]
_filename_cache: (),
_marker: marker::PhantomData<&'a i32>,
}

impl Symbol {
impl Symbol<'_> {
pub fn name(&self) -> Option<SymbolName> {
Some(SymbolName::new(unsafe { &*self.name }))
}
Expand Down Expand Up @@ -209,6 +211,7 @@ unsafe fn do_resolve(
line: lineno,
filename,
_filename_cache: cache(filename),
_marker: marker::PhantomData,
},
})
}
Expand Down
38 changes: 23 additions & 15 deletions src/symbolize/dladdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@

cfg_if::cfg_if! {
if #[cfg(all(unix, not(target_os = "emscripten"), feature = "dladdr"))] {
use core::ffi::c_void;
use core::marker;
use core::{mem, slice};
use crate::SymbolName;
use crate::types::BytesOrWideString;
use core::ffi::c_void;
use libc::{self, Dl_info};

use crate::SymbolName;

pub struct Symbol {
pub struct Symbol<'a> {
inner: Dl_info,
_marker: marker::PhantomData<&'a i32>,
}

impl Symbol {
impl Symbol<'_> {
pub fn name(&self) -> Option<SymbolName> {
if self.inner.dli_sname.is_null() {
None
Expand Down Expand Up @@ -57,45 +58,52 @@ cfg_if::cfg_if! {
}
}

pub unsafe fn resolve(addr: *mut c_void, cb: &mut FnMut(Symbol)) {
pub unsafe fn resolve(addr: *mut c_void, cb: &mut FnMut(Symbol<'static>)) {
let mut info = Symbol {
inner: mem::zeroed(),
_marker: marker::PhantomData,
};
if libc::dladdr(addr as *mut _, &mut info.inner) != 0 {
cb(info)
}
}
} else {
use core::ffi::c_void;
use crate::types::BytesOrWideString;
use core::marker;
use crate::symbolize::SymbolName;
use crate::types::BytesOrWideString;

pub struct Symbol<'a> {
a: Void,
_b: marker::PhantomData<&'a i32>,
}

pub enum Symbol {}
enum Void {}

impl Symbol {
impl Symbol<'_> {
pub fn name(&self) -> Option<SymbolName> {
match *self {}
match self.a {}
}

pub fn addr(&self) -> Option<*mut c_void> {
match *self {}
match self.a {}
}

pub fn filename_raw(&self) -> Option<BytesOrWideString> {
match *self {}
match self.a {}
}

#[cfg(feature = "std")]
pub fn filename(&self) -> Option<&::std::path::Path> {
match *self {}
match self.a {}
}

pub fn lineno(&self) -> Option<u32> {
match *self {}
match self.a {}
}
}

pub unsafe fn resolve(addr: *mut c_void, cb: &mut FnMut(Symbol)) {
pub unsafe fn resolve(addr: *mut c_void, cb: &mut FnMut(Symbol<'static>)) {
drop((addr, cb));
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/symbolize/dladdr_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
//! basic, not handling inline frame information at all. Since it's so prevalent
//! though we have an option to use it!

use core::ffi::c_void;
use crate::symbolize::{dladdr, ResolveWhat, SymbolName};
use crate::types::BytesOrWideString;
use crate::symbolize::{dladdr, SymbolName, ResolveWhat};
use core::ffi::c_void;

pub struct Symbol(dladdr::Symbol);
pub struct Symbol<'a>(dladdr::Symbol<'a>);

impl Symbol {
impl Symbol<'_> {
pub fn name(&self) -> Option<SymbolName> {
self.0.name()
}
Expand All @@ -45,8 +45,6 @@ impl Symbol {

pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
dladdr::resolve(what.address_or_ip(), &mut |sym| {
cb(&super::Symbol {
inner: Symbol(sym),
})
cb(&super::Symbol { inner: Symbol(sym) })
});
}
Loading