diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2016-07-26 22:33:45 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2016-07-26 22:33:45 -0500 |
| commit | 774fbdf40deb9b257dd6aa166096fed1eeac80c2 (patch) | |
| tree | aa2e2de54b3f8ad792e1d10be390c51317286b21 /src/libstd | |
| parent | d464422c0a15b88a7f5791652ce1f881959fcc44 (diff) | |
| download | rust-774fbdf40deb9b257dd6aa166096fed1eeac80c2.tar.gz rust-774fbdf40deb9b257dd6aa166096fed1eeac80c2.zip | |
keep backtraces if using the old build system
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/panicking.rs | 24 | ||||
| -rw-r--r-- | src/libstd/sys/common/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 2 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 319fbdaac55..57a4c3df70a 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -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) { diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs index 67b19682fc9..a1f3f477b3a 100644 --- a/src/libstd/sys/common/mod.rs +++ b/src/libstd/sys/common/mod.rs @@ -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; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 9aac7be8017..1c25c8f77c1 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -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; |
