Skip to content

Commit 914eaec

Browse files
authored
Split out samply-object crate (#689)
2 parents 4783f15 + cc7f362 commit 914eaec

File tree

26 files changed

+193
-258
lines changed

26 files changed

+193
-258
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"gecko_profile",
77
"samply-api",
88
"samply-debugid",
9+
"samply-object",
910
"samply-quota-manager",
1011
"samply-symbols",
1112
"samply",

samply-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ default = []
1414
send_futures = ["samply-symbols/send_futures"]
1515

1616
[dependencies]
17+
samply-debugid = { version = "0.1.0", path = "../samply-debugid" }
1718
samply-symbols = { version = "0.24.1", path = "../samply-symbols" }
1819
thiserror = "2"
1920
serde = "1.0.204"

samply-api/src/asm/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::str::FromStr;
22

3+
use samply_debugid::CodeId;
34
use samply_symbols::debugid::DebugId;
45
use samply_symbols::{
5-
object, CodeByteReadingError, CodeId, FileAndPathHelper, FileAndPathHelperError, LibraryInfo,
6+
object, CodeByteReadingError, FileAndPathHelper, FileAndPathHelperError, LibraryInfo,
67
LookupAddress, SymbolManager,
78
};
89
use yaxpeax_arch::{Arch, DecodeError, LengthedInstruction, Reader, U8Reader};

samply-debugid/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ readme = "README.md"
1212
default-features = false
1313
version = "0.8.0"
1414

15-
[dependencies.object]
16-
default-features = false
17-
features = ["read_core"]
18-
version = "0.37"
19-
2015
[dependencies.uuid]
2116
default-features = false
2217
version = "1"

samply-debugid/src/codeid.rs

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

3-
use object::Object;
43
use uuid::Uuid;
54

65
/// An enum carrying an identifier for a binary. This is stores the same information
@@ -147,20 +146,3 @@ impl std::fmt::Display for ElfBuildId {
147146
Ok(())
148147
}
149148
}
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 & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use debugid::DebugId;
2-
use object::{Object, ObjectSection};
32
use uuid::Uuid;
43

54
pub trait DebugIdExt {
@@ -60,37 +59,3 @@ impl DebugIdExt for DebugId {
6059
DebugId::from_identifier(&hash, little_endian)
6160
}
6261
}
63-
64-
/// Tries to obtain a DebugId for an object. This uses the build ID, if available,
65-
/// and falls back to hashing the first page of the text section otherwise.
66-
/// Returns None on failure.
67-
pub fn debug_id_for_object<'data>(obj: &impl Object<'data>) -> Option<DebugId> {
68-
// Windows
69-
if let Ok(Some(pdb_info)) = obj.pdb_info() {
70-
return Some(DebugId::from_guid_age(&pdb_info.guid(), pdb_info.age()).unwrap());
71-
}
72-
73-
// ELF
74-
if let Ok(Some(build_id)) = obj.build_id() {
75-
return Some(DebugId::from_identifier(build_id, obj.is_little_endian()));
76-
}
77-
78-
// mach-O
79-
if let Ok(Some(uuid)) = obj.mach_uuid() {
80-
return Some(DebugId::from_uuid(Uuid::from_bytes(uuid)));
81-
}
82-
83-
// We were not able to locate a build ID, so fall back to creating a synthetic
84-
// identifier from a hash of the first page of the ".text" (program code) section.
85-
if let Some(section) = obj.section_by_name(".text") {
86-
let data_len = section.size().min(4096);
87-
if let Ok(Some(first_page_data)) = section.data_range(section.address(), data_len) {
88-
return Some(DebugId::from_text_first_page(
89-
first_page_data,
90-
obj.is_little_endian(),
91-
));
92-
}
93-
}
94-
95-
None
96-
}

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::{code_id_for_object, CodeId, ElfBuildId, PeCodeId};
5-
pub use debugid::{debug_id_for_object, DebugIdExt};
4+
pub use codeid::{CodeId, ElfBuildId, PeCodeId};
5+
pub use debugid::DebugIdExt;

samply-object/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "samply-object"
3+
version = "0.1.0"
4+
authors = ["Markus Stange <[email protected]>"]
5+
license = "MIT OR Apache-2.0"
6+
edition = "2021"
7+
description = "Samply object functions."
8+
repository = "https://github.com/mstange/samply/"
9+
readme = "README.md"
10+
11+
[dependencies.debugid]
12+
default-features = false
13+
version = "0.8.0"
14+
15+
[dependencies.object]
16+
default-features = false
17+
features = ["read_core"]
18+
version = "0.37"
19+
20+
[dependencies.uuid]
21+
default-features = false
22+
version = "1"
23+
24+
[dependencies]
25+
samply-debugid = { version = "0.1.0", path = "../samply-debugid" }

samply-object/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# samply-object
2+
3+
This crate defines the functions for getting `DebugId`s, `CodeId`s and relative
4+
base addresses for use with `samply`. Useful for writing your own profiles to
5+
be symbolicated and displayed with `samply load`.

0 commit comments

Comments
 (0)