Skip to content

Commit c82b572

Browse files
committed
fix deadlock error showing 'no span available' nonsense backtraces
1 parent a8b14ee commit c82b572

14 files changed

+24
-93
lines changed

src/tools/miri/src/concurrency/thread.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,13 @@ impl<'tcx> ThreadManager<'tcx> {
515515
&mut self.threads[self.active_thread].stack
516516
}
517517

518-
pub fn all_stacks(
518+
pub fn all_blocked_stacks(
519519
&self,
520520
) -> impl Iterator<Item = (ThreadId, &[Frame<'tcx, Provenance, FrameExtra<'tcx>>])> {
521-
self.threads.iter_enumerated().map(|(id, t)| (id, &t.stack[..]))
521+
self.threads
522+
.iter_enumerated()
523+
.filter(|(_id, t)| matches!(t.state, ThreadState::Blocked { .. }))
524+
.map(|(id, t)| (id, &t.stack[..]))
522525
}
523526

524527
/// Create a new thread and returns its id.

src/tools/miri/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ pub fn report_result<'tcx>(
469469
eprint!("{extra}"); // newlines are already in the string
470470

471471
if show_all_threads {
472-
for (thread, stack) in ecx.machine.threads.all_stacks() {
472+
for (thread, stack) in ecx.machine.threads.all_blocked_stacks() {
473473
if thread != ecx.active_thread() {
474474
let stacktrace = Frame::generate_stacktrace_from_stack(stack);
475475
let (stacktrace, was_pruned) = prune_stacktrace(stacktrace, &ecx.machine);

src/tools/miri/tests/fail-dep/libc/eventfd_block_read_twice.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@only-target: linux android illumos
2-
//~^ERROR: deadlocked
3-
//~^^ERROR: deadlocked
42
//@compile-flags: -Zmiri-deterministic-concurrency
53
//@error-in-other-file: deadlock
64

src/tools/miri/tests/fail-dep/libc/eventfd_block_read_twice.stderr

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@ note: inside `main`
1414
LL | thread2.join().unwrap();
1515
| ^^^^^^^^^^^^^^
1616

17-
error: the evaluated program deadlocked
18-
|
19-
= note: this thread got stuck here
20-
= note: (no span available)
21-
2217
error: the evaluated program deadlocked
2318
--> tests/fail-dep/libc/eventfd_block_read_twice.rs:LL:CC
2419
|
2520
LL | let res: i64 = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), 8).try_into().unwrap() };
2621
| ^ this thread got stuck here
2722

28-
error: the evaluated program deadlocked
29-
|
30-
= note: this thread got stuck here
31-
= note: (no span available)
32-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
33-
3423
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
3524

36-
error: aborting due to 4 previous errors
25+
error: aborting due to 2 previous errors
3726

src/tools/miri/tests/fail-dep/libc/eventfd_block_write_twice.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@only-target: linux android illumos
2-
//~^ERROR: deadlocked
3-
//~^^ERROR: deadlocked
42
//@compile-flags: -Zmiri-deterministic-concurrency
53
//@error-in-other-file: deadlock
64

@@ -38,7 +36,7 @@ fn main() {
3836

3937
let thread2 = thread::spawn(move || {
4038
let sized_8_data = (u64::MAX - 1).to_ne_bytes();
41-
// Write u64::MAX - 1, so the all subsequent write will block.
39+
// Write u64::MAX - 1, so that all subsequent writes will block.
4240
let res: i64 = unsafe {
4341
// This `write` will initially blocked, then get unblocked by thread3, then get blocked again
4442
// because the `write` in thread1 executes first.

src/tools/miri/tests/fail-dep/libc/eventfd_block_write_twice.stderr

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@ note: inside `main`
1414
LL | thread2.join().unwrap();
1515
| ^^^^^^^^^^^^^^
1616

17-
error: the evaluated program deadlocked
18-
|
19-
= note: this thread got stuck here
20-
= note: (no span available)
21-
2217
error: the evaluated program deadlocked
2318
--> tests/fail-dep/libc/eventfd_block_write_twice.rs:LL:CC
2419
|
2520
LL | libc::write(fd, sized_8_data.as_ptr() as *const libc::c_void, 8).try_into().unwrap()
2621
| ^ this thread got stuck here
2722

28-
error: the evaluated program deadlocked
29-
|
30-
= note: this thread got stuck here
31-
= note: (no span available)
32-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
33-
3423
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
3524

36-
error: aborting due to 4 previous errors
25+
error: aborting due to 2 previous errors
3726

src/tools/miri/tests/fail-dep/libc/libc_epoll_block_two_thread.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//@compile-flags: -Zmiri-deterministic-concurrency
2-
//~^ERROR: deadlocked
3-
//~^^ERROR: deadlocked
42
//@only-target: linux android illumos
53
//@error-in-other-file: deadlock
64

75
use std::convert::TryInto;
8-
use std::thread::spawn;
6+
use std::thread;
97

108
// Using `as` cast since `EPOLLET` wraps around
119
const EPOLL_IN_OUT_ET: u32 = (libc::EPOLLIN | libc::EPOLLOUT | libc::EPOLLET) as _;
@@ -66,22 +64,21 @@ fn main() {
6664

6765
let expected_event = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT).unwrap();
6866
let expected_value = fds[0] as u64;
69-
let thread1 = spawn(move || {
67+
let thread1 = thread::spawn(move || {
7068
check_epoll_wait::<1>(epfd, &[(expected_event, expected_value)], -1);
71-
//~^ERROR: deadlocked
7269
});
73-
let thread2 = spawn(move || {
70+
let thread2 = thread::spawn(move || {
7471
check_epoll_wait::<1>(epfd, &[(expected_event, expected_value)], -1);
72+
//~^ERROR: deadlocked
7573
});
74+
// Yield so the threads are both blocked.
75+
thread::yield_now();
7676

77-
let thread3 = spawn(move || {
78-
// Just a single write, so we only wake up one of them.
79-
let data = "abcde".as_bytes().as_ptr();
80-
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
81-
assert!(res > 0 && res <= 5);
82-
});
77+
// Just a single write, so we only wake up one of them.
78+
let data = "abcde".as_bytes().as_ptr();
79+
let res = unsafe { libc::write(fds[1], data as *const libc::c_void, 5) };
80+
assert!(res > 0 && res <= 5);
8381

8482
thread1.join().unwrap();
8583
thread2.join().unwrap();
86-
thread3.join().unwrap();
8784
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
error: the evaluated program deadlocked
2-
|
3-
= note: this thread got stuck here
4-
= note: (no span available)
5-
61
error: the evaluated program deadlocked
72
--> RUSTLIB/std/src/sys/thread/PLATFORM.rs:LL:CC
83
|
@@ -16,7 +11,7 @@ LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) };
1611
note: inside `main`
1712
--> tests/fail-dep/libc/libc_epoll_block_two_thread.rs:LL:CC
1813
|
19-
LL | thread1.join().unwrap();
14+
LL | thread2.join().unwrap();
2015
| ^^^^^^^^^^^^^^
2116

2217
error: the evaluated program deadlocked
@@ -25,13 +20,7 @@ error: the evaluated program deadlocked
2520
LL | check_epoll_wait::<TAG>(epfd, &[(expected_event, expected_value)], -1);
2621
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this thread got stuck here
2722

28-
error: the evaluated program deadlocked
29-
|
30-
= note: this thread got stuck here
31-
= note: (no span available)
32-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
33-
3423
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
3524

36-
error: aborting due to 4 previous errors
25+
error: aborting due to 2 previous errors
3726

src/tools/miri/tests/fail-dep/libc/socketpair-close-while-blocked.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! This is a regression test for <https://github.com/rust-lang/miri/issues/3947>: we had some
22
//! faulty logic around `release_clock` that led to this code not reporting a data race.
3-
//~^^ERROR: deadlock
43
//@ignore-target: windows # no libc socketpair on Windows
54
//@compile-flags: -Zmiri-deterministic-concurrency
65
//@error-in-other-file: deadlock

src/tools/miri/tests/fail-dep/libc/socketpair-close-while-blocked.stderr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ error: the evaluated program deadlocked
2020
LL | libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t)
2121
| ^ this thread got stuck here
2222

23-
error: the evaluated program deadlocked
24-
|
25-
= note: this thread got stuck here
26-
= note: (no span available)
27-
2823
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
2924

30-
error: aborting due to 3 previous errors
25+
error: aborting due to 2 previous errors
3126

0 commit comments

Comments
 (0)