keep backtraces if using the old build system
This commit is contained in:
parent
d464422c0a
commit
774fbdf40d
3 changed files with 16 additions and 14 deletions
|
|
@ -28,11 +28,7 @@ use intrinsics;
|
|||
use mem;
|
||||
use raw;
|
||||
use sys_common::rwlock::RWLock;
|
||||
#[cfg(feature = "backtrace")]
|
||||
use sync::atomic::{AtomicBool, Ordering};
|
||||
use sys::stdio::Stderr;
|
||||
#[cfg(feature = "backtrace")]
|
||||
use sys_common::backtrace;
|
||||
use sys_common::thread_info;
|
||||
use sys_common::util;
|
||||
use thread;
|
||||
|
|
@ -73,8 +69,6 @@ enum Hook {
|
|||
|
||||
static HOOK_LOCK: RWLock = RWLock::new();
|
||||
static mut HOOK: Hook = Hook::Default;
|
||||
#[cfg(feature = "backtrace")]
|
||||
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
/// Registers a custom panic hook, replacing any that was previously registered.
|
||||
///
|
||||
|
|
@ -186,13 +180,17 @@ impl<'a> Location<'a> {
|
|||
}
|
||||
|
||||
fn default_hook(info: &PanicInfo) {
|
||||
#[cfg(feature = "backtrace")]
|
||||
let panics = PANIC_COUNT.with(|c| c.get());
|
||||
#[cfg(any(not(cargobuild), feature = "backtrace"))]
|
||||
use sys_common::backtrace;
|
||||
|
||||
// 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 = panics >= 2 || backtrace::log_enabled();
|
||||
#[cfg(any(not(cargobuild), feature = "backtrace"))]
|
||||
let log_backtrace = {
|
||||
let panics = PANIC_COUNT.with(|c| c.get());
|
||||
|
||||
panics >= 2 || backtrace::log_enabled()
|
||||
};
|
||||
|
||||
let file = info.location.file;
|
||||
let line = info.location.line;
|
||||
|
|
@ -212,8 +210,12 @@ fn default_hook(info: &PanicInfo) {
|
|||
let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}",
|
||||
name, msg, file, line);
|
||||
|
||||
#[cfg(feature = "backtrace")]
|
||||
#[cfg(any(not(cargobuild), feature = "backtrace"))]
|
||||
{
|
||||
use sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
if log_backtrace {
|
||||
let _ = backtrace::write(err);
|
||||
} else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ macro_rules! rtassert {
|
|||
|
||||
pub mod args;
|
||||
pub mod at_exit_imp;
|
||||
#[cfg(feature = "backtrace")]
|
||||
#[cfg(any(not(cargobuild), feature = "backtrace"))]
|
||||
pub mod backtrace;
|
||||
pub mod condvar;
|
||||
pub mod io;
|
||||
|
|
@ -43,7 +43,7 @@ pub mod thread_local;
|
|||
pub mod util;
|
||||
pub mod wtf8;
|
||||
|
||||
#[cfg(feature = "backtrace")]
|
||||
#[cfg(any(not(cargobuild), feature = "backtrace"))]
|
||||
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))),
|
||||
all(windows, target_env = "gnu")))]
|
||||
pub mod gnu;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use libc;
|
|||
pub mod weak;
|
||||
|
||||
pub mod android;
|
||||
#[cfg(feature = "backtrace")]
|
||||
#[cfg(any(not(cargobuild), feature = "backtrace"))]
|
||||
pub mod backtrace;
|
||||
pub mod condvar;
|
||||
pub mod ext;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue