Skip to content

Commit e73ac8e

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 e73ac8e

15 files changed

+52
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ 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+
`RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test`
165+
155166
#### "found possibly newer version of crate `std` which `<dependency>` depends on"
156167

157168
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
}

tests/run-pass/panic/panic1.stderr

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:2:5
1+
thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:8:5
2+
stack backtrace:
3+
0: std::rt::begin_panic
4+
RUSTLIB/std/src/panicking.rs:505:12
5+
1: main
6+
at $DIR/panic1.rs:8:5
7+
2: <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
8+
RUSTLIB/core/src/ops/function.rs:227:5
9+
3: std::rt::lang_start::{closure#0}
10+
RUSTLIB/std/src/rt.rs:66:18
11+
4: std::ops::function::impls::call_once
12+
RUSTLIB/core/src/ops/function.rs:259:13
13+
5: std::panicking::r#try::do_call
14+
RUSTLIB/std/src/panicking.rs:381:40
15+
6: std::panicking::r#try
16+
RUSTLIB/std/src/panicking.rs:345:19
17+
7: std::panic::catch_unwind
18+
RUSTLIB/std/src/panic.rs:382:14
19+
8: std::rt::lang_start_internal
20+
RUSTLIB/std/src/rt.rs:51:25
21+
9: std::rt::lang_start
22+
RUSTLIB/std/src/rt.rs:65:5
23+
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

tests/run-pass/panic/panic2.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at '42-panicking from libstd', $DIR/panic2.rs:2:5
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/run-pass/panic/panic3.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at 'panicking from libcore', $DIR/panic3.rs:2:5
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/run-pass/panic/panic4.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at '42-panicking from libcore', $DIR/panic4.rs:2:5
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/run-pass/transmute_fat2.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', $DIR/transmute_fat2.rs:15:5
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)