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

The backtrace printed by assert_eq is wrong with panic=abort #111816

Closed
e00E opened this issue May 21, 2023 · 8 comments
Closed

The backtrace printed by assert_eq is wrong with panic=abort #111816

e00E opened this issue May 21, 2023 · 8 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.

Comments

@e00E
Copy link
Contributor

e00E commented May 21, 2023

stable-x86_64-unknown-linux-gnu
rustc 1.69.0 (84c898d 2023-04-16

Consider the following rust program:

fn main() {
    foo();
}

fn foo() {
    bar();
}

fn bar() {
    assert_eq!(false, true);
}

This program panics. The call stack at the panic is bar <- foo <- main.

I am going to run this program while varying the -Cpanic argument like so:

rustc -Cpanic=unwind -Cdebuginfo=1 a.rs && env RUST_BACKTRACE=full ./a

With -Cpanic=unwind:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `false`,
 right: `true`', a.rs:10:5
stack backtrace:
   0:     0x555d9bd4c5aa - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x555d9bd4c5aa - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x555d9bd4c5aa - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x555d9bd4c5aa - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x555d9bd6620e - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:     0x555d9bd4a735 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:     0x555d9bd4c375 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x555d9bd4c375 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x555d9bd4d9cf - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:     0x555d9bd4d70b - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:     0x555d9bd4df78 - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:692:13
  11:     0x555d9bd4de79 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  12:     0x555d9bd4ca16 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x555d9bd4db82 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  14:     0x555d9bd34ed3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  15:     0x555d9bd3514f - core::panicking::assert_failed_inner::haf9816227b20b6f2
  16:     0x555d9bd356e6 - core::panicking::assert_failed::hfe4604f1e2156329
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:211:5
  17:     0x555d9bd355d2 - a::bar::h54068ed5e62eaea6
                               at /tmp/a/a.rs:10:5
  18:     0x555d9bd35586 - a::foo::hbe93c09168c5d787
                               at /tmp/a/a.rs:6:5
  19:     0x555d9bd35576 - a::main::hf778f5e35fefb56f
                               at /tmp/a/a.rs:2:5
  20:     0x555d9bd35503 - core::ops::function::FnOnce::call_once::h0cda876b3b6f352f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5
  21:     0x555d9bd354e9 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcd8ad9bf1b410bdc
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:134:18
  22:     0x555d9bd35659 - std::rt::lang_start::{{closure}}::h135e76f90c71d025
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:166:18
  23:     0x555d9bd48a6c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hd6efcd3bec896f2c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:287:13
  24:     0x555d9bd48a6c - std::panicking::try::do_call::hce04e543bb1f4cbb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487:40
  25:     0x555d9bd48a6c - std::panicking::try::h3342dd4e1f680968
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451:19
  26:     0x555d9bd48a6c - std::panic::catch_unwind::h148ce1e59ac0cee7
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140:14
  27:     0x555d9bd48a6c - std::rt::lang_start_internal::{{closure}}::h25f9dda2057a67fe
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:148:48
  28:     0x555d9bd48a6c - std::panicking::try::do_call::h7caaaeaf9401650b
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487:40
  29:     0x555d9bd48a6c - std::panicking::try::he7d15285746cbbc2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451:19
  30:     0x555d9bd48a6c - std::panic::catch_unwind::h89fb4f50c0301fe0
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140:14
  31:     0x555d9bd48a6c - std::rt::lang_start_internal::h078acd489417d3c1
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:148:20
  32:     0x555d9bd35637 - std::rt::lang_start::h123fe1c2f5ee3bc1
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:165:17
  33:     0x555d9bd355fe - main
  34:     0x7f78e854c850 - <unknown>
  35:     0x7f78e854c90a - __libc_start_main
  36:     0x555d9bd35405 - _start
  37:                0x0 - <unknown>

With -Cpanic=abort:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `false`,
 right: `true`', a.rs:10:5
stack backtrace:
   0:     0x557cb620a58a - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x557cb620a58a - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x557cb620a58a - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x557cb620a58a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x557cb6223d9e - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:     0x557cb6208715 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:     0x557cb620a355 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x557cb620a355 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x557cb620b76f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:     0x557cb620b4ab - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:     0x557cb620bd18 - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:692:13
  11:     0x557cb620bc19 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  12:     0x557cb620a9f6 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x557cb620b922 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  14:     0x557cb61f2ed3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  15:     0x557cb61f314f - core::panicking::assert_failed_inner::haf9816227b20b6f2
  16:     0x557cb61f36c6 - core::panicking::assert_failed::hfe4604f1e2156329
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:211:5

Now I am going to change the assert_eq to assert:

assert!(false == true, "expected {} == {} but they weren't", false, true);

With -Cpanic=unwind:

thread 'main' panicked at 'expected false == true but they weren't', a.rs:10:5
stack backtrace:
   0:     0x564f3069467a - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x564f3069467a - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x564f3069467a - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x564f3069467a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x564f306ae2de - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:     0x564f30692805 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:     0x564f30694445 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x564f30694445 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x564f30695a9f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:     0x564f306957db - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:     0x564f30696048 - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:692:13
  11:     0x564f30695f49 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  12:     0x564f30694ae6 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x564f30695c52 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  14:     0x564f3067ced3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  15:     0x564f3067d5fd - a::bar::h54068ed5e62eaea6
                               at /tmp/a/a.rs:10:5
  16:     0x564f3067d576 - a::foo::hbe93c09168c5d787
                               at /tmp/a/a.rs:6:5
  17:     0x564f3067d566 - a::main::hf778f5e35fefb56f
                               at /tmp/a/a.rs:2:5
  18:     0x564f3067d503 - core::ops::function::FnOnce::call_once::h0cda876b3b6f352f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5
  19:     0x564f3067d4e9 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcd8ad9bf1b410bdc
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:134:18
  20:     0x564f3067d679 - std::rt::lang_start::{{closure}}::h135e76f90c71d025
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:166:18
  21:     0x564f30690b3c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hd6efcd3bec896f2c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:287:13
  22:     0x564f30690b3c - std::panicking::try::do_call::hce04e543bb1f4cbb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487:40
  23:     0x564f30690b3c - std::panicking::try::h3342dd4e1f680968
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451:19
  24:     0x564f30690b3c - std::panic::catch_unwind::h148ce1e59ac0cee7
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140:14
  25:     0x564f30690b3c - std::rt::lang_start_internal::{{closure}}::h25f9dda2057a67fe
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:148:48
  26:     0x564f30690b3c - std::panicking::try::do_call::h7caaaeaf9401650b
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487:40
  27:     0x564f30690b3c - std::panicking::try::he7d15285746cbbc2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451:19
  28:     0x564f30690b3c - std::panic::catch_unwind::h89fb4f50c0301fe0
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140:14
  29:     0x564f30690b3c - std::rt::lang_start_internal::h078acd489417d3c1
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:148:20
  30:     0x564f3067d657 - std::rt::lang_start::h123fe1c2f5ee3bc1
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:165:17
  31:     0x564f3067d61e - main
  32:     0x7fbbad08d850 - <unknown>
  33:     0x7fbbad08d90a - __libc_start_main
  34:     0x564f3067d405 - _start
  35:                0x0 - <unknown>

With -Cpanic=abort:

thread 'main' panicked at 'expected false == true but they weren't', a.rs:10:5
stack backtrace:
   0:     0x5562f55a165a - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x5562f55a165a - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5562f55a165a - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x5562f55a165a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x5562f55bae6e - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:     0x5562f559f7e5 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:     0x5562f55a1425 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x5562f55a1425 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x5562f55a283f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:     0x5562f55a257b - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:     0x5562f55a2de8 - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:692:13
  11:     0x5562f55a2ce9 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  12:     0x5562f55a1ac6 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x5562f55a29f2 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  14:     0x5562f5589ed3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  15:     0x5562f558a5dd - a::bar::h54068ed5e62eaea6
                               at /tmp/a/a.rs:10:5
  16:     0x5562f558a556 - a::foo::hbe93c09168c5d787
                               at /tmp/a/a.rs:6:5
  17:     0x5562f558a546 - a::main::hf778f5e35fefb56f
                               at /tmp/a/a.rs:2:5
  18:     0x5562f558a503 - core::ops::function::FnOnce::call_once::h0cda876b3b6f352f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5

The part of the backtrace that is meaningful is the bar <- foo <- main relation. This part was found in all configurations except when using -Cpanic=abort with assert_eq. This is a bug because as evidenced by the other backtraces, main, foo, and bar are part of the call stack at this point. Yet they are not printed. Even when accepting that asserts might print incorrect backtraces in an abort configuration (which I don't), it is still separately unexpected that the backtrace is only incorrect with assert_eq but not with assert.

@e00E e00E added the C-bug Category: This is a bug. label May 21, 2023
@rhmcruiser
Copy link

The outputs of assert and assert_eq with -Cpanic=abort are indeed having different call stacks.
And it seems the abort stack for 'assert_eq' is as intended as compared to abort stack of assert.

In the case of program with assert_eq and -Cpanic=abort the stack frames indicate panic right away as compared to the stack frames of program with assert call. (which is intended as opposed to Cpanic=unwind)

14: 0x557cb61f2ed3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
15: 0x557cb61f314f - core::panicking::assert_failed_inner::haf9816227b20b6f2
16: 0x557cb61f36c6 - core::panicking::assert_failed::hfe4604f1e2156329
at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:211:5

In case of program with assert and -Cpanic=abort the stack frames are not an abrupt panic as intended, but still goes through a milder form of walking up stack frames before starting the panic call ie as below core::ops::call_once->main-> foo->bar->panic_fmt

14: 0x5562f5589ed3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
15: 0x5562f558a5dd - a::bar::h54068ed5e62eaea6
at /tmp/a/a.rs:10:5
16: 0x5562f558a556 - a::foo::hbe93c09168c5d787
at /tmp/a/a.rs:6:5
17: 0x5562f558a546 - a::main::hf778f5e35fefb56f
at /tmp/a/a.rs:2:5
18: 0x5562f558a503 - core::ops::function::FnOnce::call_once::h0cda876b3b6f352f
at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:250:5

It appears that assert_eq is more close and correct to the intended behavior in this case, as per the below.

Below is a short read of when to use Cpanic=abort versus Cpanic=unwind and also using build time information for the same.

Unwinding the Stack or Aborting in Response to a Panic

By default, when a panic occurs, the program starts unwinding, which means Rust walks back up the stack and cleans up the data from each function it encounters. However, this walking back and cleanup is a lot of work. Rust, therefore, allows you to choose the alternative of immediately aborting, which ends the program without cleaning up.

Memory that the program was using will then need to be cleaned up by the operating system. If in your project you need to make the resulting binary as small as possible, you can switch from unwinding to aborting upon a panic by adding panic = 'abort' to the appropriate [profile] sections in your Cargo.toml file. For example, if you want to abort on panic in release mode, add this:

[profile.release]
panic = 'abort'

@e00E
Copy link
Contributor Author

e00E commented May 22, 2023

Your post and the documentation you link is about the difference between unwinding and aborting. This is not what this bug report is about. This bug report is about the backtrace that is printed when a panic occurs. The program prints the backtrace before unwinding/aborting.

@WaffleLapkin
Copy link
Member

With little testing I've found out that this is a regression between 1.20.0 and 1.30.0. Then with cargo bisect-rustc I've bisected down to a single nightly. This is a regression in nightly-2017-10-14.

The command I've used is cargo bisect-rustc --start=1.20.0 --end=1.30.0 --regress=error --script=./t.sh --access=github.

t.sh
#!/usr/bin/bash

rustc -Cpanic=abort -Cdebuginfo=1 ./t.rs && env RUST_BACKTRACE=full ./t 2>&1 | rg "bar"
t.rs
fn main() {
    foo();
}

fn foo() {
    bar();
}

fn bar() {
    assert_eq!(false, true);
}
cargo bisect-rustc output
searched toolchains nightly-2017-07-17 through nightly-2018-09-17


********************************************************************************
Regression in nightly-2017-10-14
********************************************************************************

fetching https://static.rust-lang.org/dist/2017-10-13/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2017-10-13: 40 B / 40 B [==============================================================================================================================] 100.00 % 913.59 KB/s converted 2017-10-13 to dcbbfb6e807fdff9c9ba80073bb755f9d9d95e31
fetching https://static.rust-lang.org/dist/2017-10-14/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2017-10-14: 40 B / 40 B [================================================================================================================================] 100.00 % 1.51 MB/s converted 2017-10-14 to 02a24dbdd8c3a5daa6578af72116020de75b5f93
looking for regression commit between 2017-10-13 and 2017-10-14
fetching (via remote github) commits from max(dcbbfb6e807fdff9c9ba80073bb755f9d9d95e31, 2017-10-11) to 02a24dbdd8c3a5daa6578af72116020de75b5f93
ending github query because we found starting sha: dcbbfb6e807fdff9c9ba80073bb755f9d9d95e31
get_commits_between returning commits, len: 10
  commit[0] 2017-10-12: Auto merge of #45007 - undecidabot:optimize-iter, r=bluss
  commit[1] 2017-10-12: Auto merge of #45233 - kennytm:rollup, r=kennytm
  commit[2] 2017-10-13: Auto merge of #45013 - chrisvittal:mir_pretty_printing_pr, r=nikomatsakis
  commit[3] 2017-10-13: Auto merge of #45025 - pnkfelix:mir-borrowck-moves-of-supporting-prefixes-invalidate-uses-too, r=arielb1
  commit[4] 2017-10-13: Auto merge of #45031 - alexcrichton:nounwind, r=arielb1
  commit[5] 2017-10-13: Auto merge of #45032 - alexcrichton:target-cfu, r=michaelwoerister
  commit[6] 2017-10-13: Auto merge of #45055 - GuillaumeGomez:search-tabs, r=QuietMisdreavus
  commit[7] 2017-10-13: Auto merge of #45063 - michaelwoerister:bring-back-incremental-info, r=nikomatsakis
  commit[8] 2017-10-13: Auto merge of #45261 - kennytm:rollup, r=kennytm
  commit[9] 2017-10-13: Auto merge of #45069 - sinkuu:tuple_arg, r=nikomatsakis
ERROR: no CI builds available between dcbbfb6e807fdff9c9ba80073bb755f9d9d95e31 and 02a24dbdd8c3a5daa6578af72116020de75b5f93 within last 167 days

Out of PRs mentioned in the output, the only one that is suspicious is #45031 which adds nounwind with -C panic=abort. I'd guess that LLVM thinks that since those functions can't unwind, there is no point in preserving the call chain and the calls get completely inlined.

I'm currently trying to use git bisect to find the exact commit, to be sure, but having troubles actually building rustc/llvm at such an old commit.

Not sure how raw assert! is different, that'll need more testing and I currently need sleep.

@WaffleLapkin WaffleLapkin added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label May 22, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 22, 2023
@rhmcruiser
Copy link

Even when accepting that asserts might print incorrect backtraces in an abort configuration (which I don't), it is still separately unexpected that the backtrace is only incorrect with assert_eq but not with assert.

@e00E I was only indicating that the observation of stack frames seemed the opposite, for the comparison between assert_eq( ) and assert( ) with -Cpanic=abort. It appears the assert_eq( ) stack frames were expected output for -Cpanic=abort style of termination of program and that assert( ) with -Cpanic=abort was not. ( The link reference was just an aside of what stack frames to expect at panic with abort versus panic with unwind and if that was inline here with the stack frames we saw. )

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 23, 2023
@Amanieu
Copy link
Member

Amanieu commented May 23, 2023

You need to pass -Cforce-unwind-tables when building with -C panic=abort otherwise LLVM will discard the metadata needed by the unwinder to generate a stack backtrace. Whether this should be the default behavior is an open question.

@apiraino
Copy link
Contributor

#94815 related to enabling -Cforce-unwind-tables by default when panic-abort

@apiraino
Copy link
Contributor

ok, we can close this as a dupe of #94815

@rustbot label -P-medium

@apiraino apiraino closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2023
@rustbot rustbot removed the P-medium Medium priority label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.
Projects
None yet
Development

No branches or pull requests

6 participants