diff --git a/src/symbolize/gimli/coff.rs b/src/symbolize/gimli/coff.rs index 018cb494..031afea0 100644 --- a/src/symbolize/gimli/coff.rs +++ b/src/symbolize/gimli/coff.rs @@ -1,5 +1,7 @@ -use super::{gimli, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; +use super::mystd::path::Path; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; +use alloc::vec::Vec; use core::convert::TryFrom; use object::pe::{ImageDosHeader, ImageSymbol}; use object::read::coff::ImageSymbol as _; diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index b73f6aac..4db6be44 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -1,12 +1,14 @@ #![allow(clippy::useless_conversion)] -use super::mystd::ffi::{OsStr, OsString}; +use super::mystd::ffi::OsStr; use super::mystd::fs; -use super::mystd::os::unix::ffi::{OsStrExt, OsStringExt}; +use super::mystd::os::unix::ffi::OsStrExt; use super::mystd::path::{Path, PathBuf}; use super::Either; -use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash, Vec}; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; +use alloc::string::String; use alloc::sync::Arc; +use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; use core::str; use object::elf::{ @@ -391,7 +393,7 @@ fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> { Some(()) } -const DEBUG_PATH: &[u8] = b"/usr/lib/debug"; +const DEBUG_PATH: &str = "/usr/lib/debug"; fn debug_path_exists() -> bool { cfg_if::cfg_if! { @@ -401,7 +403,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(DEBUG_PATH).is_dir() { 1 } else { 2 @@ -420,8 +422,8 @@ fn debug_path_exists() -> bool { /// The format of build id paths is documented at: /// https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html fn locate_build_id(build_id: &[u8]) -> Option { - const BUILD_ID_PATH: &[u8] = b"/usr/lib/debug/.build-id/"; - const BUILD_ID_SUFFIX: &[u8] = b".debug"; + const BUILD_ID_PATH: &str = "/usr/lib/debug/.build-id/"; + const BUILD_ID_SUFFIX: &str = ".debug"; if build_id.len() < 2 { return None; @@ -432,25 +434,17 @@ fn locate_build_id(build_id: &[u8]) -> Option { } let mut path = - Vec::with_capacity(BUILD_ID_PATH.len() + BUILD_ID_SUFFIX.len() + build_id.len() * 2 + 1); - path.extend(BUILD_ID_PATH); - path.push(hex(build_id[0] >> 4)); - path.push(hex(build_id[0] & 0xf)); - path.push(b'/'); + String::with_capacity(BUILD_ID_PATH.len() + BUILD_ID_SUFFIX.len() + build_id.len() * 2 + 1); + path.push_str(BUILD_ID_PATH); + path.push(char::from_digit((build_id[0] >> 4) as u32, 16)?); + path.push(char::from_digit((build_id[0] & 0xf) as u32, 16)?); + path.push('/'); for byte in &build_id[1..] { - path.push(hex(byte >> 4)); - path.push(hex(byte & 0xf)); - } - path.extend(BUILD_ID_SUFFIX); - Some(PathBuf::from(OsString::from_vec(path))) -} - -fn hex(byte: u8) -> u8 { - if byte < 10 { - b'0' + byte - } else { - b'a' + byte - 10 + path.push(char::from_digit((byte >> 4) as u32, 16)?); + path.push(char::from_digit((byte & 0xf) as u32, 16)?); } + path.push_str(BUILD_ID_SUFFIX); + Some(PathBuf::from(path)) } /// Locate a file specified in a `.gnu_debuglink` section. @@ -467,9 +461,8 @@ fn hex(byte: u8) -> u8 { fn locate_debuglink(path: &Path, filename: &[u8]) -> 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 mut f = + PathBuf::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" @@ -480,9 +473,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { } // Try "/parent/.debug/filename" - let mut s = OsString::from(f); - s.clear(); - f = PathBuf::from(s); + f.clear(); f.push(parent); f.push(".debug"); f.push(filename); @@ -492,10 +483,8 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { if debug_path_exists() { // Try "/usr/lib/debug/parent/filename" - let mut s = OsString::from(f); - s.clear(); - f = PathBuf::from(s); - f.push(OsStr::from_bytes(DEBUG_PATH)); + f.clear(); + f.push(DEBUG_PATH); f.push(parent.strip_prefix("/").unwrap()); f.push(filename); if f.is_file() { diff --git a/src/symbolize/gimli/libs_aix.rs b/src/symbolize/gimli/libs_aix.rs index aa4eaff8..509fae1e 100644 --- a/src/symbolize/gimli/libs_aix.rs +++ b/src/symbolize/gimli/libs_aix.rs @@ -1,11 +1,13 @@ -use super::mystd::borrow::ToOwned; use super::mystd::env; -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::OsStr; use super::mystd::io::Error; use super::mystd::os::unix::prelude::*; use super::xcoff; -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::borrow::ToOwned; use alloc::vec; +use alloc::vec::Vec; +use core::ffi::CStr; use core::mem; const EXE_IMAGE_BASE: u64 = 0x100000000; diff --git a/src/symbolize/gimli/libs_dl_iterate_phdr.rs b/src/symbolize/gimli/libs_dl_iterate_phdr.rs index 6bee79dd..d52819f6 100644 --- a/src/symbolize/gimli/libs_dl_iterate_phdr.rs +++ b/src/symbolize/gimli/libs_dl_iterate_phdr.rs @@ -2,11 +2,13 @@ // and typically implement an API called `dl_iterate_phdr` to load // native libraries. -use super::mystd::borrow::ToOwned; use super::mystd::env; -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::{OsStr, OsString}; use super::mystd::os::unix::prelude::*; -use super::{parse_running_mmaps, Library, LibrarySegment, OsString, Vec}; +use super::{parse_running_mmaps, Library, LibrarySegment}; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; +use core::ffi::CStr; use core::slice; struct CallbackData { diff --git a/src/symbolize/gimli/libs_haiku.rs b/src/symbolize/gimli/libs_haiku.rs index 87e023e6..ddfd6b47 100644 --- a/src/symbolize/gimli/libs_haiku.rs +++ b/src/symbolize/gimli/libs_haiku.rs @@ -5,11 +5,13 @@ // that section. All the read-only segments of the ELF-binary are in // that part of the address space. -use super::mystd::borrow::ToOwned; -use super::mystd::ffi::{CStr, OsStr}; -use super::mystd::mem::MaybeUninit; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::prelude::*; -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; +use core::ffi::CStr; +use core::mem::MaybeUninit; pub(super) fn native_libraries() -> Vec { let mut libraries: Vec = Vec::new(); diff --git a/src/symbolize/gimli/libs_illumos.rs b/src/symbolize/gimli/libs_illumos.rs index 4fc510cf..32b73b62 100644 --- a/src/symbolize/gimli/libs_illumos.rs +++ b/src/symbolize/gimli/libs_illumos.rs @@ -1,7 +1,9 @@ -use super::mystd::borrow::ToOwned; -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::prelude::*; -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; +use core::ffi::CStr; use core::mem; use object::NativeEndian; diff --git a/src/symbolize/gimli/libs_libnx.rs b/src/symbolize/gimli/libs_libnx.rs index 803008ef..01ef2161 100644 --- a/src/symbolize/gimli/libs_libnx.rs +++ b/src/symbolize/gimli/libs_libnx.rs @@ -1,4 +1,5 @@ -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::vec::Vec; // DevkitA64 doesn't natively support debug info, but the build system will // place debug info at the path `romfs:/debug_info.elf`. diff --git a/src/symbolize/gimli/libs_macos.rs b/src/symbolize/gimli/libs_macos.rs index 671505a1..f65811b2 100644 --- a/src/symbolize/gimli/libs_macos.rs +++ b/src/symbolize/gimli/libs_macos.rs @@ -1,10 +1,11 @@ #![allow(deprecated)] -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::prelude::*; use super::mystd::prelude::v1::*; use super::{Library, LibrarySegment}; use core::convert::TryInto; +use core::ffi::CStr; use core::mem; // FIXME: replace with ptr::from_ref once MSRV is high enough diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index 9afeaf91..6ba63ccc 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -1,6 +1,7 @@ use super::super::super::windows_sys::*; +use super::mystd::ffi::OsString; use super::mystd::os::windows::prelude::*; -use super::{coff, mmap, Library, LibrarySegment, OsString}; +use super::{coff, mmap, Library, LibrarySegment}; use alloc::vec; use alloc::vec::Vec; use core::mem; diff --git a/src/symbolize/gimli/macho.rs b/src/symbolize/gimli/macho.rs index ef51f148..fcbe6098 100644 --- a/src/symbolize/gimli/macho.rs +++ b/src/symbolize/gimli/macho.rs @@ -1,5 +1,8 @@ -use super::{gimli, Box, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; +use super::mystd::path::Path; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; +use alloc::boxed::Box; use alloc::sync::Arc; +use alloc::vec::Vec; use core::convert::TryInto; use object::macho; use object::read::macho::{MachHeader, Nlist, Section, Segment as _}; diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index 534492c5..5803d5dc 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -2,10 +2,12 @@ // in `mod libs_dl_iterate_phdr` (e.g. linux, freebsd, ...); it may be more // general purpose, but it hasn't been tested elsewhere. +use super::mystd::ffi::OsString; use super::mystd::fs::File; use super::mystd::io::Read; -use super::mystd::str::FromStr; -use super::{OsString, String, Vec}; +use alloc::string::String; +use alloc::vec::Vec; +use core::str::FromStr; #[derive(PartialEq, Eq, Debug)] pub(super) struct MapsEntry { diff --git a/src/symbolize/gimli/xcoff.rs b/src/symbolize/gimli/xcoff.rs index dd308840..77fd1d3d 100644 --- a/src/symbolize/gimli/xcoff.rs +++ b/src/symbolize/gimli/xcoff.rs @@ -1,9 +1,11 @@ use super::mystd::ffi::{OsStr, OsString}; use super::mystd::os::unix::ffi::OsStrExt; -use super::mystd::str; -use super::{gimli, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; +use super::mystd::path::Path; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; +use alloc::vec::Vec; use core::ops::Deref; +use core::str; use object::read::archive::ArchiveFile; use object::read::xcoff::{FileHeader, SectionHeader, XcoffFile, XcoffSymbol}; use object::Object as _;