Rollup merge of #64444 - RalfJung:no-backtrace, r=alexcrichton
fix building libstd without backtrace feature Fixes https://github.com/rust-lang/rust/issues/64410 r? @alexcrichton
This commit is contained in:
commit
2a6a342aaf
5 changed files with 25 additions and 27 deletions
|
|
@ -25,17 +25,11 @@ profiler_builtins = { path = "../libprofiler_builtins", optional = true }
|
|||
unwind = { path = "../libunwind" }
|
||||
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
|
||||
|
||||
[dependencies.backtrace]
|
||||
[dependencies.backtrace_rs]
|
||||
package = "backtrace"
|
||||
version = "0.3.37"
|
||||
default-features = false # don't use coresymbolication on OSX
|
||||
features = [
|
||||
"rustc-dep-of-std", # enable build support for integrating into libstd
|
||||
"dbghelp", # backtrace/symbolize on MSVC
|
||||
"libbacktrace", # symbolize on most platforms
|
||||
"libunwind", # backtrace on most platforms
|
||||
"dladdr", # symbolize on platforms w/o libbacktrace
|
||||
]
|
||||
optional = true
|
||||
default-features = false # without the libstd `backtrace` feature, stub out everything
|
||||
features = [ "rustc-dep-of-std" ] # enable build support for integrating into libstd
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.7"
|
||||
|
|
@ -65,6 +59,13 @@ cc = "1.0"
|
|||
[features]
|
||||
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
|
||||
|
||||
backtrace = [
|
||||
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC
|
||||
"backtrace_rs/libbacktrace", # symbolize on most platforms
|
||||
"backtrace_rs/libunwind", # backtrace on most platforms
|
||||
"backtrace_rs/dladdr", # symbolize on platforms w/o libbacktrace
|
||||
]
|
||||
|
||||
panic-unwind = ["panic_unwind"]
|
||||
profiler = ["profiler_builtins"]
|
||||
compiler-builtins-c = ["alloc/compiler-builtins-c"]
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
|||
use crate::sync::Mutex;
|
||||
use crate::sys_common::backtrace::{output_filename, lock};
|
||||
use crate::vec::Vec;
|
||||
use backtrace_rs as backtrace;
|
||||
use backtrace::BytesOrWideString;
|
||||
|
||||
/// A captured OS thread stack backtrace.
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ use crate::ptr;
|
|||
use crate::raw;
|
||||
use crate::sys::stdio::panic_output;
|
||||
use crate::sys_common::rwlock::RWLock;
|
||||
use crate::sys_common::thread_info;
|
||||
use crate::sys_common::util;
|
||||
use crate::sys_common::{thread_info, util, backtrace};
|
||||
use crate::thread;
|
||||
|
||||
#[cfg(not(test))]
|
||||
|
|
@ -157,20 +156,18 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
|
|||
}
|
||||
|
||||
fn default_hook(info: &PanicInfo<'_>) {
|
||||
#[cfg(feature = "backtrace")]
|
||||
use crate::sys_common::{backtrace as backtrace_mod};
|
||||
|
||||
// If this is a double panic, make sure that we print a backtrace
|
||||
// for this panic. Otherwise only print it if logging is enabled.
|
||||
#[cfg(feature = "backtrace")]
|
||||
let log_backtrace = {
|
||||
let log_backtrace = if cfg!(feature = "backtrace") {
|
||||
let panics = update_panic_count(0);
|
||||
|
||||
if panics >= 2 {
|
||||
Some(backtrace::PrintFmt::Full)
|
||||
Some(backtrace_rs::PrintFmt::Full)
|
||||
} else {
|
||||
backtrace_mod::log_enabled()
|
||||
backtrace::log_enabled()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// The current implementation always returns `Some`.
|
||||
|
|
@ -190,14 +187,13 @@ fn default_hook(info: &PanicInfo<'_>) {
|
|||
let _ = writeln!(err, "thread '{}' panicked at '{}', {}",
|
||||
name, msg, location);
|
||||
|
||||
#[cfg(feature = "backtrace")]
|
||||
{
|
||||
if cfg!(feature = "backtrace") {
|
||||
use crate::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
if let Some(format) = log_backtrace {
|
||||
let _ = backtrace_mod::print(err, format);
|
||||
let _ = backtrace::print(err, format);
|
||||
} else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
|
||||
let _ = writeln!(err, "note: run with `RUST_BACKTRACE=1` \
|
||||
environment variable to display a backtrace.");
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@ use crate::io;
|
|||
use crate::borrow::Cow;
|
||||
use crate::io::prelude::*;
|
||||
use crate::path::{self, Path, PathBuf};
|
||||
use crate::sync::atomic::{self, Ordering};
|
||||
use crate::sys::mutex::Mutex;
|
||||
|
||||
use backtrace::{BacktraceFmt, BytesOrWideString, PrintFmt};
|
||||
use backtrace_rs::{BacktraceFmt, BytesOrWideString, PrintFmt};
|
||||
|
||||
/// Max number of frames to print.
|
||||
const MAX_NB_FRAMES: usize = 100;
|
||||
|
|
@ -74,14 +73,14 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
|
|||
bt_fmt.add_context()?;
|
||||
let mut idx = 0;
|
||||
let mut res = Ok(());
|
||||
backtrace::trace_unsynchronized(|frame| {
|
||||
backtrace_rs::trace_unsynchronized(|frame| {
|
||||
if print_fmt == PrintFmt::Short && idx > MAX_NB_FRAMES {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut hit = false;
|
||||
let mut stop = false;
|
||||
backtrace::resolve_frame_unsynchronized(frame, |symbol| {
|
||||
backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
|
||||
hit = true;
|
||||
if print_fmt == PrintFmt::Short {
|
||||
if let Some(sym) = symbol.name().and_then(|s| s.as_str()) {
|
||||
|
|
@ -130,6 +129,8 @@ where
|
|||
// For now logging is turned off by default, and this function checks to see
|
||||
// whether the magical environment variable is present to see if it's turned on.
|
||||
pub fn log_enabled() -> Option<PrintFmt> {
|
||||
use crate::sync::atomic::{self, Ordering};
|
||||
|
||||
// Setting environment variables for Fuchsia components isn't a standard
|
||||
// or easily supported workflow. For now, always display backtraces.
|
||||
if cfg!(target_os = "fuchsia") {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ macro_rules! rtunwrap {
|
|||
|
||||
pub mod alloc;
|
||||
pub mod at_exit_imp;
|
||||
#[cfg(feature = "backtrace")]
|
||||
pub mod backtrace;
|
||||
pub mod condvar;
|
||||
pub mod io;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue