Skip to content

Commit 04eacd0

Browse files
committed
document -Zmiri-backtrace; dont print backtrace when there's only one frame
1 parent 7e0783f commit 04eacd0

File tree

460 files changed

+32
-991
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

460 files changed

+32
-991
lines changed

src/tools/miri/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ Try running `cargo miri clean`.
292292
Miri adds its own set of `-Z` flags, which are usually set via the `MIRIFLAGS`
293293
environment variable. We first document the most relevant and most commonly used flags:
294294

295+
* `-Zmiri-backtrace=<0|1|full>` configures how Miri prints backtraces: `1` is the default,
296+
where backtraces are printed in pruned form; `full` prints backtraces without pruning, and `0`
297+
disables backtraces entirely.
295298
* `-Zmiri-deterministic-concurrency` makes Miri's concurrency-related behavior fully deterministic.
296299
Strictly speaking, Miri is always fully deterministic when isolation is enabled (the default
297300
mode), but this determinism is achieved by using an RNG with a fixed seed. Seemingly harmless

src/tools/miri/src/diagnostics.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -604,28 +604,30 @@ pub fn report_msg<'tcx>(
604604
}
605605

606606
// Add backtrace
607-
let mut backtrace_title = String::from("BACKTRACE");
608-
if extra_span {
609-
write!(backtrace_title, " (of the first span)").unwrap();
610-
}
611-
if let Some(thread) = thread {
612-
let thread_name = machine.threads.get_thread_display_name(thread);
613-
if thread_name != "main" {
614-
// Only print thread name if it is not `main`.
615-
write!(backtrace_title, " on thread `{thread_name}`").unwrap();
616-
};
617-
}
618-
write!(backtrace_title, ":").unwrap();
619-
err.note(backtrace_title);
620-
for (idx, frame_info) in stacktrace.iter().enumerate() {
621-
let is_local = machine.is_local(frame_info);
622-
// No span for non-local frames and the first frame (which is the error site).
623-
if is_local && idx > 0 {
624-
err.subdiagnostic(frame_info.as_note(machine.tcx));
625-
} else {
626-
let sm = sess.source_map();
627-
let span = sm.span_to_embeddable_string(frame_info.span);
628-
err.note(format!("{frame_info} at {span}"));
607+
if stacktrace.len() > 1 {
608+
let mut backtrace_title = String::from("BACKTRACE");
609+
if extra_span {
610+
write!(backtrace_title, " (of the first span)").unwrap();
611+
}
612+
if let Some(thread) = thread {
613+
let thread_name = machine.threads.get_thread_display_name(thread);
614+
if thread_name != "main" {
615+
// Only print thread name if it is not `main`.
616+
write!(backtrace_title, " on thread `{thread_name}`").unwrap();
617+
};
618+
}
619+
write!(backtrace_title, ":").unwrap();
620+
err.note(backtrace_title);
621+
for (idx, frame_info) in stacktrace.iter().enumerate() {
622+
let is_local = machine.is_local(frame_info);
623+
// No span for non-local frames and the first frame (which is the error site).
624+
if is_local && idx > 0 {
625+
err.subdiagnostic(frame_info.as_note(machine.tcx));
626+
} else {
627+
let sm = sess.source_map();
628+
let span = sm.span_to_embeddable_string(frame_info.span);
629+
err.note(format!("{frame_info} at {span}"));
630+
}
629631
}
630632
}
631633

src/tools/miri/tests/fail-dep/concurrency/apple_os_unfair_lock_assert_not_owner.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: abnormal termination: called os_unfair_lock_assert_not_owner on an os_unf
33
|
44
LL | libc::os_unfair_lock_assert_not_owner(lock.get());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
6-
|
7-
= note: BACKTRACE:
8-
= note: inside `main` at tests/fail-dep/concurrency/apple_os_unfair_lock_assert_not_owner.rs:LL:CC
96

107
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
118

src/tools/miri/tests/fail-dep/concurrency/apple_os_unfair_lock_assert_owner.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: abnormal termination: called os_unfair_lock_assert_owner on an os_unfair_
33
|
44
LL | libc::os_unfair_lock_assert_owner(lock.get());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
6-
|
7-
= note: BACKTRACE:
8-
= note: inside `main` at tests/fail-dep/concurrency/apple_os_unfair_lock_assert_owner.rs:LL:CC
96

107
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
118

src/tools/miri/tests/fail-dep/concurrency/apple_os_unfair_lock_move_deadlock.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: the evaluated program deadlocked
33
|
44
LL | unsafe { libc::os_unfair_lock_lock(lock.get()) };
55
| ^ this thread got stuck here
6-
|
7-
= note: BACKTRACE:
8-
= note: inside `main` at tests/fail-dep/concurrency/apple_os_unfair_lock_move_deadlock.rs:LL:CC
96

107
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
118

src/tools/miri/tests/fail-dep/concurrency/apple_os_unfair_lock_reentrant.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: abnormal termination: attempted to lock an os_unfair_lock that is already
33
|
44
LL | libc::os_unfair_lock_lock(lock.get());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
6-
|
7-
= note: BACKTRACE:
8-
= note: inside `main` at tests/fail-dep/concurrency/apple_os_unfair_lock_reentrant.rs:LL:CC
96

107
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
118

src/tools/miri/tests/fail-dep/concurrency/apple_os_unfair_lock_unowned.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: abnormal termination: attempted to unlock an os_unfair_lock not owned by
33
|
44
LL | libc::os_unfair_lock_unlock(lock.get());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
6-
|
7-
= note: BACKTRACE:
8-
= note: inside `main` at tests/fail-dep/concurrency/apple_os_unfair_lock_unowned.rs:LL:CC
96

107
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
118

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_cond_double_destroy.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | libc::pthread_cond_destroy(cond.as_mut_ptr());
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: BACKTRACE:
10-
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_cond_double_destroy.rs:LL:CC
119

1210
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
1311
ALLOC DUMP

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_condattr_double_destroy.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | libc::pthread_condattr_destroy(attr.as_mut_ptr());
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9-
= note: BACKTRACE:
10-
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_condattr_double_destroy.rs:LL:CC
119

1210
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
1311
ALLOC DUMP

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_create_too_few_args.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ error: Undefined Behavior: calling a function with more arguments than it expect
44
= note: (no span available)
55
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
66
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
7-
= note: BACKTRACE on thread `unnamed-ID`:
87

98
error: aborting due to 1 previous error
109

0 commit comments

Comments
 (0)