Auto merge of #74682 - alexcrichton:backtrace-gimli-round-2, r=Mark-Simulacrum
std: Switch from libbacktrace to gimli (take 2) This is the second attempt to land https://github.com/rust-lang/rust/pull/73441 after being reverted in https://github.com/rust-lang/rust/pull/74613. Will be gathering precise perf numbers here in this take. Closes #71060
This commit is contained in:
commit
c058a8b8dc
14 changed files with 130 additions and 56 deletions
|
@ -91,6 +91,7 @@
|
|||
// `Backtrace`, but that's a relatively small price to pay relative to capturing
|
||||
// a backtrace or actually symbolizing it.
|
||||
|
||||
use crate::backtrace_rs::{self, BytesOrWideString};
|
||||
use crate::env;
|
||||
use crate::ffi::c_void;
|
||||
use crate::fmt;
|
||||
|
@ -98,8 +99,6 @@ use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
|||
use crate::sync::Mutex;
|
||||
use crate::sys_common::backtrace::{lock, output_filename};
|
||||
use crate::vec::Vec;
|
||||
use backtrace::BytesOrWideString;
|
||||
use backtrace_rs as backtrace;
|
||||
|
||||
/// A captured OS thread stack backtrace.
|
||||
///
|
||||
|
@ -150,7 +149,7 @@ struct BacktraceFrame {
|
|||
}
|
||||
|
||||
enum RawFrame {
|
||||
Actual(backtrace::Frame),
|
||||
Actual(backtrace_rs::Frame),
|
||||
#[cfg(test)]
|
||||
Fake,
|
||||
}
|
||||
|
@ -197,7 +196,7 @@ impl fmt::Debug for BacktraceSymbol {
|
|||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(fmt, "{{ ")?;
|
||||
|
||||
if let Some(fn_name) = self.name.as_ref().map(|b| backtrace::SymbolName::new(b)) {
|
||||
if let Some(fn_name) = self.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)) {
|
||||
write!(fmt, "fn: \"{:#}\"", fn_name)?;
|
||||
} else {
|
||||
write!(fmt, "fn: <unknown>")?;
|
||||
|
@ -223,7 +222,7 @@ impl fmt::Debug for BytesOrWide {
|
|||
BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
|
||||
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
|
||||
},
|
||||
backtrace::PrintFmt::Short,
|
||||
backtrace_rs::PrintFmt::Short,
|
||||
crate::env::current_dir().as_ref().ok(),
|
||||
)
|
||||
}
|
||||
|
@ -305,7 +304,7 @@ impl Backtrace {
|
|||
let mut frames = Vec::new();
|
||||
let mut actual_start = None;
|
||||
unsafe {
|
||||
backtrace::trace_unsynchronized(|frame| {
|
||||
backtrace_rs::trace_unsynchronized(|frame| {
|
||||
frames.push(BacktraceFrame {
|
||||
frame: RawFrame::Actual(frame.clone()),
|
||||
symbols: Vec::new(),
|
||||
|
@ -356,9 +355,9 @@ impl fmt::Display for Backtrace {
|
|||
|
||||
let full = fmt.alternate();
|
||||
let (frames, style) = if full {
|
||||
(&capture.frames[..], backtrace::PrintFmt::Full)
|
||||
(&capture.frames[..], backtrace_rs::PrintFmt::Full)
|
||||
} else {
|
||||
(&capture.frames[capture.actual_start..], backtrace::PrintFmt::Short)
|
||||
(&capture.frames[capture.actual_start..], backtrace_rs::PrintFmt::Short)
|
||||
};
|
||||
|
||||
// When printing paths we try to strip the cwd if it exists, otherwise
|
||||
|
@ -370,7 +369,7 @@ impl fmt::Display for Backtrace {
|
|||
output_filename(fmt, path, style, cwd.as_ref().ok())
|
||||
};
|
||||
|
||||
let mut f = backtrace::BacktraceFmt::new(fmt, style, &mut print_path);
|
||||
let mut f = backtrace_rs::BacktraceFmt::new(fmt, style, &mut print_path);
|
||||
f.add_context()?;
|
||||
for frame in frames {
|
||||
let mut f = f.frame();
|
||||
|
@ -380,7 +379,7 @@ impl fmt::Display for Backtrace {
|
|||
for symbol in frame.symbols.iter() {
|
||||
f.print_raw(
|
||||
frame.frame.ip(),
|
||||
symbol.name.as_ref().map(|b| backtrace::SymbolName::new(b)),
|
||||
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
|
||||
symbol.filename.as_ref().map(|b| match b {
|
||||
BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
|
||||
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
|
||||
|
@ -415,7 +414,7 @@ impl Capture {
|
|||
RawFrame::Fake => unimplemented!(),
|
||||
};
|
||||
unsafe {
|
||||
backtrace::resolve_frame_unsynchronized(frame, |symbol| {
|
||||
backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
|
||||
symbols.push(BacktraceSymbol {
|
||||
name: symbol.name().map(|m| m.as_bytes().to_vec()),
|
||||
filename: symbol.filename_raw().map(|b| match b {
|
||||
|
|
|
@ -511,6 +511,10 @@ mod panicking;
|
|||
// compiler
|
||||
pub mod rt;
|
||||
|
||||
#[path = "../../backtrace/src/lib.rs"]
|
||||
#[allow(dead_code, unused_attributes)]
|
||||
mod backtrace_rs;
|
||||
|
||||
// Pull in the `std_detect` crate directly into libstd. The contents of
|
||||
// `std_detect` are in a different repository: rust-lang/stdarch.
|
||||
//
|
||||
|
|
|
@ -171,7 +171,7 @@ fn default_hook(info: &PanicInfo<'_>) {
|
|||
// If this is a double panic, make sure that we print a backtrace
|
||||
// for this panic. Otherwise only print it if logging is enabled.
|
||||
let backtrace_env = if panic_count::get() >= 2 {
|
||||
RustBacktrace::Print(backtrace_rs::PrintFmt::Full)
|
||||
RustBacktrace::Print(crate::backtrace_rs::PrintFmt::Full)
|
||||
} else {
|
||||
backtrace::rust_backtrace_env()
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt};
|
||||
use crate::borrow::Cow;
|
||||
/// Common code for printing the backtrace in the same way across the different
|
||||
/// supported platforms.
|
||||
|
@ -9,8 +10,6 @@ use crate::path::{self, Path, PathBuf};
|
|||
use crate::sync::atomic::{self, Ordering};
|
||||
use crate::sys::mutex::Mutex;
|
||||
|
||||
use backtrace_rs::{BacktraceFmt, BytesOrWideString, PrintFmt};
|
||||
|
||||
/// Max number of frames to print.
|
||||
const MAX_NB_FRAMES: usize = 100;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue