-
Notifications
You must be signed in to change notification settings - Fork 352
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
Allow backtraces to cross thread boundaries #4093
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -588,6 +588,36 @@ pub fn report_msg<'tcx>( | |
} | ||
} | ||
|
||
// Traverse thread spawns to display thread backtraces up to main thread | ||
if let Some(mut thread) = thread { | ||
let mut thread_spawn_context = machine.threads.get_thread_spawn_context(thread); | ||
|
||
while let Some((spawning_thread, thread_spawn_backtrace)) = thread_spawn_context { | ||
err.note(format!( | ||
"thread `{}` was spawned by thread `{}`", | ||
machine.threads.get_thread_display_name(thread), | ||
machine.threads.get_thread_display_name(*spawning_thread) | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)); | ||
let (pruned_stacktrace, _was_pruned) = | ||
prune_stacktrace(thread_spawn_backtrace.to_vec(), machine); | ||
|
||
for (idx, frame_info) in pruned_stacktrace.iter().enumerate() { | ||
let is_local = machine.is_local(frame_info); | ||
// No span for non-local frames except the first frame (which is the error site). | ||
if is_local && idx > 0 { | ||
err.subdiagnostic(frame_info.as_note(machine.tcx)); | ||
Comment on lines
+606
to
+608
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is not right, the first frame is not the error site. |
||
} else { | ||
let sm = sess.source_map(); | ||
let span = sm.span_to_embeddable_string(frame_info.span); | ||
err.note(format!("{frame_info} at {span}")); | ||
} | ||
} | ||
Comment on lines
+604
to
+614
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicating existing logic. Can you move this into a shared helper fn? |
||
|
||
thread = *spawning_thread; | ||
thread_spawn_context = machine.threads.get_thread_spawn_context(thread); | ||
} | ||
} | ||
|
||
err.emit(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,19 @@ LL | assert_eq!(libc::pthread_mutex_lock(lock_copy.0.get() as *mut _ | |
| | ||
= note: BACKTRACE on thread `unnamed-ID`: | ||
= note: inside closure at tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC | ||
= note: thread `unnamed-ID` was spawned by thread `main` | ||
= note: inside `std::sys::pal::PLATFORM::thread::Thread::new` at RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC | ||
= note: inside `std::thread::Builder::spawn_unchecked_::<'_, {closure@tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC}, ()>` at RUSTLIB/std/src/thread/mod.rs:LL:CC | ||
= note: inside `std::thread::Builder::spawn_unchecked::<{closure@tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC}, ()>` at RUSTLIB/std/src/thread/mod.rs:LL:CC | ||
= note: inside `std::thread::Builder::spawn::<{closure@tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC}, ()>` at RUSTLIB/std/src/thread/mod.rs:LL:CC | ||
= note: inside `std::thread::spawn::<{closure@tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC}, ()>` at RUSTLIB/std/src/thread/mod.rs:LL:CC | ||
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not pretty to show this for every backtrace. We spent a bunch of effort making backtraces nice, i.e. they usually stop at I could imagine two options:
I am leaning towards the first option since the second option might prune too much when the thread is spawned deep inside some other library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have posted rust-lang/rust#134560 to add the |
||
note: inside `main` | ||
--> tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.rs:LL:CC | ||
| | ||
LL | / thread::spawn(move || { | ||
LL | | assert_eq!(libc::pthread_mutex_lock(lock_copy.0.get() as *mut _), 0); | ||
LL | | }) | ||
| |__________^ | ||
|
||
error: deadlock: the evaluated program deadlocked | ||
--> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.