From 6463d67e9f9b1a63e73145953697054f197abc9f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 23 Jun 2019 23:00:10 -0700 Subject: [PATCH 1/3] Use built-in `mach_uuid()` function instead of our own The implementation is even basically the same! --- Cargo.toml | 3 +-- src/symbolize/gimli.rs | 24 +++++------------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6318a7f2a..a37919d89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ cpp_demangle = { default-features = false, version = "0.2.3", optional = true } addr2line = { version = "0.9.0", optional = true, default-features = false, features = ['std', 'std-object'] } findshlibs = { version = "0.5.0", optional = true } memmap = { version = "0.7.0", optional = true } -goblin = { version = "0.0.22", optional = true, default-features = false } [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.3", optional = true } @@ -93,7 +92,7 @@ kernel32 = [] libbacktrace = ["backtrace-sys"] dladdr = [] coresymbolication = [] -gimli-symbolize = ["addr2line", "findshlibs", "memmap", "goblin"] +gimli-symbolize = ["addr2line", "findshlibs", "memmap"] #======================================= # Methods of serialization diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index 48490cd7c..1ff7166e8 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -11,7 +11,7 @@ use crate::symbolize::ResolveWhat; use crate::types::BytesOrWideString; use crate::SymbolName; use addr2line::gimli; -use addr2line::object::{self, Object}; +use addr2line::object::{self, Object, Uuid}; use core::cell::RefCell; use core::convert::TryFrom; use core::mem; @@ -71,7 +71,7 @@ impl Mapping { // header of the file we're reading, specified at `path`. let map = mmap(path)?; let object = object::MachOFile::parse(&map).ok()?; - let uuid = get_uuid(&object)?; + let uuid = object.mach_uuid()?; // Next we need to look for a `*.dSYM` file. For now we just probe the // containing directory and look around for something that matches @@ -100,13 +100,13 @@ impl Mapping { // symbolication purposes. return Some(mk!(Mapping { map, object })); - fn load_dsym(dir: &Path, uuid: &[u8]) -> Option { + fn load_dsym(dir: &Path, uuid: &Uuid) -> Option { for entry in dir.read_dir().ok()? { let entry = entry.ok()?; let map = mmap(&entry.path())?; let object = object::MachOFile::parse(&map).ok()?; - let entry_uuid = get_uuid(&object)?; - if &entry_uuid[..] != uuid { + let entry_uuid = object.mach_uuid()?; + if entry_uuid != *uuid { continue; } return Some(mk!(Mapping { map, object })); @@ -114,20 +114,6 @@ impl Mapping { None } - - fn get_uuid(object: &object::MachOFile) -> Option<[u8; 16]> { - use goblin::mach::load_command::CommandVariant; - - object - .macho() - .load_commands - .iter() - .filter_map(|cmd| match cmd.command { - CommandVariant::Uuid(u) => Some(u.uuid), - _ => None, - }) - .next() - } } // Ensure the 'static lifetimes don't leak. From 2781711f68b2e7d18c9785fb40f5bd967881c157 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 23 Jun 2019 23:00:44 -0700 Subject: [PATCH 2/3] Parse pe files on Windows --- src/symbolize/gimli.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index 1ff7166e8..2bd60887d 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -59,6 +59,10 @@ impl Mapping { fn new(path: &Path) -> Option { if cfg!(target_os = "macos") { Mapping::new_find_dsym(path) + } else if cfg!(windows) { + let map = mmap(path)?; + let object = object::PeFile::parse(&map).ok()?; + Some(mk!(Mapping { map, object })) } else { let map = mmap(path)?; let object = object::ElfFile::parse(&map).ok()?; From af98145332349418f82c90cc3016f49c271e7c69 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 23 Jun 2019 23:05:58 -0700 Subject: [PATCH 3/3] Minor style tweaks for gimli --- src/symbolize/gimli.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index 2bd60887d..0704553d7 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -233,7 +233,6 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) { // Finally, get a cached mapping or create a new mapping for this file, and // evaluate the DWARF info to find the file/line/name for this address. with_mapping_for_path(path, |dwarf, symbols| { - let mut found_sym = false; if let Ok(mut frames) = dwarf.find_frames(addr.0 as u64) { while let Ok(Some(frame)) = frames.next() { let name = frame.function.as_ref().and_then(|f| f.raw_name().ok()); @@ -245,21 +244,21 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) { name, }, }); - found_sym = true; } } + if cb.called { + return; + } // No DWARF info found, so fallback to the symbol table. - if !found_sym { - if let Some(name) = symbols.get(addr.0 as u64).and_then(|x| x.name()) { - let sym = super::Symbol { - inner: Symbol::Symbol { - addr: addr.0 as usize as *mut c_void, - name: name.as_bytes(), - }, - }; - cb.call(&sym); - } + if let Some(name) = symbols.get(addr.0 as u64).and_then(|x| x.name()) { + let sym = super::Symbol { + inner: Symbol::Symbol { + addr: addr.0 as usize as *mut c_void, + name: name.as_bytes(), + }, + }; + cb.call(&sym); } });