miri
miri copied to clipboard
Allow backtraces to cross thread boundaries
Fixes #4066
When a thread is spawned we store the ID of the spawning thread as well as a backtrace to the spawn location. When there's an error we can traverse upwards, displaying a backtrace up to the main thread.
For instance, with the following program:
extern "C" {
fn unknown();
}
fn bad() {
unsafe { unknown() }
}
fn main() {
std::thread::spawn(bad);
}
Whereas previously we would see:
error: unsupported operation: can't call foreign function `unknown` on OS `linux`
--> tests/temp.rs:6:14
|
6 | unsafe { unknown() }
| ^^^^^^^^^ can't call foreign function `unknown` on OS `linux`
|
= help: if this is a basic API commonly used on this target, please report an issue with Miri
= help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
= note: BACKTRACE on thread `unnamed-1`:
= note: inside `bad` at tests/temp.rs:6:14: 6:23
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error
We now have:
error: unsupported operation: can't call foreign function `unknown` on OS `linux`
--> tests/temp.rs:6:14
|
6 | unsafe { unknown() }
| ^^^^^^^^^ can't call foreign function `unknown` on OS `linux`
|
= help: if this is a basic API commonly used on this target, please report an issue with Miri
= help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
= note: BACKTRACE on thread `unnamed-1`:
= note: inside `bad` at tests/temp.rs:6:14: 6:23
= note: thread `unnamed-1` was spawned by thread `main`
= note: inside `std::sys::pal::unix::thread::Thread::new` at /home/reimu/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/pal/unix/thread.rs:84:19: 84:86
= note: inside `std::thread::Builder::spawn_unchecked_::<'_, fn() {bad}, ()>` at /home/reimu/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/thread/mod.rs:600:30: 600:64
= note: inside `std::thread::Builder::spawn_unchecked::<fn() {bad}, ()>` at /home/reimu/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/thread/mod.rs:467:32: 467:62
= note: inside `std::thread::Builder::spawn::<fn() {bad}, ()>` at /home/reimu/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/thread/mod.rs:400:18: 400:41
= note: inside `std::thread::spawn::<fn() {bad}, ()>` at /home/reimu/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/thread/mod.rs:730:5: 730:28
note: inside `main`
--> tests/temp.rs:10:5
|
10 | std::thread::spawn(bad);
| ^^^^^^^^^^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error
You'll need to bless the windows tests, too. It should suffice to pass --target with a windows target, no windows host needed
I have some nits.
@rustbot author
Please post @rustbot ready when the PR is ready for the next round of review.
:umbrella: The latest upstream changes (possibly 807129cf8228252494eb074a1df13f5decb0c78b) made this pull request unmergeable. Please resolve the merge conflicts.
I will close this due to inactivity. Feel free to reopen if you want to pick this back up!