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

Enable backtrace feature in the generated Xargo.toml #1589

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ cargo miri test
When using the above instructions, you may encounter a number of confusing compiler
errors.

### "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"

You may see this when trying to get Miri to display a backtrace. By default, Miri
doesn't expose any environment to the program, so running
`RUST_BACKTRACE=1 cargo miri test` will not do what you expect.

To get a backtrace, you need to disable isolation
[using `-Zmiri-disable-isolation`](#miri-flags):

```sh
RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test
```

#### "found possibly newer version of crate `std` which `<dependency>` depends on"

Your build directory may contain artifacts from an earlier build that have/have
Expand Down
2 changes: 1 addition & 1 deletion cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fn setup(subcommand: MiriCommand) {
[dependencies.std]
default_features = false
# We support unwinding, so enable that panic runtime.
features = ["panic_unwind"]
features = ["panic_unwind", "backtrace"]

[dependencies.test]
"#,
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/concurrency/simple.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
warning: thread support is experimental. For example, Miri does not detect data races yet.

thread '<unnamed>' panicked at 'Hello!', $DIR/simple.rs:54:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'childthread' panicked at 'Hello, world!', $DIR/simple.rs:64:9
1 change: 1 addition & 0 deletions tests/run-pass/panic/catch_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
thread 'main' panicked at 'Hello from panic: std', $DIR/catch_panic.rs:LL:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Caught panic message (&str): Hello from panic: std
thread 'main' panicked at 'Hello from panic: 1', $DIR/catch_panic.rs:LL:26
Caught panic message (String): Hello from panic: 1
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/panic/concurrent-panic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ warning: thread support is experimental. For example, Miri does not detect data
Thread 1 starting, will block on mutex
Thread 1 reported it has started
thread '<unnamed>' panicked at 'panic in thread 2', $DIR/concurrent-panic.rs:65:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Thread 2 blocking on thread 1
Thread 2 reported it has started
Unlocking mutex
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/panic/div-by-zero-2.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at 'attempt to divide by zero', $DIR/div-by-zero-2.rs:4:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/run-pass/panic/overflowing-lsh-neg.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at 'attempt to shift left with overflow', $DIR/overflowing-lsh-neg.rs:4:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/run-pass/panic/overflowing-rsh-1.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-1.rs:4:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/run-pass/panic/overflowing-rsh-2.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-2.rs:5:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
6 changes: 6 additions & 0 deletions tests/run-pass/panic/panic1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// rustc-env: RUST_BACKTRACE=1
// compile-flags: -Zmiri-disable-isolation
// normalize-stderr-test ".*/(rust|checkout)/library/" -> "RUSTLIB/"
// normalize-stderr-test "RUSTLIB/(.*):\d+:\d+ "-> "RUSTLIB/$1:LL:COL "
// normalize-stderr-test "::<.*>" -> ""

fn main() {
std::panic!("panicking from libstd");
}
24 changes: 23 additions & 1 deletion tests/run-pass/panic/panic1.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:2:5
thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:8:5
stack backtrace:
0: std::rt::begin_panic
RUSTLIB/std/src/panicking.rs:505:12
1: main
at $DIR/panic1.rs:8:5
2: <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
RUSTLIB/core/src/ops/function.rs:227:5
3: std::rt::lang_start::{closure#0}
RUSTLIB/std/src/rt.rs:66:18
4: std::ops::function::impls::call_once
RUSTLIB/core/src/ops/function.rs:259:13
5: std::panicking::r#try::do_call
RUSTLIB/std/src/panicking.rs:381:40
6: std::panicking::r#try
RUSTLIB/std/src/panicking.rs:345:19
7: std::panic::catch_unwind
RUSTLIB/std/src/panic.rs:382:14
8: std::rt::lang_start_internal
RUSTLIB/std/src/rt.rs:51:25
9: std::rt::lang_start
RUSTLIB/std/src/rt.rs:65:5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this stacktrace ever changes we'll have to adjust quite a few tests... I can see why you asked for a --bless^^

note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
1 change: 1 addition & 0 deletions tests/run-pass/panic/panic2.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at '42-panicking from libstd', $DIR/panic2.rs:2:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/run-pass/panic/panic3.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at 'panicking from libcore', $DIR/panic3.rs:2:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/run-pass/panic/panic4.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at '42-panicking from libcore', $DIR/panic4.rs:2:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/run-pass/transmute_fat2.stderr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', $DIR/transmute_fat2.rs:15:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace