Skip to content

Commit 1e608b9

Browse files
authored
feat: Upgrade to new findshlibs (#153)
1 parent 002ee97 commit 1e608b9

File tree

4 files changed

+20
-61
lines changed

4 files changed

+20
-61
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ error-chain = { version = "0.12.0", optional = true }
5151
im = { version = "12.3.4", optional = true }
5252
libc = { version = "0.2.51", optional = true }
5353
hostname = { version = "0.1.5", optional = true }
54-
findshlibs = { version = "0.4.1", optional = true }
54+
findshlibs = { version = "0.5.0", optional = true }
5555
rand = "0.6.5"
5656
httpdate = { version = "0.3.2", optional = true }
5757
curl = { version = "0.4.21", optional = true }

src/scope/noop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Scope {
9797
/// Add an event processor to the scope.
9898
pub fn add_event_processor(
9999
&mut self,
100-
f: Box<Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync>,
100+
f: Box<dyn Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync>,
101101
) {
102102
let _f = f;
103103
minimal_unreachable!();

src/utils.rs

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -67,72 +67,26 @@ mod model_support {
6767
mod findshlibs_support {
6868
use super::*;
6969

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-
8170
#[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-
12571
pub fn find_shlibs() -> Option<Vec<DebugImage>> {
12672
if !TARGET_SUPPORTED {
12773
return None;
12874
}
12975

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+
13084
let mut rv = vec![];
13185
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+
});
13690

13791
let debug_id = match maybe_debug_id {
13892
Some(debug_id) => debug_id,
@@ -182,6 +136,11 @@ mod findshlibs_support {
182136

183137
Some(rv)
184138
}
139+
140+
#[cfg(not(unix))]
141+
pub fn find_shlibs() -> Option<Vec<DebugImage>> {
142+
None
143+
}
185144
}
186145

187146
#[cfg(not(feature = "with_debug_meta"))]

tests/test_basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn test_factory() {
100100
let options = sentry::ClientOptions {
101101
dsn: "http://[email protected]/42".parse().ok(),
102102
transport: Box::new(
103-
move |opts: &sentry::ClientOptions| -> Box<sentry::internals::Transport> {
103+
move |opts: &sentry::ClientOptions| -> Box<dyn sentry::internals::Transport> {
104104
assert_eq!(opts.dsn.as_ref().unwrap().host(), "example.com");
105105
Box::new(TestTransport(events_for_options.clone()))
106106
},

0 commit comments

Comments
 (0)