|
| 1 | +//! Test that with `-C panic=abort` the backtrace is not cut off by default |
| 2 | +//! (i.e. without using `-C force-unwind-tables=yes`) by ensuring that our own |
| 3 | +//! functions are in the backtrace. If we just check one function it might be |
| 4 | +//! the last function, so make sure the backtrace can continue by checking for |
| 5 | +//! two functions. Regression test for |
| 6 | +//! <https://github.com/rust-lang/rust/issues/81902>. |
| 7 | +
|
| 8 | +//@ run-pass |
| 9 | +//@ needs-subprocess |
| 10 | +//@ compile-flags: -C panic=abort -C opt-level=0 |
| 11 | +//@ no-prefer-dynamic |
| 12 | + |
| 13 | +static FN_1: &str = "this_function_must_be_in_the_backtrace"; |
| 14 | +fn this_function_must_be_in_the_backtrace() { |
| 15 | + and_this_function_too(); |
| 16 | +} |
| 17 | + |
| 18 | +static FN_2: &str = "and_this_function_too"; |
| 19 | +fn and_this_function_too() { |
| 20 | + panic!("generate panic backtrace"); |
| 21 | +} |
| 22 | + |
| 23 | +fn run_test() { |
| 24 | + let output = std::process::Command::new(std::env::current_exe().unwrap()) |
| 25 | + .arg("whatever") |
| 26 | + .env("RUST_BACKTRACE", "full") |
| 27 | + .output() |
| 28 | + .unwrap(); |
| 29 | + let backtrace = std::str::from_utf8(&output.stderr).unwrap(); |
| 30 | + |
| 31 | + fn assert(function_name: &str, backtrace: &str) { |
| 32 | + assert!( |
| 33 | + backtrace.contains(function_name), |
| 34 | + "ERROR: no `{}` in stderr! actual stderr: {}", |
| 35 | + function_name, |
| 36 | + backtrace |
| 37 | + ); |
| 38 | + } |
| 39 | + assert(FN_1, backtrace); |
| 40 | + assert(FN_2, backtrace); |
| 41 | +} |
| 42 | + |
| 43 | +fn main() { |
| 44 | + let args: Vec<String> = std::env::args().collect(); |
| 45 | + if args.len() == 1 { |
| 46 | + run_test(); |
| 47 | + } else { |
| 48 | + this_function_must_be_in_the_backtrace(); |
| 49 | + } |
| 50 | +} |
0 commit comments