Skip to content

Commit 05bb560

Browse files
committed
Enable backtrace feature in the generated Xargo.toml
This allows the normal std panic hook to print a backtrace if `RUST_BACKTRACE=1` and `-Z miri-disable-isolation` are set
1 parent cc21740 commit 05bb560

15 files changed

+54
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ cargo miri test
152152
When using the above instructions, you may encounter a number of confusing compiler
153153
errors.
154154

155+
### "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"
156+
157+
You may see this when trying to get Miri to display a backtrace. By default, Miri
158+
doesn't expose any environment to the program, so running
159+
`RUST_BACKTRACE=1 cargo miri test` will not do what you expect.
160+
161+
To get a backtrace, you need to disable isolation
162+
[using `-Zmiri-disable-isolation`](#miri-flags):
163+
164+
```sh
165+
RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test
166+
```
167+
155168
#### "found possibly newer version of crate `std` which `<dependency>` depends on"
156169

157170
Your build directory may contain artifacts from an earlier build that have/have

cargo-miri/bin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn setup(subcommand: MiriCommand) {
296296
[dependencies.std]
297297
default_features = false
298298
# We support unwinding, so enable that panic runtime.
299-
features = ["panic_unwind"]
299+
features = ["panic_unwind", "backtrace"]
300300
301301
[dependencies.test]
302302
"#,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
warning: thread support is experimental. For example, Miri does not detect data races yet.
22

33
thread '<unnamed>' panicked at 'Hello!', $DIR/simple.rs:54:9
4+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
thread 'childthread' panicked at 'Hello, world!', $DIR/simple.rs:64:9

tests/run-pass/panic/catch_panic.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
thread 'main' panicked at 'Hello from panic: std', $DIR/catch_panic.rs:LL:27
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
23
Caught panic message (&str): Hello from panic: std
34
thread 'main' panicked at 'Hello from panic: 1', $DIR/catch_panic.rs:LL:26
45
Caught panic message (String): Hello from panic: 1

tests/run-pass/panic/concurrent-panic.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ warning: thread support is experimental. For example, Miri does not detect data
33
Thread 1 starting, will block on mutex
44
Thread 1 reported it has started
55
thread '<unnamed>' panicked at 'panic in thread 2', $DIR/concurrent-panic.rs:65:13
6+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
67
Thread 2 blocking on thread 1
78
Thread 2 reported it has started
89
Unlocking mutex
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at 'attempt to divide by zero', $DIR/div-by-zero-2.rs:4:14
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at 'attempt to shift left with overflow', $DIR/overflowing-lsh-neg.rs:4:14
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-1.rs:4:14
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-2.rs:5:14
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/run-pass/panic/panic1.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// rustc-env: RUST_BACKTRACE=1
2+
// compile-flags: -Zmiri-disable-isolation
3+
// normalize-stderr-test ".*/(rust|checkout)/library/" -> "RUSTLIB/"
4+
// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
5+
// normalize-stderr-test "::<.*>" -> ""
6+
17
fn main() {
28
std::panic!("panicking from libstd");
39
}

0 commit comments

Comments
 (0)