]> git.lizzy.rs Git - rust.git/commitdiff
keep backtraces if using the old build system
authorJorge Aparicio <japaricious@gmail.com>
Wed, 27 Jul 2016 03:33:45 +0000 (22:33 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Wed, 27 Jul 2016 03:33:45 +0000 (22:33 -0500)
src/libstd/panicking.rs
src/libstd/sys/common/mod.rs
src/libstd/sys/unix/mod.rs

index 319fbdaac55dbe83fd1447e2938ab90964845401..57a4c3df70a476eeeb680233db6ab390a4c95490 100644 (file)
 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) {
index 67b19682fc9a8603bf5fdee29e47db71facc2104..a1f3f477b3ab7dfa4f64eadac9847bc8568d4f92 100644 (file)
@@ -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 @@ macro_rules! rtassert {
 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;
index 9aac7be80176ee494ceb949089782bea8952f5f3..1c25c8f77c196f444489178e37a471c67cdb3947 100644 (file)
@@ -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;