diff --git a/src/symbolize/gimli/libs_dl_iterate_phdr.rs b/src/symbolize/gimli/libs_dl_iterate_phdr.rs index 9f0304ce8..a5f6b92c5 100644 --- a/src/symbolize/gimli/libs_dl_iterate_phdr.rs +++ b/src/symbolize/gimli/libs_dl_iterate_phdr.rs @@ -18,12 +18,11 @@ pub(super) fn native_libraries() -> Vec { } fn infer_current_exe(base_addr: usize) -> OsString { - if let Ok(entries) = super::parse_running_mmaps::parse_maps() { + if let Some(entries) = super::parse_running_mmaps::parse_maps() { let opt_path = entries - .iter() + .filter_map(|e| e.ok()) .find(|e| e.ip_matches(base_addr) && e.pathname().len() > 0) - .map(|e| e.pathname()) - .cloned(); + .map(|e| e.pathname().clone()); if let Some(path) = opt_path { return path; } diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index 9805d0030..87ebf1c91 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -3,9 +3,9 @@ // general purpose, but it hasn't been tested elsewhere. use super::mystd::fs::File; -use super::mystd::io::Read; +use super::mystd::io::{self, BufRead, BufReader, ErrorKind}; use super::mystd::str::FromStr; -use super::{OsString, String, Vec}; +use super::OsString; #[derive(PartialEq, Eq, Debug)] pub(super) struct MapsEntry { @@ -53,19 +53,17 @@ pub(super) struct MapsEntry { pathname: OsString, } -pub(super) fn parse_maps() -> Result, &'static str> { - let failed_io_err = "couldn't read /proc/self/maps"; - let mut v = Vec::new(); - let mut proc_self_maps = File::open("/proc/self/maps").map_err(|_| failed_io_err)?; - let mut buf = String::new(); - let _bytes_read = proc_self_maps - .read_to_string(&mut buf) - .map_err(|_| failed_io_err)?; - for line in buf.lines() { - v.push(line.parse()?); - } - - Ok(v) +pub(super) fn parse_maps() -> Option>> { + let proc_self_maps = match File::open("/proc/self/maps") { + Ok(f) => f, + Err(_) => return None, + }; + let buf_read = BufReader::new(proc_self_maps); + Some( + buf_read + .lines() + .map(|res| res.and_then(|s| s.parse().map_err(|e| io::Error::from(e)))), + ) } impl MapsEntry { @@ -81,15 +79,15 @@ impl MapsEntry { } impl FromStr for MapsEntry { - type Err = &'static str; + type Err = io::ErrorKind; // Format: address perms offset dev inode pathname // e.g.: "ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]" // e.g.: "7f5985f46000-7f5985f48000 rw-p 00039000 103:06 76021795 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2" // e.g.: "35b1a21000-35b1a22000 rw-p 00000000 00:00 0" fn from_str(s: &str) -> Result { - let missing_field = "failed to find all map fields"; - let parse_err = "failed to parse all map fields"; + let missing_field = ErrorKind::NotFound; + let parse_err = ErrorKind::InvalidData; let mut parts = s.split_ascii_whitespace(); let range_str = parts.next().ok_or(missing_field)?; let perms_str = parts.next().ok_or(missing_field)?;