Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::PrintFmt;
use crate::resolve;
use crate::{BacktraceFmt, Symbol, SymbolName, resolve_frame, trace};
use core::ffi::c_void;
use std::fmt;
use std::path::{Path, PathBuf};
use std::prelude::v1::*;
use std::{env, fmt};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -490,22 +490,21 @@ impl fmt::Debug for Backtrace {
PrintFmt::Short
};

// When printing paths we try to strip the cwd if it exists, otherwise
// we just print the path as-is. Note that we also only do this for the
// short format, because if it's full we presumably want to print
// everything.
let cwd = std::env::current_dir();
let mut print_path =
move |fmt: &mut fmt::Formatter<'_>, path: crate::BytesOrWideString<'_>| {
let path = path.into_path_buf();
if style != PrintFmt::Full {
if let Ok(cwd) = &cwd {
if let Ok(suffix) = path.strip_prefix(cwd) {
return fmt::Display::fmt(&suffix.display(), fmt);
}
}
// When printing paths we try to strip the cwd if it exists, otherwise
// we just print the path as-is
if style == PrintFmt::Short
&& let Ok(cwd) = &env::current_dir()
&& let Ok(suffix) = path.strip_prefix(cwd)
{
fmt::Display::fmt(&suffix.display(), fmt)
} else {
fmt::Display::fmt(&path.display(), fmt)
}
fmt::Display::fmt(&path.display(), fmt)
};

let mut f = BacktraceFmt::new(fmt, style, &mut print_path);
Expand Down
20 changes: 10 additions & 10 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,16 @@ pub unsafe fn resolve(what: ResolveWhat<'_>, cb: &mut dyn FnMut(&super::Symbol))
}
}
if !any_frames {
if let Some((object_cx, object_addr)) = cx.object.search_object_map(addr as u64) {
if let Ok(mut frames) = object_cx.find_frames(stash, object_addr) {
while let Ok(Some(frame)) = frames.next() {
any_frames = true;
call(Symbol::Frame {
addr: addr as *mut c_void,
location: frame.location,
name: frame.function.map(|f| f.name.slice()),
});
}
if let Some((object_cx, object_addr)) = cx.object.search_object_map(addr as u64)
&& let Ok(mut frames) = object_cx.find_frames(stash, object_addr)
{
while let Ok(Some(frame)) = frames.next() {
any_frames = true;
call(Symbol::Frame {
addr: addr as *mut c_void,
location: frame.location,
name: frame.function.map(|f| f.name.slice()),
});
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ impl Mapping {
let object = Object::parse(map)?;

// Try to locate an external debug file using the build ID.
if let Some(path_debug) = object.build_id().and_then(locate_build_id) {
if let Some(mapping) = Mapping::new_debug(path, path_debug, None) {
return Some(Either::A(mapping));
}
if let Some(path_debug) = object.build_id().and_then(locate_build_id)
&& let Some(mapping) = Mapping::new_debug(path, path_debug, None)
{
return Some(Either::A(mapping));
}

// Try to locate an external debug file using the GNU debug link section.
if let Some((path_debug, crc)) = object.gnu_debuglink_path(path) {
if let Some(mapping) = Mapping::new_debug(path, path_debug, Some(crc)) {
return Some(Either::A(mapping));
}
if let Some((path_debug, crc)) = object.gnu_debuglink_path(path)
&& let Some(mapping) = Mapping::new_debug(path, path_debug, Some(crc))
{
return Some(Either::A(mapping));
}

let dwp = Mapping::load_dwarf_package(path, stash);
Expand Down Expand Up @@ -102,14 +102,14 @@ impl Mapping {

// Try to locate a supplementary object file.
let mut sup = None;
if let Some((path_sup, build_id_sup)) = object.gnu_debugaltlink_path(&path) {
if let Some(map_sup) = super::mmap(&path_sup) {
let map_sup = stash.cache_mmap(map_sup);
if let Some(sup_) = Object::parse(map_sup) {
if sup_.build_id() == Some(build_id_sup) {
sup = Some(sup_);
}
}
if let Some((path_sup, build_id_sup)) = object.gnu_debugaltlink_path(&path)
&& let Some(map_sup) = super::mmap(&path_sup)
{
let map_sup = stash.cache_mmap(map_sup);
Comment on lines +105 to +108
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I want a better code pattern for this particular motion, since we do it in many places.

if let Some(sup_) = Object::parse(map_sup)
&& sup_.build_id() == Some(build_id_sup)
{
sup = Some(sup_);
}
}

Expand Down Expand Up @@ -532,10 +532,10 @@ pub(super) fn handle_split_dwarf<'data>(
stash: &'data Stash,
load: addr2line::SplitDwarfLoad<EndianSlice<'data, Endian>>,
) -> Option<Arc<gimli::Dwarf<EndianSlice<'data, Endian>>>> {
if let Some(dwp) = package.as_ref() {
if let Ok(Some(cu)) = dwp.find_cu(load.dwo_id, &load.parent) {
return Some(Arc::new(cu));
}
if let Some(dwp) = package.as_ref()
&& let Ok(Some(cu)) = dwp.find_cu(load.dwo_id, &load.parent)
{
return Some(Arc::new(cu));
}

let mut path = PathBuf::new();
Expand Down
11 changes: 5 additions & 6 deletions src/symbolize/gimli/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ impl Mapping {
// contains and try to find a macho file which has a matching UUID as
// the one of our own file. If we find a match that's the dwarf file we
// want to return.
if let Some(uuid) = uuid {
if let Some(parent) = path.parent() {
if let Some(mapping) = Mapping::load_dsym(parent, uuid) {
return Some(mapping);
}
}
if let Some(uuid) = uuid
&& let Some(parent) = path.parent()
&& let Some(mapping) = Mapping::load_dsym(parent, uuid)
{
return Some(mapping);
}

// Looks like nothing matched our UUID, so let's at least return our own
Expand Down
16 changes: 8 additions & 8 deletions src/symbolize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ impl<'a> fmt::Display for SymbolName<'a> {
// This may fail to print if the demangled symbol isn't actually
// valid, so handle the error here gracefully by not propagating
// it outwards.
if let Some(ref cpp) = self.cpp_demangled.0 {
if let Ok(s) = cpp.demangle() {
return s.fmt(f);
}
if let Some(ref cpp) = self.cpp_demangled.0
&& let Ok(s) = cpp.demangle()
{
return s.fmt(f);
}
}

Expand All @@ -398,10 +398,10 @@ impl<'a> fmt::Debug for SymbolName<'a> {
// This may fail to print if the demangled symbol isn't actually
// valid, so handle the error here gracefully by not propagating
// it outwards.
if let Some(ref cpp) = self.cpp_demangled.0 {
if let Ok(s) = cpp.demangle() {
return s.fmt(f);
}
if let Some(ref cpp) = self.cpp_demangled.0
&& let Ok(s) = cpp.demangle()
{
return s.fmt(f);
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ impl<'a> BytesOrWideString<'a> {
}
}

if let BytesOrWideString::Bytes(b) = self {
if let Ok(s) = str::from_utf8(b) {
return PathBuf::from(s);
}
// cross-platform fallback is to pray we are dealing with utf-8
if let BytesOrWideString::Bytes(b) = self
&& let Ok(s) = str::from_utf8(b)
{
PathBuf::from(s)
} else {
// or die
unreachable!()
}
unreachable!()
}
}

Expand Down
Loading