@@ -67,72 +67,26 @@ mod model_support {
67
67
mod findshlibs_support {
68
68
use super :: * ;
69
69
70
- use std:: env;
71
- use std:: ffi:: CStr ;
72
-
73
- use findshlibs:: {
74
- Segment , SharedLibrary , SharedLibraryId , TargetSharedLibrary , TARGET_SUPPORTED ,
75
- } ;
76
-
77
- use crate :: internals:: Uuid ;
78
- use crate :: protocol:: debugid:: DebugId ;
79
- use crate :: protocol:: SymbolicDebugImage ;
80
-
81
70
#[ cfg( unix) ]
82
- pub fn find_build_id_from_binary ( name : & CStr ) -> Option < DebugId > {
83
- use std:: ffi:: OsStr ;
84
- use std:: fs:: File ;
85
- use std:: os:: unix:: ffi:: OsStrExt ;
86
- use std:: path:: Path ;
87
-
88
- use goblin:: elf:: note:: NT_GNU_BUILD_ID ;
89
- use goblin:: elf:: Elf ;
90
- use memmap:: Mmap ;
91
-
92
- fn from_be ( id : Uuid ) -> Uuid {
93
- let ( a, b, c, d) = id. as_fields ( ) ;
94
- Uuid :: from_fields ( u32:: from_be ( a) , u16:: from_be ( b) , u16:: from_be ( c) , d) . unwrap ( )
95
- }
96
-
97
- let os_str = OsStr :: from_bytes ( name. to_bytes ( ) ) ;
98
- let path: & Path = if os_str. is_empty ( ) {
99
- "/proc/self/exe" . as_ref ( )
100
- } else {
101
- os_str. as_ref ( )
102
- } ;
103
-
104
- let file = File :: open ( & path) . ok ( ) ?;
105
- let mmap = unsafe { Mmap :: map ( & file) } . ok ( ) ?;
106
- if let Ok ( elf_obj) = Elf :: parse ( & mmap) {
107
- if let Some ( note) = elf_obj
108
- . iter_note_headers ( & mmap) ?
109
- . filter_map ( Result :: ok)
110
- . find ( |note| note. n_type == NT_GNU_BUILD_ID && note. desc . len ( ) >= 16 )
111
- {
112
- // Can only fail if length of input is not 16
113
- let build_id = from_be ( Uuid :: from_slice ( & note. desc [ 0 ..16 ] ) . unwrap ( ) ) ;
114
- return Some ( DebugId :: from_uuid ( build_id) ) ;
115
- }
116
- }
117
- None
118
- }
119
-
120
- #[ cfg( not( unix) ) ]
121
- pub fn find_build_id_from_binary ( _name : & CStr ) -> Option < DebugId > {
122
- None
123
- }
124
-
125
71
pub fn find_shlibs ( ) -> Option < Vec < DebugImage > > {
126
72
if !TARGET_SUPPORTED {
127
73
return None ;
128
74
}
129
75
76
+ use crate :: internals:: Uuid ;
77
+ use crate :: protocol:: debugid:: DebugId ;
78
+ use crate :: protocol:: SymbolicDebugImage ;
79
+ use findshlibs:: {
80
+ Segment , SharedLibrary , SharedLibraryId , TargetSharedLibrary , TARGET_SUPPORTED ,
81
+ } ;
82
+ use std:: env;
83
+
130
84
let mut rv = vec ! [ ] ;
131
85
TargetSharedLibrary :: each ( |shlib| {
132
- let maybe_debug_id = shlib
133
- . id ( )
134
- . map ( | SharedLibraryId :: Uuid ( bytes ) | DebugId :: from_uuid ( Uuid :: from_bytes ( bytes ) ) )
135
- . or_else ( || find_build_id_from_binary ( shlib . name ( ) ) ) ;
86
+ let maybe_debug_id = shlib. id ( ) . and_then ( |id| match id {
87
+ SharedLibraryId :: Uuid ( bytes ) => Some ( DebugId :: from_uuid ( Uuid :: from_bytes ( bytes ) ) ) ,
88
+ SharedLibraryId :: GnuBuildId ( ref id ) => DebugId :: from_guid_age ( & id [ .. 16 ] , 0 ) . ok ( ) ,
89
+ } ) ;
136
90
137
91
let debug_id = match maybe_debug_id {
138
92
Some ( debug_id) => debug_id,
@@ -182,6 +136,11 @@ mod findshlibs_support {
182
136
183
137
Some ( rv)
184
138
}
139
+
140
+ #[ cfg( not( unix) ) ]
141
+ pub fn find_shlibs ( ) -> Option < Vec < DebugImage > > {
142
+ None
143
+ }
185
144
}
186
145
187
146
#[ cfg( not( feature = "with_debug_meta" ) ) ]
0 commit comments