@@ -2,6 +2,7 @@ use super::mystd::ffi::{OsStr, OsString};
2
2
use super :: mystd:: fs;
3
3
use super :: mystd:: os:: unix:: ffi:: { OsStrExt , OsStringExt } ;
4
4
use super :: mystd:: path:: { Path , PathBuf } ;
5
+ use super :: Either ;
5
6
use super :: { Context , Mapping , Stash , Vec } ;
6
7
use core:: convert:: { TryFrom , TryInto } ;
7
8
use core:: str;
@@ -18,75 +19,50 @@ type Elf = object::elf::FileHeader64<NativeEndian>;
18
19
impl Mapping {
19
20
pub fn new ( path : & Path ) -> Option < Mapping > {
20
21
let map = super :: mmap ( path) ?;
21
- let object = Object :: parse ( & map) ?;
22
+ Mapping :: mk_or_other ( map, |map, stash| {
23
+ let object = Object :: parse ( & map) ?;
22
24
23
- // Try to locate an external debug file using the build ID.
24
- if let Some ( path_debug) = object. build_id ( ) . and_then ( locate_build_id) {
25
- if let Some ( mapping) = Mapping :: new_debug ( path_debug, None ) {
26
- return Some ( mapping) ;
25
+ // Try to locate an external debug file using the build ID.
26
+ if let Some ( path_debug) = object. build_id ( ) . and_then ( locate_build_id) {
27
+ if let Some ( mapping) = Mapping :: new_debug ( path_debug, None ) {
28
+ return Some ( Either :: A ( mapping) ) ;
29
+ }
27
30
}
28
- }
29
31
30
- // Try to locate an external debug file using the GNU debug link section.
31
- if let Some ( ( path_debug, crc) ) = object. gnu_debuglink_path ( path) {
32
- if let Some ( mapping) = Mapping :: new_debug ( path_debug, Some ( crc) ) {
33
- return Some ( mapping) ;
32
+ // Try to locate an external debug file using the GNU debug link section.
33
+ if let Some ( ( path_debug, crc) ) = object. gnu_debuglink_path ( path) {
34
+ if let Some ( mapping) = Mapping :: new_debug ( path_debug, Some ( crc) ) {
35
+ return Some ( Either :: A ( mapping) ) ;
36
+ }
34
37
}
35
- }
36
38
37
- let stash = Stash :: new ( ) ;
38
- let cx = Context :: new ( & stash, object, None ) ?;
39
- Some ( Mapping {
40
- // Convert to 'static lifetimes since the symbols should
41
- // only borrow `map` and `stash` and we're preserving them below.
42
- cx : unsafe { core:: mem:: transmute :: < Context < ' _ > , Context < ' static > > ( cx) } ,
43
- _map : map,
44
- _map_sup : None ,
45
- _stash : stash,
39
+ Context :: new ( stash, object, None ) . map ( Either :: B )
46
40
} )
47
41
}
48
42
49
43
/// Load debuginfo from an external debug file.
50
44
fn new_debug ( path : PathBuf , crc : Option < u32 > ) -> Option < Mapping > {
51
45
let map = super :: mmap ( & path) ?;
52
- let object = Object :: parse ( & map) ?;
46
+ Mapping :: mk ( map, |map, stash| {
47
+ let object = Object :: parse ( & map) ?;
53
48
54
- if let Some ( _crc) = crc {
55
- // TODO: check crc
56
- }
49
+ if let Some ( _crc) = crc {
50
+ // TODO: check crc
51
+ }
57
52
58
- // Try to locate a supplementary object file.
59
- if let Some ( ( path_sup, build_id_sup) ) = object. gnu_debugaltlink_path ( & path) {
60
- if let Some ( map_sup) = super :: mmap ( & path_sup) {
61
- if let Some ( sup) = Object :: parse ( & map_sup) {
62
- if sup. build_id ( ) == Some ( build_id_sup) {
63
- let stash = Stash :: new ( ) ;
64
- let cx = Context :: new ( & stash, object, Some ( sup) ) ?;
65
- return Some ( Mapping {
66
- // Convert to 'static lifetimes since the symbols should
67
- // only borrow `map`, `map_sup`, and `stash` and we're
68
- // preserving them below.
69
- cx : unsafe {
70
- core:: mem:: transmute :: < Context < ' _ > , Context < ' static > > ( cx)
71
- } ,
72
- _map : map,
73
- _map_sup : Some ( map_sup) ,
74
- _stash : stash,
75
- } ) ;
53
+ // Try to locate a supplementary object file.
54
+ if let Some ( ( path_sup, build_id_sup) ) = object. gnu_debugaltlink_path ( & path) {
55
+ if let Some ( map_sup) = super :: mmap ( & path_sup) {
56
+ let map_sup = stash. set_mmap_aux ( map_sup) ;
57
+ if let Some ( sup) = Object :: parse ( map_sup) {
58
+ if sup. build_id ( ) == Some ( build_id_sup) {
59
+ return Context :: new ( stash, object, Some ( sup) ) ;
60
+ }
76
61
}
77
62
}
78
63
}
79
- }
80
64
81
- let stash = Stash :: new ( ) ;
82
- let cx = Context :: new ( & stash, object, None ) ?;
83
- Some ( Mapping {
84
- // Convert to 'static lifetimes since the symbols should
85
- // only borrow `map` and `stash` and we're preserving them below.
86
- cx : unsafe { core:: mem:: transmute :: < Context < ' _ > , Context < ' static > > ( cx) } ,
87
- _map : map,
88
- _map_sup : None ,
89
- _stash : stash,
65
+ Context :: new ( stash, object, None )
90
66
} )
91
67
}
92
68
}
0 commit comments