Panic_nounwind line numbers: is it technical restriction or design decision

If panic going to cross extern "C" boundaries then panic_nounwind was called and process aborted, but why crash dumps not contain line number where panic was called, only line where extern "C" function was defined?

I mean with such code I got backtrace that point to line extern "C" fn c_func(abort: bool) { as source of panic:

extern "C" fn c_func(abort: bool) {
    if abort {
        panic!("something realy goes wrong");
    }
}

fn main() {
    c_func(true);
}

it is useful of course, but much more information I can get, if backtrace would contain line with panic source (panic!("something realy goes wrong");).

So exact line with panic! not included because of some technical problem, or it is by design?

By the time that the abort happens, the stack frame of the initial panic!() is already unwound and thus permanently lost.

1 Like

If you use the default panic hook with RUST_BACKTRACE=1, the original panic will be printed along with its stacktrace before unwinding starts.

For example (enable backtraces using the "..." button next to "stable")

thread 'main' panicked at src/main.rs:3:9:
something realy goes wrong
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/core/src/panicking.rs:75:14
   2: playground::c_func
             at ./src/main.rs:3:9
   3: playground::main
             at ./src/main.rs:8:5
   4: core::ops::function::FnOnce::call_once
             at ./.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

thread 'main' panicked at library/core/src/panicking.rs:225:5:
panic in a function that cannot unwind
stack backtrace:
[...]
  18:     0x60ebd76aa185 - core::panicking::panic_cannot_unwind::h4320389209385803
                               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/core/src/panicking.rs:330:5
  19:     0x60ebd76aa920 - playground::c_func::h0a787a9bd077b646
                               at /playground/src/main.rs:1:1
  20:     0x60ebd76aa94b - playground::main::h420381be4f74d8d6
                               at /playground/src/main.rs:8:5
[...]