Skip to content

Commit

Permalink
keep backtraces if using the old build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Jul 27, 2016
1 parent d464422 commit 774fbdf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
24 changes: 13 additions & 11 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 774fbdf

Please sign in to comment.