-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
short backtraces do not always work on Windows without debug info #87481
Comments
Works fine with
|
It looks like there are two issues at play here:
|
…ktraces_windows_optimized, r=dtolnay [backtraces]: look for the `begin` symbol only after seeing `end` On `x86_64-pc-windows-msvc`, we often get backtraces which look like this: ``` 10: 0x7ff77e0e9be5 - std::panicking::rust_panic_with_hook 11: 0x7ff77e0e11b4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c 12: 0x7ff77e0e116f - std::sys_common::backtrace::__rust_end_short_backtrace::h61c7ecb1b55338ae 13: 0x7ff77e0f89dd - std::panicking::begin_panic::h8e60ef9f82a41805 14: 0x7ff77e0e108c - d 15: 0x7ff77e0e1069 - c 16: 0x7ff77e0e1059 - b 17: 0x7ff77e0e1049 - a 18: 0x7ff77e0e1039 - core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>::h1bfcd14d5e15ba81 19: 0x7ff77e0e1186 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c 20: 0x7ff77e0e100c - std::rt::lang_start::{{closure}}::ha054184bbf9921e3 ``` Notice that `__rust_begin_short_backtrace` appears on frame 11 before `__rust_end_short_backtrace` on frame 12. This is because in typical release binaries without debug symbols, dbghelp.dll, which we use to walk and symbolize the stack, does not know where CGU internal functions start or end and so the closure invoked by `__rust_end_short_backtrace` is incorrectly described as `__rust_begin_short_backtrace` because it happens to be near that symbol. While that can obviously change, this has been happening quite consistently since rust-lang#75048. Since this is a very small change to the std and the change makes sense by itself, I think this is worth doing. This doesn't completely resolve the situation for release binaries on Windows, since without debug symbols, the stack printed can still show incorrect symbol names (this is why the test uses `#[no_mangle]`) but it does slightly improve the situation in that you see the same backtrace you would see with `RUST_BACKTRACE=full` or in a debugger (without the uninteresting bits at the top and bottom). Fixes part of rust-lang#87481
10332: minor: Allow overwriting RUST_BACKTRACE for the server manually r=jonas-schievink a=Veykril Trying to figure out why we aren't getting backtraces for windows builds from CI, this let's one set the backtraces to `FULL` Might be cc rust-lang/rust#87481 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
This has been causing failures in CI here and in rust-lang#90408. A comment there (rust-lang#90408 (comment)) suggested blessing the output; this commit does that manually.
Ever since #75048,
RUST_BACKTRACE=1
does not show a backtrace in some situations when compiling with x86_64-pc-windows-msvc. Some examples:Basic main
RUST_BACKTRACE=1 cargo run --release
On windows shows:
On other platforms, this shows:
Hm, OK, maybe there's just something weird about
main
on Windows, let's panic from some function:Exact same results. I wonder what
RUST_BACKTRACE=full
shows:There's a lot of weird
__rust_begin_short_backtrace
frames in there, and no sign of myabc
function. Running with debuginfo:CARGO_PROFILE_RELEASE_DEBUG=1 RUST_BACKTRACE=1 cargo run --release
Well at least with debuginfo the frames look much more reasonable.
rustc treat-err-as-bug
Trying to get a backtrace from rustc:
// Some bogus code to trigger a compiler error. abc
RUSTFLAGS="-Ztreat-err-as-bug" RUST_BACKTRACE=1 cargo build
results in:
Hmm, no frames at all. Here's what
full
looks like:Notice the complete absence of
__rust_begin_short_backtrace
.Larger example
What's strange is that it works sometimes. I figured I'd try a larger example. I put a panic inside cargo itself, and got this:
Well that's weird! The short backtrace seems to work fine there.
Expected behavior
In general, I would expect it to work like it does on other platforms.
Meta
The short backtraces start with nightly-2020-08-09. In versions prior to that, RUST_BACKTRACE=1 just shows the full backtrace (with all the "noisy" frames). Tested up to nightly-2021-07-26.
The text was updated successfully, but these errors were encountered: