@@ -11,7 +11,7 @@ use crate::symbolize::ResolveWhat;
11
11
use crate :: types:: BytesOrWideString ;
12
12
use crate :: SymbolName ;
13
13
use addr2line:: gimli;
14
- use addr2line:: object:: { self , Object } ;
14
+ use addr2line:: object:: { self , Object , Uuid } ;
15
15
use core:: cell:: RefCell ;
16
16
use core:: convert:: TryFrom ;
17
17
use core:: mem;
@@ -59,6 +59,10 @@ impl Mapping {
59
59
fn new ( path : & Path ) -> Option < Mapping > {
60
60
if cfg ! ( target_os = "macos" ) {
61
61
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 } ) )
62
66
} else {
63
67
let map = mmap ( path) ?;
64
68
let object = object:: ElfFile :: parse ( & map) . ok ( ) ?;
@@ -71,7 +75,7 @@ impl Mapping {
71
75
// header of the file we're reading, specified at `path`.
72
76
let map = mmap ( path) ?;
73
77
let object = object:: MachOFile :: parse ( & map) . ok ( ) ?;
74
- let uuid = get_uuid ( & object) ?;
78
+ let uuid = object. mach_uuid ( ) ?;
75
79
76
80
// Next we need to look for a `*.dSYM` file. For now we just probe the
77
81
// containing directory and look around for something that matches
@@ -100,34 +104,20 @@ impl Mapping {
100
104
// symbolication purposes.
101
105
return Some ( mk ! ( Mapping { map, object } ) ) ;
102
106
103
- fn load_dsym ( dir : & Path , uuid : & [ u8 ] ) -> Option < Mapping > {
107
+ fn load_dsym ( dir : & Path , uuid : & Uuid ) -> Option < Mapping > {
104
108
for entry in dir. read_dir ( ) . ok ( ) ? {
105
109
let entry = entry. ok ( ) ?;
106
110
let map = mmap ( & entry. path ( ) ) ?;
107
111
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 {
110
114
continue ;
111
115
}
112
116
return Some ( mk ! ( Mapping { map, object } ) ) ;
113
117
}
114
118
115
119
None
116
120
}
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
- }
131
121
}
132
122
133
123
// Ensure the 'static lifetimes don't leak.
@@ -243,7 +233,6 @@ pub unsafe fn resolve(what: ResolveWhat, cb: &mut FnMut(&super::Symbol)) {
243
233
// Finally, get a cached mapping or create a new mapping for this file, and
244
234
// evaluate the DWARF info to find the file/line/name for this address.
245
235
with_mapping_for_path ( path, |dwarf, symbols| {
246
- let mut found_sym = false ;
247
236
if let Ok ( mut frames) = dwarf. find_frames ( addr. 0 as u64 ) {
248
237
while let Ok ( Some ( frame) ) = frames. next ( ) {
249
238
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)) {
255
244
name,
256
245
} ,
257
246
} ) ;
258
- found_sym = true ;
259
247
}
260
248
}
249
+ if cb. called {
250
+ return ;
251
+ }
261
252
262
253
// 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) ;
273
262
}
274
263
} ) ;
275
264
0 commit comments