This is the code used to replicate the issue
use std::backtrace::Backtrace;
pub fn register_panic_handler() {
std::panic::set_hook(Box::new(move |panic_info| {
let pid = std::process::id();
eprintln!("process {} panicked", std::process::id());
eprintln!("{}", panic_info);
let backtrace = Backtrace::force_capture();
eprintln!("{:#?}", backtrace);
}));
}
fn foo() {
panic!("foo");
}
fn bar() {
foo()
}
fn main() {
register_panic_handler();
None::<u8>.unwrap();
}
I am using a Windows ARM VM on a MacBook.
When running the following I have an incomplete backtrace
Backtrace [
{ fn: "std::backtrace_rs::backtrace::dbghelp64::trace", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\..\..\backtrace\src\backtrace\dbghelp64.rs", line: 91 },
{ fn: "std::backtrace_rs::backtrace::trace_unsynchronized", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\..\..\backtrace\src\backtrace\mod.rs", line: 66 },
{ fn: "std::backtrace::Backtrace::create", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\backtrace.rs", line: 331 },
{ fn: "__ImageBase" },
{ fn: "alloc::boxed::impl$50::call", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/alloc\src\boxed.rs", line: 2245 },
{ fn: "std::panicking::rust_panic_with_hook", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\panicking.rs", line: 805 },
{ fn: "std::panicking::begin_panic_handler::closure$0", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\panicking.rs", line: 664 },
{ fn: "std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>", file: "/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\sys\backtrace.rs", line: 170 },
]
Nothing about main
, foo
or bar
. But when running the same code on any other target (MacOS ARM, Windows x86, MacOs x86, Linux, ...) I have the correct backtrace
Backtrace [
{ fn: "std::backtrace_rs::backtrace::libunwind::trace", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/libunwind.rs", line: 104 },
{ fn: "std::backtrace_rs::backtrace::trace_unsynchronized", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/mod.rs", line: 66 },
{ fn: "std::backtrace::Backtrace::create", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/backtrace.rs", line: 331 },
{ fn: "toto::register_panic_handler::{{closure}}", file: "./src/main.rs", line: 8 },
{ fn: "<alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs", line: 2021 },
{ fn: "std::panicking::rust_panic_with_hook", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 783 },
{ fn: "std::panicking::begin_panic_handler::{{closure}}", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 649 },
{ fn: "std::sys_common::backtrace::__rust_end_short_backtrace", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs", line: 170 },
{ fn: "rust_begin_unwind", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 645 },
{ fn: "core::panicking::panic_fmt", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs", line: 72 },
{ fn: "toto::foo", file: "./src/main.rs", line: 15 },
{ fn: "toto::bar", file: "./src/main.rs", line: 19 },
{ fn: "toto::main", file: "./src/main.rs", line: 25 },
{ fn: "core::ops::function::FnOnce::call_once", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs", line: 250 },
{ fn: "std::sys_common::backtrace::__rust_begin_short_backtrace", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs", line: 154 },
{ fn: "std::rt::lang_start::{{closure}}", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs", line: 167 },
{ fn: "core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs", line: 284 },
{ fn: "std::panicking::try::do_call", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 552 },
{ fn: "std::panicking::try", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 516 },
{ fn: "std::panic::catch_unwind", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs", line: 142 },
{ fn: "std::rt::lang_start_internal::{{closure}}", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs", line: 148 },
{ fn: "std::panicking::try::do_call", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 552 },
{ fn: "std::panicking::try", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs", line: 516 },
{ fn: "std::panic::catch_unwind", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs", line: 142 },
{ fn: "std::rt::lang_start_internal", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs", line: 148 },
{ fn: "std::rt::lang_start", file: "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs", line: 166 },
{ fn: "_main" },
]
Does anyone had the same issue on windows ARM ?
Note that after running the code multiple times in a row (no changes) I had a correct backtrace once (but never reproduced) in hundreds of attempts