Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/libstd/sys_common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use io::prelude::*;
use sys::stdio::{Stderr, stderr_prints_nothing};
use thread;

#[cfg(feature = "backtrace")]
use sys_common::backtrace;

pub fn dumb_print(args: fmt::Arguments) {
if stderr_prints_nothing() {
return
Expand All @@ -34,4 +37,21 @@ pub fn abort(args: fmt::Arguments) -> ! {
pub unsafe fn report_overflow() {
dumb_print(format_args!("\nthread '{}' has overflowed its stack\n",
thread::current().name().unwrap_or("<unknown>")));

#[cfg(feature = "backtrace")]
{
let log_backtrace = backtrace::log_enabled();

use sync::atomic::{AtomicBool, Ordering};

static FIRST_OVERFLOW: AtomicBool = AtomicBool::new(true);

if let Some(format) = log_backtrace {
if let Ok(mut stderr) = Stderr::new() {
let _ = backtrace::print(&mut stderr, format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please print thread '{}' has overflowed its stack here too, because the backtrace is likely to be very big, which makes it easy to miss the first time it is printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea.

}
} else if FIRST_OVERFLOW.compare_and_swap(true, false, Ordering::SeqCst) {
dumb_print(format_args!("note: Run with `RUST_BACKTRACE=1` for a backtrace."));
}
}
}
1 change: 1 addition & 0 deletions src/test/run-pass/stack-probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ fn assert_overflow(cmd: &mut Command) {
println!("stderr: {}", stderr);
assert!(stdout.is_empty());
assert!(stderr.contains("has overflowed its stack\n"));
assert!(stderr.contains("::"));
}