Skip to content
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

By default, RUST_BACKTRACE=1 silently has no effect on Miri, even though it is suggested in panic messages #2855

Closed
matthiaskrgr opened this issue Apr 2, 2023 · 11 comments · Fixed by rust-lang/rust#124116
Labels
A-diagnostics errors and warnings emitted by miri C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement

Comments

@matthiaskrgr
Copy link
Member

cc rust-lang/rust#98112
cc @saethlin

Code from the pr

fn main() {
    let mut x = [0u32; 2];
    let ptr: *mut u8 = x.as_mut_ptr().cast::<u8>();
    unsafe {
        *(ptr.add(1).cast::<u32>()) = 42;
    }
}

run with RUST_BACKTRACE=1 ~/.cargo/bin/cargo miri run seems to not print any backtrace disregarding what the panic output suggests:

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping.
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/f`
thread 'main' panicked at 'misaligned pointer dereference: address must be a multiple of 0x4 but is 0x278b1', src/main.rs:5:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Apr 2, 2023
@deltragon
Copy link

Does disabling isolation help?
See https://github.com/rust-lang/miri#note-run-with-rust_backtrace1-environment-variable-to-display-a-backtrace

@saethlin
Copy link
Member

saethlin commented Apr 2, 2023

There's no bug here, but I do believe we have a diagnostic issue. @matthiaskrgr is a decently experienced Rust and Miri user, if this is too subtle for Matthias it has probably tripped up new Miri users.

@rust-lang/miri Is there a reasonable way to solve this in Miri? I'm tempted to stick something like this into the standard library right after the write! for that note: run with RUST_BACKTRACE=1, but that seems like hacking the library because I can't figure out how to detect this situation inside Miri.

@RalfJung
Copy link
Member

RalfJung commented Apr 3, 2023 via email

@saethlin
Copy link
Member

saethlin commented Apr 3, 2023

We could also always set it when isolation is enabled. The only potential hazard there is that I have seen one other library check for RUST_BACKTRACE=1 and change behavior (trust-dns-resolver used to include a full backtrace in the Debug impl for its errors when RUST_BACKTRACE was set).

But really what I'm asking is: Can we detect in Miri that we have hit the default panic handler and printed a backtrace, then issue our own little note: after that? My instinct is "no", because that's asking for a lot of details about exactly what library code we executed, but I would like to be sure.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 5, 2023

We could make default_hook a diagnostic_item and check that in miri. After calling it we could just write another note: to stderr, even if writing to stderr is not 100% the right thing (there's some thread local shenanigans going on).

@saethlin saethlin changed the title RUST_BACKTRACE has no effect on misaligned pointer dereference panic? By default, RUST_BACKTRACE=1 silently has no effect on Miri, even though it is suggested in panic messages Apr 6, 2023
@saethlin saethlin removed the C-bug Category: This is a bug. label Apr 6, 2023
@RalfJung
Copy link
Member

RalfJung commented Apr 7, 2023 via email

@jyn514
Copy link
Member

jyn514 commented Apr 7, 2023

Should this be moved to the rust-lang/miri repo?

@jyn514 jyn514 added the A-diagnostics errors and warnings emitted by miri label Apr 7, 2023
@saethlin
Copy link
Member

saethlin commented Apr 7, 2023

No, 2 of the 3 proposed solutions involve modifying the standard library code.

@RalfJung RalfJung transferred this issue from rust-lang/rust Apr 26, 2023
@RalfJung
Copy link
Member

This is a Miri issue, so moving to the Miri repo.

@RalfJung RalfJung added the C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement label Apr 18, 2024
@workingjubilee
Copy link
Member

I believe the preferable solution would be to simply ignore the env vars and emit a backtrace while emitting a backtrace due to panic.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 18, 2024
…lstrieb

when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
@RalfJung
Copy link
Member

That seems like an odd difference between regular default and Miri defaults to me.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 18, 2024
…lstrieb

when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Apr 18, 2024
…lstrieb

when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Apr 18, 2024
…lstrieb

when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 19, 2024
Rollup merge of rust-lang#124116 - RalfJung:miri-rust-backtrace, r=Nilstrieb

when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
github-actions bot pushed a commit that referenced this issue Apr 20, 2024
when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes #2855
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 20, 2024
when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes rust-lang/miri#2855
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics errors and warnings emitted by miri C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants