From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- library/backtrace/src/print.rs | 3 +- library/backtrace/src/print/fuchsia.rs | 7 +- .../symbolize/gimli/parse_running_mmaps_unix.rs | 81 +++++++++++++++++++--- library/backtrace/src/symbolize/mod.rs | 2 +- library/backtrace/src/windows.rs | 4 +- 5 files changed, 83 insertions(+), 14 deletions(-) (limited to 'library/backtrace/src') diff --git a/library/backtrace/src/print.rs b/library/backtrace/src/print.rs index 8d9cbe3d4..395328a0a 100644 --- a/library/backtrace/src/print.rs +++ b/library/backtrace/src/print.rs @@ -83,7 +83,8 @@ impl<'a, 'b> BacktraceFmt<'a, 'b> { /// This is currently a no-op but is added for future compatibility with /// backtrace formats. pub fn finish(&mut self) -> fmt::Result { - // Currently a no-op-- including this hook to allow for future additions. + #[cfg(target_os = "fuchsia")] + fuchsia::finish_context(self.fmt)?; Ok(()) } diff --git a/library/backtrace/src/print/fuchsia.rs b/library/backtrace/src/print/fuchsia.rs index ce3f17862..cb872697d 100644 --- a/library/backtrace/src/print/fuchsia.rs +++ b/library/backtrace/src/print/fuchsia.rs @@ -425,7 +425,7 @@ impl DsoPrinter<'_, '_> { /// This function prints the Fuchsia symbolizer markup for all information contained in a DSO. pub fn print_dso_context(out: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - out.write_str("{{{reset}}}\n")?; + out.write_str("{{{reset:begin}}}\n")?; let mut visitor = DsoPrinter { writer: out, module_count: 0, @@ -434,3 +434,8 @@ pub fn print_dso_context(out: &mut core::fmt::Formatter<'_>) -> core::fmt::Resul for_each_dso(&mut visitor); visitor.error } + +/// This function prints the Fuchsia symbolizer markup to end the backtrace. +pub fn finish_context(out: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + out.write_str("{{{reset:end}}}\n") +} diff --git a/library/backtrace/src/symbolize/gimli/parse_running_mmaps_unix.rs b/library/backtrace/src/symbolize/gimli/parse_running_mmaps_unix.rs index deeeb2971..5d4b34675 100644 --- a/library/backtrace/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/library/backtrace/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -85,16 +85,37 @@ impl FromStr for MapsEntry { // 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" + // + // Note that paths may contain spaces, so we can't use `str::split` for parsing (until + // Split::remainder is stabilized #77998). fn from_str(s: &str) -> Result { - let mut parts = s - .split(' ') // space-separated fields - .filter(|s| s.len() > 0); // multiple spaces implies empty strings that need to be skipped. - let range_str = parts.next().ok_or("Couldn't find address")?; - let perms_str = parts.next().ok_or("Couldn't find permissions")?; - let offset_str = parts.next().ok_or("Couldn't find offset")?; - let dev_str = parts.next().ok_or("Couldn't find dev")?; - let inode_str = parts.next().ok_or("Couldn't find inode")?; - let pathname_str = parts.next().unwrap_or(""); // pathname may be omitted. + let (range_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); + if range_str.is_empty() { + return Err("Couldn't find address"); + } + + let (perms_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); + if perms_str.is_empty() { + return Err("Couldn't find permissions"); + } + + let (offset_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); + if offset_str.is_empty() { + return Err("Couldn't find offset"); + } + + let (dev_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); + if dev_str.is_empty() { + return Err("Couldn't find dev"); + } + + let (inode_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); + if inode_str.is_empty() { + return Err("Couldn't find inode"); + } + + // Pathname may be omitted in which case it will be empty + let pathname_str = s.trim_start(); let hex = |s| usize::from_str_radix(s, 16).map_err(|_| "Couldn't parse hex number"); let address = if let Some((start, limit)) = range_str.split_once('-') { @@ -229,4 +250,46 @@ fn check_maps_entry_parsing_32bit() { pathname: Default::default(), } ); + assert_eq!( + "b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ + /executable/path/with some spaces" + .parse::() + .unwrap(), + MapsEntry { + address: (0xb7c79000, 0xb7e02000), + perms: ['r', '-', '-', 'p'], + offset: 0x00000000, + dev: (0x08, 0x01), + inode: 0x60662705, + pathname: "/executable/path/with some spaces".into(), + } + ); + assert_eq!( + "b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ + /executable/path/with multiple-continuous spaces " + .parse::() + .unwrap(), + MapsEntry { + address: (0xb7c79000, 0xb7e02000), + perms: ['r', '-', '-', 'p'], + offset: 0x00000000, + dev: (0x08, 0x01), + inode: 0x60662705, + pathname: "/executable/path/with multiple-continuous spaces ".into(), + } + ); + assert_eq!( + " b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ + /executable/path/starts-with-spaces" + .parse::() + .unwrap(), + MapsEntry { + address: (0xb7c79000, 0xb7e02000), + perms: ['r', '-', '-', 'p'], + offset: 0x00000000, + dev: (0x08, 0x01), + inode: 0x60662705, + pathname: "/executable/path/starts-with-spaces".into(), + } + ); } diff --git a/library/backtrace/src/symbolize/mod.rs b/library/backtrace/src/symbolize/mod.rs index dbc346522..a7c199506 100644 --- a/library/backtrace/src/symbolize/mod.rs +++ b/library/backtrace/src/symbolize/mod.rs @@ -471,7 +471,7 @@ cfg_if::cfg_if! { mod dbghelp; use dbghelp as imp; } else if #[cfg(all( - any(unix, windows), + any(unix, all(windows, target_env = "gnu")), not(target_vendor = "uwp"), not(target_os = "emscripten"), any(not(backtrace_in_libstd), feature = "backtrace"), diff --git a/library/backtrace/src/windows.rs b/library/backtrace/src/windows.rs index 9ec3ba99b..92c2b2e66 100644 --- a/library/backtrace/src/windows.rs +++ b/library/backtrace/src/windows.rs @@ -177,9 +177,9 @@ macro_rules! ffi { assert_eq!($name as usize, winapi::$name as usize); let mut x: unsafe extern "system" fn($($args)*) -> $ret; x = $name; - drop(x); + let _ = x; x = winapi::$name; - drop(x); + let _ = x; } } )* -- cgit v1.2.3