diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index 906a3005..09506951 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -261,7 +261,7 @@ impl<'a> Object<'a> { let section = self.section_header(".gnu_debuglink")?; let data = section.data(self.endian, self.data).ok()?; let len = data.iter().position(|x| *x == 0)?; - let filename = &data[..len]; + let filename = OsStr::from_bytes(&data[..len]); let offset = (len + 1 + 3) & !3; let crc_bytes = data .get(offset..offset + 4) @@ -276,7 +276,7 @@ impl<'a> Object<'a> { let section = self.section_header(".gnu_debugaltlink")?; let data = section.data(self.endian, self.data).ok()?; let len = data.iter().position(|x| *x == 0)?; - let filename = &data[..len]; + let filename = OsStr::from_bytes(&data[..len]); let build_id = &data[len + 1..]; let path_sup = locate_debugaltlink(path, filename, build_id)?; Some((path_sup, build_id)) @@ -304,7 +304,7 @@ fn decompress_zlib(input: &[u8], output: &mut [u8]) -> Option<()> { } } -const DEBUG_PATH: &[u8] = b"/usr/lib/debug"; +const DEBUG_PATH: &str = "/usr/lib/debug"; fn debug_path_exists() -> bool { cfg_if::cfg_if! { @@ -314,7 +314,7 @@ fn debug_path_exists() -> bool { let mut exists = DEBUG_PATH_EXISTS.load(Ordering::Relaxed); if exists == 0 { - exists = if Path::new(OsStr::from_bytes(DEBUG_PATH)).is_dir() { + exists = if Path::new(OsStr::new(DEBUG_PATH)).is_dir() { 1 } else { 2 @@ -377,13 +377,12 @@ fn hex(byte: u8) -> u8 { /// gdb also allows the user to customize the debug search path, but we don't. /// /// gdb also supports debuginfod, but we don't yet. -fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { +fn locate_debuglink(path: &Path, filename: &OsStr) -> Option { let path = fs::canonicalize(path).ok()?; let parent = path.parent()?; let mut f = PathBuf::from(OsString::with_capacity( DEBUG_PATH.len() + parent.as_os_str().len() + filename.len() + 2, )); - let filename = Path::new(OsStr::from_bytes(filename)); // Try "/parent/filename" if it differs from "path" f.push(parent); @@ -408,7 +407,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { let mut s = OsString::from(f); s.clear(); f = PathBuf::from(s); - f.push(OsStr::from_bytes(DEBUG_PATH)); + f.push(OsStr::new(DEBUG_PATH)); f.push(parent.strip_prefix("/").unwrap()); f.push(filename); if f.is_file() { @@ -431,8 +430,8 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { /// gdb also allows the user to customize the debug search path, but we don't. /// /// gdb also supports debuginfod, but we don't yet. -fn locate_debugaltlink(path: &Path, filename: &[u8], build_id: &[u8]) -> Option { - let filename = Path::new(OsStr::from_bytes(filename)); +fn locate_debugaltlink(path: &Path, filename: &OsStr, build_id: &[u8]) -> Option { + let filename = Path::new(filename); if filename.is_absolute() { if filename.is_file() { return Some(filename.into()); @@ -450,11 +449,6 @@ fn locate_debugaltlink(path: &Path, filename: &[u8], build_id: &[u8]) -> Option< locate_build_id(build_id) } -fn convert_path(r: &R) -> Result { - let bytes = r.to_slice()?; - Ok(PathBuf::from(OsStr::from_bytes(&bytes))) -} - pub(super) fn handle_split_dwarf<'data>( package: Option<&gimli::DwarfPackage>>, stash: &'data Stash, @@ -468,10 +462,10 @@ pub(super) fn handle_split_dwarf<'data>( let mut path = PathBuf::new(); if let Some(p) = load.comp_dir.as_ref() { - path.push(convert_path(p).ok()?); + path.push(OsStr::from_bytes(&p.slice())); } - path.push(convert_path(load.path.as_ref()?).ok()?); + path.push(OsStr::from_bytes(&load.path.as_ref()?)); if let Some(map_dwo) = super::mmap(&path) { let map_dwo = stash.cache_mmap(map_dwo); diff --git a/src/symbolize/gimli/xcoff.rs b/src/symbolize/gimli/xcoff.rs index 007b2573..f4061204 100644 --- a/src/symbolize/gimli/xcoff.rs +++ b/src/symbolize/gimli/xcoff.rs @@ -1,4 +1,4 @@ -use super::mystd::ffi::{OsStr, OsString}; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::ffi::OsStrExt; use super::{gimli, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; use alloc::sync::Arc; @@ -17,7 +17,7 @@ type Xcoff = object::xcoff::FileHeader32; type Xcoff = object::xcoff::FileHeader64; impl Mapping { - pub fn new(path: &Path, member_name: &OsString) -> Option { + pub fn new(path: &Path, member_name: &OsStr) -> Option { let map = super::mmap(path)?; Mapping::mk(map, |data, stash| { if member_name.is_empty() { @@ -79,7 +79,7 @@ pub fn parse_xcoff(data: &[u8]) -> Option { } } -pub fn parse_image(path: &Path, member_name: &OsString) -> Option { +pub fn parse_image(path: &Path, member_name: &OsStr) -> Option { let map = super::mmap(path)?; let data = map.deref(); if member_name.is_empty() {