File tree Expand file tree Collapse file tree 3 files changed +20
-21
lines changed Expand file tree Collapse file tree 3 files changed +20
-21
lines changed Original file line number Diff line number Diff line change 11use std:: str:: FromStr ;
22
3+ use object:: Object ;
34use uuid:: Uuid ;
45
56/// An enum carrying an identifier for a binary. This is stores the same information
@@ -146,3 +147,20 @@ impl std::fmt::Display for ElfBuildId {
146147 Ok ( ( ) )
147148 }
148149}
150+
151+ /// Tries to obtain a CodeId for an object.
152+ ///
153+ /// This currently only handles mach-O and ELF.
154+ pub fn code_id_for_object < ' data > ( obj : & impl Object < ' data > ) -> Option < CodeId > {
155+ // ELF
156+ if let Ok ( Some ( build_id) ) = obj. build_id ( ) {
157+ return Some ( CodeId :: ElfBuildId ( ElfBuildId :: from_bytes ( build_id) ) ) ;
158+ }
159+
160+ // mach-O
161+ if let Ok ( Some ( uuid) ) = obj. mach_uuid ( ) {
162+ return Some ( CodeId :: MachoUuid ( Uuid :: from_bytes ( uuid) ) ) ;
163+ }
164+
165+ None
166+ }
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ use debugid::DebugId;
22use object:: { Object , ObjectSection } ;
33use uuid:: Uuid ;
44
5- use crate :: { CodeId , ElfBuildId } ;
6-
75pub trait DebugIdExt {
86 /// Creates a DebugId from some identifier. The identifier could be
97 /// an ELF build ID, or a hash derived from the text section.
@@ -96,20 +94,3 @@ pub fn debug_id_for_object<'data>(obj: &impl Object<'data>) -> Option<DebugId> {
9694
9795 None
9896}
99-
100- /// Tries to obtain a CodeId for an object.
101- ///
102- /// This currently only handles mach-O and ELF.
103- pub fn code_id_for_object < ' data > ( obj : & impl Object < ' data > ) -> Option < CodeId > {
104- // ELF
105- if let Ok ( Some ( build_id) ) = obj. build_id ( ) {
106- return Some ( CodeId :: ElfBuildId ( ElfBuildId :: from_bytes ( build_id) ) ) ;
107- }
108-
109- // mach-O
110- if let Ok ( Some ( uuid) ) = obj. mach_uuid ( ) {
111- return Some ( CodeId :: MachoUuid ( Uuid :: from_bytes ( uuid) ) ) ;
112- }
113-
114- None
115- }
Original file line number Diff line number Diff line change 11mod codeid;
22mod debugid;
33
4- pub use codeid:: { CodeId , ElfBuildId , PeCodeId } ;
5- pub use debugid:: { code_id_for_object , debug_id_for_object, DebugIdExt } ;
4+ pub use codeid:: { code_id_for_object , CodeId , ElfBuildId , PeCodeId } ;
5+ pub use debugid:: { debug_id_for_object, DebugIdExt } ;
You can’t perform that action at this time.
0 commit comments