|  | 
|  | 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 -C debuginfo=full | 
|  | 11 | +//@ no-prefer-dynamic | 
|  | 12 | +//@ ignore-arm-unknown-linux-gnueabihf FIXME(#146996) Try removing this once #146996 has been fixed. | 
|  | 13 | + | 
|  | 14 | +static FN_1: &str = "this_function_must_be_in_the_backtrace"; | 
|  | 15 | +fn this_function_must_be_in_the_backtrace() { | 
|  | 16 | +    and_this_function_too(); | 
|  | 17 | +} | 
|  | 18 | + | 
|  | 19 | +static FN_2: &str = "and_this_function_too"; | 
|  | 20 | +fn and_this_function_too() { | 
|  | 21 | +    panic!("generate panic backtrace"); | 
|  | 22 | +} | 
|  | 23 | + | 
|  | 24 | +fn run_test() { | 
|  | 25 | +    let output = std::process::Command::new(std::env::current_exe().unwrap()) | 
|  | 26 | +        .arg("whatever") | 
|  | 27 | +        .env("RUST_BACKTRACE", "full") | 
|  | 28 | +        .output() | 
|  | 29 | +        .unwrap(); | 
|  | 30 | +    let backtrace = std::str::from_utf8(&output.stderr).unwrap(); | 
|  | 31 | + | 
|  | 32 | +    fn assert(function_name: &str, backtrace: &str) { | 
|  | 33 | +        assert!( | 
|  | 34 | +            backtrace.contains(function_name), | 
|  | 35 | +            "ERROR: no `{}` in stderr! actual stderr: {}", | 
|  | 36 | +            function_name, | 
|  | 37 | +            backtrace | 
|  | 38 | +        ); | 
|  | 39 | +    } | 
|  | 40 | +    assert(FN_1, backtrace); | 
|  | 41 | +    assert(FN_2, backtrace); | 
|  | 42 | +} | 
|  | 43 | + | 
|  | 44 | +fn main() { | 
|  | 45 | +    let args: Vec<String> = std::env::args().collect(); | 
|  | 46 | +    if args.len() == 1 { | 
|  | 47 | +        run_test(); | 
|  | 48 | +    } else { | 
|  | 49 | +        this_function_must_be_in_the_backtrace(); | 
|  | 50 | +    } | 
|  | 51 | +} | 
0 commit comments