-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-backtraceArea: BacktracesArea: BacktracesA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Given this file foo.rs
:
fn main() {
panic!();
}
A short backtrace for this panic would ideally include only std::panicking::begin_panic
and foo::main
. And, indeed, the implementing PR has a test for this output:
thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:17:5 | |
stack backtrace: | |
0: std::panicking::begin_panic | |
1: issue_47429_short_backtraces::main | |
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. |
However, this is how the backtrace actually looks with various flags:
rustc
(no flags; debug mode)
0: std::panicking::begin_panic
1: foo::main
2: core::ops::function::FnOnce::call_once
rustc -O
(release mode)
0: std::panicking::begin_panic
1: foo::main
rustc -O -C debuginfo=1
(release mode with debuginfo)
0: std::panicking::begin_panic
at ./.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:505
1: foo::main
at ./foo.rs:2
2: core::ops::function::FnOnce::call_once
at ./.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
So I think the __rust_begin_short_backtrace
implementation needs to account for this extra stack frame when it isn't optimized out by release mode. The test mentioned above only passes because it's compiled with -O
:
// compile-flags: -O |
I tested this on 1.47.0 stable and a nightly version:
rustc --version --verbose
rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0
rustc 1.49.0-nightly (91a79fb29 2020-10-07)
binary: rustc
commit-hash: 91a79fb29ac78d057d04dbe86be13d5dcc64309a
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0
Metadata
Metadata
Assignees
Labels
A-backtraceArea: BacktracesArea: BacktracesA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.