提交 774fbdf4 编写于 作者: J Jorge Aparicio

keep backtraces if using the old build system

上级 d464422c
......@@ -28,11 +28,7 @@
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 @@ pub fn line(&self) -> u32 {
}
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 @@
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 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 @@
pub mod weak;
pub mod android;
#[cfg(feature = "backtrace")]
#[cfg(any(not(cargobuild), feature = "backtrace"))]
pub mod backtrace;
pub mod condvar;
pub mod ext;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册