Skip to content

Commit e600773

Browse files
authored
Merge pull request #216 from rust-lang/gimli-tweaks
A few assorted gimli style tweaks
2 parents 2288c8c + af98145 commit e600773

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ cpp_demangle = { default-features = false, version = "0.2.3", optional = true }
3333
addr2line = { version = "0.9.0", optional = true, default-features = false, features = ['std', 'std-object'] }
3434
findshlibs = { version = "0.5.0", optional = true }
3535
memmap = { version = "0.7.0", optional = true }
36-
goblin = { version = "0.0.22", optional = true, default-features = false }
3736

3837
[target.'cfg(windows)'.dependencies]
3938
winapi = { version = "0.3.3", optional = true }
@@ -93,7 +92,7 @@ kernel32 = []
9392
libbacktrace = ["backtrace-sys"]
9493
dladdr = []
9594
coresymbolication = []
96-
gimli-symbolize = ["addr2line", "findshlibs", "memmap", "goblin"]
95+
gimli-symbolize = ["addr2line", "findshlibs", "memmap"]
9796

9897
#=======================================
9998
# Methods of serialization

src/symbolize/gimli.rs

+20-31
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::symbolize::ResolveWhat;
1111
use crate::types::BytesOrWideString;
1212
use crate::SymbolName;
1313
use addr2line::gimli;
14-
use addr2line::object::{self, Object};
14+
use addr2line::object::{self, Object, Uuid};
1515
use core::cell::RefCell;
1616
use core::convert::TryFrom;
1717
use core::mem;
@@ -59,6 +59,10 @@ impl Mapping {
5959
fn new(path: &Path) -> Option<Mapping> {
6060
if cfg!(target_os = "macos") {
6161
Mapping::new_find_dsym(path)
62+
} else if cfg!(windows) {
63+
let map = mmap(path)?;
64+
let object = object::PeFile::parse(&map).ok()?;
65+
Some(mk!(Mapping { map, object }))
6266
} else {
6367
let map = mmap(path)?;
6468
let object = object::ElfFile::parse(&map).ok()?;
@@ -71,7 +75,7 @@ impl Mapping {
7175
// header of the file we're reading, specified at `path`.
7276
let map = mmap(path)?;
7377
let object = object::MachOFile::parse(&map).ok()?;
74-
let uuid = get_uuid(&object)?;
78+
let uuid = object.mach_uuid()?;
7579

7680
// Next we need to look for a `*.dSYM` file. For now we just probe the
7781
// containing directory and look around for something that matches
@@ -100,34 +104,20 @@ impl Mapping {
100104
// symbolication purposes.
101105
return Some(mk!(Mapping { map, object }));
102106

103-
fn load_dsym(dir: &Path, uuid: &[u8]) -> Option<Mapping> {
107+
fn load_dsym(dir: &Path, uuid: &Uuid) -> Option<Mapping> {
104108
for entry in dir.read_dir().ok()? {
105109
let entry = entry.ok()?;
106110
let map = mmap(&entry.path())?;
107111
let object = object::MachOFile::parse(&map).ok()?;
108-
let entry_uuid = get_uuid(&object)?;
109-
if &entry_uuid[..] != uuid {
112+
let entry_uuid = object.mach_uuid()?;
113+
if entry_uuid != *uuid {
110114
continue;
111115
}
112116
return Some(mk!(Mapping { map, object }));
113117
}
114118

115119
None
116120
}
117-
118-
fn get_uuid(object: &object::MachOFile) -> Option<[u8; 16]> {
119-
use goblin::mach::load_command::CommandVariant;
120-
121-
object
122-
.macho()
123-
.load_commands
124-
.iter()
125-
.filter_map(|cmd| match cmd.command {
126-
CommandVariant::Uuid(u) => Some(u.uuid),
127-
_ => None,
128-
})
129-
.next()
130-
}
131121
}
132122

133123
// Ensure the 'static lifetimes don't leak.
@@ -243,7 +233,6 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
243233
// Finally, get a cached mapping or create a new mapping for this file, and
244234
// evaluate the DWARF info to find the file/line/name for this address.
245235
with_mapping_for_path(path, |dwarf, symbols| {
246-
let mut found_sym = false;
247236
if let Ok(mut frames) = dwarf.find_frames(addr.0 as u64) {
248237
while let Ok(Some(frame)) = frames.next() {
249238
let name = frame.function.as_ref().and_then(|f| f.raw_name().ok());
@@ -255,21 +244,21 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
255244
name,
256245
},
257246
});
258-
found_sym = true;
259247
}
260248
}
249+
if cb.called {
250+
return;
251+
}
261252

262253
// No DWARF info found, so fallback to the symbol table.
263-
if !found_sym {
264-
if let Some(name) = symbols.get(addr.0 as u64).and_then(|x| x.name()) {
265-
let sym = super::Symbol {
266-
inner: Symbol::Symbol {
267-
addr: addr.0 as usize as *mut c_void,
268-
name: name.as_bytes(),
269-
},
270-
};
271-
cb.call(&sym);
272-
}
254+
if let Some(name) = symbols.get(addr.0 as u64).and_then(|x| x.name()) {
255+
let sym = super::Symbol {
256+
inner: Symbol::Symbol {
257+
addr: addr.0 as usize as *mut c_void,
258+
name: name.as_bytes(),
259+
},
260+
};
261+
cb.call(&sym);
273262
}
274263
});
275264

0 commit comments

Comments
 (0)