From 8121de137cfcb9848cf9951c8b690d54214efc78 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 20 Aug 2023 10:18:59 +0200 Subject: [PATCH 1/2] for triple-panics, do not keep printing backtraces --- library/std/src/panicking.rs | 5 ++++- src/tools/miri/tests/fail/panic/double_panic.stderr | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 6ff7b19f293d3..ca32e458478da 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -246,7 +246,10 @@ fn default_hook(info: &PanicInfo<'_>) { pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path::Path>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. - let backtrace = if panic_count::get_count() >= 2 { + // We do not keep printing for further panics, so that e.g. a "panic inside a drop on an unwind + // path", which leads to a triple-panic (the third panic being "cannot unwind here"), doesn't + // print *two* backtraces. + let backtrace = if panic_count::get_count() == 2 { BacktraceStyle::full() } else { crate::panic::get_backtrace_style() diff --git a/src/tools/miri/tests/fail/panic/double_panic.stderr b/src/tools/miri/tests/fail/panic/double_panic.stderr index 9efba031250be..20b751d57a250 100644 --- a/src/tools/miri/tests/fail/panic/double_panic.stderr +++ b/src/tools/miri/tests/fail/panic/double_panic.stderr @@ -6,7 +6,6 @@ second stack backtrace: thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a destructor during cleanup -stack backtrace: thread caused non-unwinding panic. aborting. error: abnormal termination: the program aborted execution --> RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC From 5160ea744e0b8319c79a988a79e1d1e0f3e467bf Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 22 Aug 2023 15:06:15 +0200 Subject: [PATCH 2/2] have a test ensure that a panic-during-cleanup only prints one btacktrace by default --- tests/ui/backtrace.rs | 2 ++ tests/ui/panics/panic-in-cleanup.run.stderr | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ui/backtrace.rs b/tests/ui/backtrace.rs index 95783945529a5..4c832ca157381 100644 --- a/tests/ui/backtrace.rs +++ b/tests/ui/backtrace.rs @@ -106,6 +106,8 @@ fn runtest(me: &str) { contains_verbose_expected(s, "double"), "bad output3: {}", s ); + // Make sure it's only one stack trace. + assert_eq!(s.split("stack backtrace").count(), 2); // Make sure a stack trace isn't printed too many times // diff --git a/tests/ui/panics/panic-in-cleanup.run.stderr b/tests/ui/panics/panic-in-cleanup.run.stderr index 923bac69c50ef..b655b388c6c68 100644 --- a/tests/ui/panics/panic-in-cleanup.run.stderr +++ b/tests/ui/panics/panic-in-cleanup.run.stderr @@ -6,5 +6,4 @@ BOOM stack backtrace: thread 'main' panicked at library/core/src/panicking.rs:126:5: panic in a destructor during cleanup -stack backtrace: thread caused non-unwinding panic. aborting.