Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very confusing error message when panicking during a panic #114954

Closed
SUPERCILEX opened this issue Aug 18, 2023 · 18 comments · Fixed by #115045
Closed

Very confusing error message when panicking during a panic #114954

SUPERCILEX opened this issue Aug 18, 2023 · 18 comments · Fixed by #115045
Labels
A-panic Area: Panicking machinery C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@SUPERCILEX
Copy link
Contributor

I tried this code:

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        panic!("drop");
    }
}

fn main() {
    let f = Foo;
    panic!("main");
}
9  | / fn main() {
10 | |     let f = Foo;
11 | |     panic!("main");
12 | | }
   | |_^ panic in a function that cannot unwind

Clearly the function panics so the error message doesn't make much sense. I believe it's saying that while panicking, the function is placed into a context in which nested panics are disallowed. Perhaps the message could include a hint that says something like Possibly caused by nested panics from a drop function.

@SUPERCILEX SUPERCILEX added the C-bug Category: This is a bug. label Aug 18, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 18, 2023
@SUPERCILEX
Copy link
Contributor Author

cc @RalfJung

@SUPERCILEX
Copy link
Contributor Author

Mmmm, actually this doesn't have anything to do with miri. Simply executing this code produces thread caused non-unwinding panic. aborting.. It'd be nice if these error messages could hint that the problem may be a panic inside a drop function while handling another panic. Took me a while to figure out that bug for code I was working on.

@SUPERCILEX SUPERCILEX changed the title Very confusing error message from Miri when panicking during a panic Very confusing error message when panicking during a panic Aug 18, 2023
@asquared31415
Copy link
Contributor

asquared31415 commented Aug 18, 2023

This changed in 1.71:

1.70.0 output:

thread 'main' panicked at 'main', /app/example.rs:11:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'drop', /app/example.rs:5:9
stack backtrace:
<panic impl>
  12:     0x55850c75f2e6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x55850c760382 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:     0x55850c747f43 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:     0x55850c748589 - <example::Foo as core::ops::drop::Drop>::drop::h393280156e206bc4
                               at /app/example.rs:5:9
  16:     0x55850c748589 - core::ptr::drop_in_place<example::Foo>::h69e3b7c38057fb9a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ptr/mod.rs:490:1
  17:     0x55850c7485e0 - example::main::h69ec135913889ca2
                               at /app/example.rs:12:1
  18:     0x55850c748623 - core::ops::function::FnOnce::call_once::he901fc162f15c821
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
  19:     0x55850c748623 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd136515e50fde4e6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:134:18
<start impl>
thread panicked while panicking. aborting.

1.71.0 output:

thread 'main' panicked at 'main', /app/example.rs:11:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'drop', /app/example.rs:5:9
stack backtrace:
<panic impl>
  13:     0x55f78aa65306 - std::sys_common::backtrace::__rust_end_short_backtrace::h1410008071796261
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55f78aa66162 - rust_begin_unwind
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
  15:     0x55f78aa4ce93 - core::panicking::panic_fmt::ha0a42a25e0cf258d
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
  16:     0x55f78aa4d60f - <example::Foo as core::ops::drop::Drop>::drop::hf6598d2a8a8b819e
                               at /app/example.rs:5:9
  17:     0x55f78aa4d60f - core::ptr::drop_in_place<example::Foo>::h0d465081db81d2a5
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ptr/mod.rs:497:1
  18:     0x55f78aa4d666 - example::main::h5848d682d5469a37
                               at /app/example.rs:12:1
  19:     0x55f78aa4d5c3 - core::ops::function::FnOnce::call_once::h0264184e1d2bb69c
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
  20:     0x55f78aa4d5c3 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha41bc7dc1ab08e83
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:135:18
<start impl>
thread 'main' panicked at 'panic in a function that cannot unwind', library/core/src/panicking.rs:126:5
stack backtrace:
<panic impl>
  13:     0x55f78aa65306 - std::sys_common::backtrace::__rust_end_short_backtrace::h1410008071796261
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55f78aa66162 - rust_begin_unwind
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
  15:     0x55f78aa4ced3 - core::panicking::panic_nounwind_fmt::h80a99c33c4703954
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:96:14
  16:     0x55f78aa4cf77 - core::panicking::panic_nounwind::h81a1bb4a16bcd655
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:126:5
  17:     0x55f78aa4d013 - core::panicking::panic_cannot_unwind::hc3ef110419ba8f94
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:188:5
  18:     0x55f78aa4d66e - example::main::h5848d682d5469a37
                               at /app/example.rs:9:1
  19:     0x55f78aa4d5c3 - core::ops::function::FnOnce::call_once::h0264184e1d2bb69c
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
  20:     0x55f78aa4d5c3 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha41bc7dc1ab08e83
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:135:18
<start impl>
thread caused non-unwinding panic. aborting.

1.71.0 stabilized C-unwind in #106075 (feature tracked in #74990), and that's what I expect this change to bisect to (though I haven't done any actual bisection)

It would be nice if the old message could be restored, the message "thread panicked while panicking. aborting." is significantly more clear. The extra backtrace also isn't super nice.

@SUPERCILEX
Copy link
Contributor Author

A combination of those error messages would be great too.

@RalfJung
Copy link
Member

RalfJung commented Aug 18, 2023 via email

@RalfJung
Copy link
Member

I think the origin of the behavior change is #110975, and this is probably known, but maybe something can be done to improve the error.

Cc @Amanieu

@Amanieu
Copy link
Member

Amanieu commented Aug 20, 2023

Currently the compiler does not differentiate between an unwind in a landing pad (recursive panic) and an unwind from a function that cannot unwind (extern "C"). It might be possible to handle these slightly differently so they produce different panic messages.

@RalfJung
Copy link
Member

RalfJung commented Aug 20, 2023

Well, unwind in a landing pad itself doesn't show that same error. It's the double-panic that triggers the error.

Here's the full error:

thread 'main' panicked at src/main.rs:11:5:
main
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at src/main.rs:5:9:
drop
stack backtrace:
   0:     0x562b11e2b2fc - std::backtrace_rs::backtrace::libunwind::trace::hcccbe357f6294ee4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x562b11e2b2fc - std::backtrace_rs::backtrace::trace_unsynchronized::h2aeedc764cf5993d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x562b11e2b2fc - std::sys_common::backtrace::_print_fmt::h5253f13953735ceb
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x562b11e2b2fc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h10e03889795ce36f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x562b11e4aecc - core::fmt::rt::Argument::fmt::hb786e11d88f815da
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/rt.rs:138:9
   5:     0x562b11e4aecc - core::fmt::write::h8196208c7c3ea798
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/mod.rs:1094:21
   6:     0x562b11e28fce - std::io::Write::write_fmt::hdd2d932fce82b22e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/io/mod.rs:1714:15
   7:     0x562b11e2b0e4 - std::sys_common::backtrace::_print::hee67efbbcef8ebe2
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x562b11e2b0e4 - std::sys_common::backtrace::print::h1f9d56503b146d30
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x562b11e2c87a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h863c0efb88e46827
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:278:22
  10:     0x562b11e2c567 - std::panicking::panic_hook_with_disk_dump::h7a9bb486f3291dc7
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:312:9
  11:     0x562b11e2ce7b - std::panicking::default_hook::h7e8caec6028d8d9d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:239:5
  12:     0x562b11e2ce7b - std::panicking::rust_panic_with_hook::h83c27eadec9ef70a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:729:13
  13:     0x562b11e2cd31 - std::panicking::begin_panic_handler::{{closure}}::hd577ca9f8724d099
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:619:13
  14:     0x562b11e2b826 - std::sys_common::backtrace::__rust_end_short_backtrace::h5a1a2830cb802d5e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:170:18
  15:     0x562b11e2cac2 - rust_begin_unwind
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:617:5
  16:     0x562b11e0ee33 - core::panicking::panic_fmt::h0645525d32fb8666
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:67:14
  17:     0x562b11e0f729 - <playground::Foo as core::ops::drop::Drop>::drop::hb5cf5518153c0058
                               at /playground/src/main.rs:5:9
  18:     0x562b11e0f6ca - core::ptr::drop_in_place<playground::Foo>::h10bed791575028cd
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ptr/mod.rs:497:1
  19:     0x562b11e0f756 - playground::main::h3a7c7f175b3be352
                               at /playground/src/main.rs:12:1
  20:     0x562b11e0f6bb - core::ops::function::FnOnce::call_once::hacc5d76449aef962
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:250:5
  21:     0x562b11e0f50e - std::sys_common::backtrace::__rust_begin_short_backtrace::h8e74152d9bd2457f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:154:18
  22:     0x562b11e0f581 - std::rt::lang_start::{{closure}}::h3d7d79b4aed530fe
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:166:18
  23:     0x562b11e26b7b - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hadefdea4fbcf6398
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:284:13
  24:     0x562b11e26b7b - std::panicking::try::do_call::haa16a0bcad25b40d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  25:     0x562b11e26b7b - std::panicking::try::h9367aba29c754779
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  26:     0x562b11e26b7b - std::panic::catch_unwind::h4021f90141f42c42
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  27:     0x562b11e26b7b - std::rt::lang_start_internal::{{closure}}::hff568c1c1264e3e9
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:48
  28:     0x562b11e26b7b - std::panicking::try::do_call::ha9e4f3477463e2d1
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  29:     0x562b11e26b7b - std::panicking::try::hac29284aba256fb6
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  30:     0x562b11e26b7b - std::panic::catch_unwind::h985169b2a86bf7f4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  31:     0x562b11e26b7b - std::rt::lang_start_internal::h23bd64986d4ee27a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:20
  32:     0x562b11e0f55a - std::rt::lang_start::hc617a4fa67be1c4d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:165:17
  33:     0x562b11e0f7be - main
  34:     0x7f7403a7e083 - __libc_start_main
  35:     0x562b11e0f43e - _start
  36:                0x0 - <unknown>
thread 'main' panicked at library/core/src/panicking.rs:126:5:
panic in a function that cannot unwind
stack backtrace:
   0:     0x562b11e2b2fc - std::backtrace_rs::backtrace::libunwind::trace::hcccbe357f6294ee4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x562b11e2b2fc - std::backtrace_rs::backtrace::trace_unsynchronized::h2aeedc764cf5993d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x562b11e2b2fc - std::sys_common::backtrace::_print_fmt::h5253f13953735ceb
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x562b11e2b2fc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h10e03889795ce36f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x562b11e4aecc - core::fmt::rt::Argument::fmt::hb786e11d88f815da
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/rt.rs:138:9
   5:     0x562b11e4aecc - core::fmt::write::h8196208c7c3ea798
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/mod.rs:1094:21
   6:     0x562b11e28fce - std::io::Write::write_fmt::hdd2d932fce82b22e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/io/mod.rs:1714:15
   7:     0x562b11e2b0e4 - std::sys_common::backtrace::_print::hee67efbbcef8ebe2
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x562b11e2b0e4 - std::sys_common::backtrace::print::h1f9d56503b146d30
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x562b11e2c87a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h863c0efb88e46827
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:278:22
  10:     0x562b11e2c567 - std::panicking::panic_hook_with_disk_dump::h7a9bb486f3291dc7
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:312:9
  11:     0x562b11e2ce7b - std::panicking::default_hook::h7e8caec6028d8d9d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:239:5
  12:     0x562b11e2ce7b - std::panicking::rust_panic_with_hook::h83c27eadec9ef70a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:729:13
  13:     0x562b11e2cd31 - std::panicking::begin_panic_handler::{{closure}}::hd577ca9f8724d099
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:619:13
  14:     0x562b11e2b826 - std::sys_common::backtrace::__rust_end_short_backtrace::h5a1a2830cb802d5e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:170:18
  15:     0x562b11e2cac2 - rust_begin_unwind
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:617:5
  16:     0x562b11e0ee73 - core::panicking::panic_nounwind_fmt::h612fcdcf4aa7da1e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:96:14
  17:     0x562b11e0ef17 - core::panicking::panic_nounwind::h4dbadcdcb4ff29ed
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:126:5
  18:     0x562b11e0efa3 - core::panicking::panic_cannot_unwind::had39ece280b9c200
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:189:5
  19:     0x562b11e0f78a - playground::main::h3a7c7f175b3be352
                               at /playground/src/main.rs:9:1
  20:     0x562b11e0f6bb - core::ops::function::FnOnce::call_once::hacc5d76449aef962
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:250:5
  21:     0x562b11e0f50e - std::sys_common::backtrace::__rust_begin_short_backtrace::h8e74152d9bd2457f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:154:18
  22:     0x562b11e0f581 - std::rt::lang_start::{{closure}}::h3d7d79b4aed530fe
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:166:18
  23:     0x562b11e26b7b - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hadefdea4fbcf6398
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:284:13
  24:     0x562b11e26b7b - std::panicking::try::do_call::haa16a0bcad25b40d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  25:     0x562b11e26b7b - std::panicking::try::h9367aba29c754779
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  26:     0x562b11e26b7b - std::panic::catch_unwind::h4021f90141f42c42
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  27:     0x562b11e26b7b - std::rt::lang_start_internal::{{closure}}::hff568c1c1264e3e9
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:48
  28:     0x562b11e26b7b - std::panicking::try::do_call::ha9e4f3477463e2d1
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  29:     0x562b11e26b7b - std::panicking::try::hac29284aba256fb6
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  30:     0x562b11e26b7b - std::panic::catch_unwind::h985169b2a86bf7f4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  31:     0x562b11e26b7b - std::rt::lang_start_internal::h23bd64986d4ee27a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:20
  32:     0x562b11e0f55a - std::rt::lang_start::hc617a4fa67be1c4d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:165:17
  33:     0x562b11e0f7be - main
  34:     0x7f7403a7e083 - __libc_start_main
  35:     0x562b11e0f43e - _start
  36:                0x0 - <unknown>
thread caused non-unwinding panic. aborting.

Having 2 stacktraces is already somewhat strange. And doesn't the panic machinery know that a panic-while-panicking occurred, so that it can print that?

@Amanieu
Copy link
Member

Amanieu commented Aug 20, 2023

That's a drop called from normal execution, not from a landing pad. I was specifically referring to a drop called from an unwind landing pad that is already being invoked as part of a previous unwind.

Having 2 stacktraces is already somewhat strange. And doesn't the panic machinery know that a panic-while-panicking occurred, so that it can print that?

The panic machinery can't determine that on its own, because this code is perfectly valid and shouldn't abort at the point of the inner panic, it should continue unwinding normally:

struct Double;

impl Drop for Double {
    fn drop(&mut self) {
        // 2 panics are active at once, but this is fine since it is caught.
        std::panic::catch_unwind(|| panic!("twice"));
    }
}

let _d = Double;

panic!("once");

@RalfJung
Copy link
Member

RalfJung commented Aug 20, 2023

Hm, I guess what happens is that the drop calls on the unwind path have UnwindAction::Terminate -- it's no longer the panic machinery that detects double-panic, it's the structure of the code itself. (EDIT: that's what you also just posted concurrently. :)

So to fix that we'd probably need some sort of reason field on UnwindAction::Terminate that records whether this is terminate-due-to-unwind-in-drop-on-cleanup-path or terminate-due-to-unwind-that-would-leave-extern "C".

@RalfJung
Copy link
Member

And then the 2nd backtrace occurs because panic_cannot_unwind is the third panic in this program, and it runs into

// 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 {
BacktraceStyle::full()
} else {
crate::panic::get_backtrace_style()
};

That's probably also undesirable for this case.

@Amanieu
Copy link
Member

Amanieu commented Aug 20, 2023

There is some value in having a backtrace here since it shows you which function on the stack was no-unwind. But I agree that in practice this has rather limited value.

@RalfJung
Copy link
Member

We should definitely print the backtrace on RUST_BACKTRACE=full, but I'm wondering if get_count() == 2 would be a better option here to avoid flooding the terminal with backtraces in the default state.

@RalfJung
Copy link
Member

When adding such a reason field, I wonder if it would be reasonable to change the UnwindAction::Terminate codegen to call panic_nounwind with an &str argument reflecting the error (like we do for Assert terminators). Or is it important that the function we call there takes no arguments?

Cc @bjorn3

@bjorn3
Copy link
Member

bjorn3 commented Aug 20, 2023

Adding a string argument would increase binary sizes as the string would be duplicated for every codegen unit that calls it. Using two separate functions would only codegen the functions + strings once in libcore.

@Amanieu
Copy link
Member

Amanieu commented Aug 20, 2023

Considering that there are a limited number of possible reasons, it would be better for code size to have a specific entry point for each reason.

@RalfJung
Copy link
Member

RalfJung commented Aug 20, 2023 via email

@bjorn3
Copy link
Member

bjorn3 commented Aug 20, 2023

Linkers can deduplicate C strings when marking the global as being a deduplicatable C string, however this requires the strings to be nul-terminated and not have any interior nul byte as they will split the section with the C strings on nul bytes to find the individual strings. There is also COMDAT which someone is trying to implement in rustc right now, but the current version of that PR seems to have the complete opposite effect and increase the binary size and make linking much slower: #114816

@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-panic Area: Panicking machinery and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 22, 2023
@bors bors closed this as completed in b60f7b5 Aug 25, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Aug 26, 2023
when terminating during unwinding, show the reason why

With this, the output on double-panic becomes something like that:
```
thread 'main' panicked at src/tools/miri/tests/fail/panic/double_panic.rs:15:5:
first
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at src/tools/miri/tests/fail/panic/double_panic.rs:10:9:
second
stack backtrace:
   0:           0xbe273a - std::backtrace_rs::backtrace::miri::trace_unsynchronized::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:99:5
   1:           0xbe22e6 - std::backtrace_rs::backtrace::miri::trace::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:62:14
   2:           0xbe1086 - std::backtrace_rs::backtrace::trace_unsynchronized::<[closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   3:           0xba3afd - std::sys_common::backtrace::_print_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:67:5
   4:           0xba2471 - <std::sys_common::backtrace::_print::DisplayBacktrace as std::fmt::Display>::fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:44:22
   5:           0xbcf754 - core::fmt::rt::Argument::<'_>::fmt
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/rt.rs:138:9
   6:           0x9b8f81 - std::fmt::write
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/mod.rs:1094:17
   7:           0x21391d - <std::sys::unix::stdio::Stderr as std::io::Write>::write_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/io/mod.rs:1714:15
   8:           0xba37b1 - std::sys_common::backtrace::_print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:47:5
   9:           0xba365b - std::sys_common::backtrace::print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:34:9
  10:           0x143c67 - std::panic_hook_with_disk_dump::{closure#1}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:278:22
  11:           0x144187 - std::panic_hook_with_disk_dump
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:312:9
  12:           0x143659 - std::panicking::default_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:239:5
  13:           0x1482a7 - std::panicking::rust_panic_with_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:729:13
  14:           0x1475d5 - std::rt::begin_panic::<&str>::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:650:9
  15:           0xba496a - std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::rt::begin_panic<&str>::{closure#0}], !>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:170:18
  16:           0x147599 - std::rt::begin_panic::<&str>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:649:12
  17:            0x31916 - <Foo as std::ops::Drop>::drop
                               at src/tools/miri/tests/fail/panic/double_panic.rs:10:9
  18:           0x1a2b5e - std::ptr::drop_in_place::<Foo> - shim(Some(Foo))
                               at /home/r/src/rust/rustc.3/library/core/src/ptr/mod.rs:497:1
  19:            0x202bf - main
                               at src/tools/miri/tests/fail/panic/double_panic.rs:16:1
  20:            0xcc6a8 - <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:250:5
  21:           0xba47d9 - std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:154:18
  22:           0x141a6a - std::rt::lang_start::<()>::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:166:18
  23:            0xcca18 - std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:284:13
  24:           0x146469 - std::panicking::try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  25:           0x145e09 - std::panicking::try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  26:            0x7b0ac - std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  27:           0x14189b - std::rt::lang_start_internal::{closure#2}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:48
  28:           0x146481 - std::panicking::try::do_call::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  29:           0x145e2c - std::panicking::try::<isize, [closure@std::rt::lang_start_internal::{closure#2}]>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  30:            0x7b0d5 - std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  31:           0x1418b0 - std::rt::lang_start_internal
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:20
  32:           0x141a97 - std::rt::lang_start::<()>
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:165:17
thread 'main' panicked at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:126:5:
panic in a destructor during cleanup
stack backtrace:
   0:           0xe9f6d7 - std::backtrace_rs::backtrace::miri::trace_unsynchronized::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:99:5
   1:           0xe9f27d - std::backtrace_rs::backtrace::miri::trace::<&mut [closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/miri.rs:62:14
   2:           0xe9e016 - std::backtrace_rs::backtrace::trace_unsynchronized::<[closure@std::sys_common::backtrace::_print_fmt::{closure#1}]>
                               at /home/r/src/rust/rustc.3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   3:           0xba3afd - std::sys_common::backtrace::_print_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:67:5
   4:           0xba2471 - <std::sys_common::backtrace::_print::DisplayBacktrace as std::fmt::Display>::fmt
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:44:22
   5:           0xbcf754 - core::fmt::rt::Argument::<'_>::fmt
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/rt.rs:138:9
   6:           0x9b8f81 - std::fmt::write
                               at /home/r/src/rust/rustc.3/library/core/src/fmt/mod.rs:1094:17
   7:           0x4d0895 - <std::sys::unix::stdio::Stderr as std::io::Write>::write_fmt
                               at /home/r/src/rust/rustc.3/library/std/src/io/mod.rs:1714:15
   8:           0xba37b1 - std::sys_common::backtrace::_print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:47:5
   9:           0xba365b - std::sys_common::backtrace::print
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:34:9
  10:           0x400bd4 - std::panic_hook_with_disk_dump::{closure#1}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:278:22
  11:           0x144187 - std::panic_hook_with_disk_dump
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:312:9
  12:           0x143659 - std::panicking::default_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:239:5
  13:           0x1482a7 - std::panicking::rust_panic_with_hook
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:729:13
  14:           0x40403b - std::panicking::begin_panic_handler::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:619:13
  15:           0xe618b3 - std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:170:18
  16:           0x403fc8 - std::panicking::begin_panic_handler
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:617:5
  17:           0xee23e9 - core::panicking::panic_nounwind_fmt
                               at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:96:14
  18:           0xee29e6 - core::panicking::panic_nounwind
                               at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:126:5
  19:           0xee365e - core::panicking::panic_in_cleanup
                               at /home/r/src/rust/rustc.3/library/core/src/panicking.rs:206:5
  20:            0x2028a - main
                               at src/tools/miri/tests/fail/panic/double_panic.rs:13:1
  21:           0x3895ee - <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:250:5
  22:           0xe61725 - std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
                               at /home/r/src/rust/rustc.3/library/std/src/sys_common/backtrace.rs:154:18
  23:           0x3fe9aa - std::rt::lang_start::<()>::{closure#0}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:166:18
  24:           0x389962 - std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once
                               at /home/r/src/rust/rustc.3/library/core/src/ops/function.rs:284:13
  25:           0x4033b9 - std::panicking::try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  26:           0x402d58 - std::panicking::try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  27:           0x337ff7 - std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  28:           0x3fe7e7 - std::rt::lang_start_internal::{closure#2}
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:48
  29:           0x4033d6 - std::panicking::try::do_call::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:524:40
  30:           0x402d7f - std::panicking::try::<isize, [closure@std::rt::lang_start_internal::{closure#2}]>
                               at /home/r/src/rust/rustc.3/library/std/src/panicking.rs:488:19
  31:           0x338028 - std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#2}], isize>
                               at /home/r/src/rust/rustc.3/library/std/src/panic.rs:142:14
  32:           0x1418b0 - std::rt::lang_start_internal
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:148:20
  33:           0x3fe9dc - std::rt::lang_start::<()>
                               at /home/r/src/rust/rustc.3/library/std/src/rt.rs:165:17
thread caused non-unwinding panic. aborting.
```
If we also land rust-lang/rust#115020, the 2nd backtrace disappears, hopefully making the "panic in a destructor during cleanup" easier to see.

Fixes rust-lang/rust#114954.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 27, 2023
…trace, r=Amanieu

avoid triple-backtrace due to panic-during-cleanup

Supersedes rust-lang#115020
Cc rust-lang#114954
r? `@Amanieu`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 28, 2023
…trace, r=Amanieu

avoid triple-backtrace due to panic-during-cleanup

Supersedes rust-lang#115020
Cc rust-lang#114954
r? ``@Amanieu``
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Aug 29, 2023
…Amanieu

avoid triple-backtrace due to panic-during-cleanup

Supersedes rust-lang/rust#115020
Cc rust-lang/rust#114954
r? ``@Amanieu``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-panic Area: Panicking machinery C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants