Skip to content

Commit 28450a3

Browse files
committed
Move code_id_for_object
1 parent 1629aa3 commit 28450a3

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

samply-debugid/src/codeid.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::str::FromStr;
22

3+
use object::Object;
34
use 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+
}

samply-debugid/src/debugid.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use debugid::DebugId;
22
use object::{Object, ObjectSection};
33
use uuid::Uuid;
44

5-
use crate::{CodeId, ElfBuildId};
6-
75
pub 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-
}

samply-debugid/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod codeid;
22
mod 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};

0 commit comments

Comments
 (0)