-
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?
Allow backtraces to cross thread boundaries #4093
Conversation
You'll need to bless the windows tests, too. It should suffice to pass |
I have some nits. |
@@ -235,6 +235,9 @@ pub struct Thread<'tcx> { | |||
/// The join status. | |||
join_status: ThreadJoinStatus, | |||
|
|||
// ThreadId that spawned this thread and backtrace to where this thread was spawned |
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.
// ThreadId that spawned this thread and backtrace to where this thread was spawned | |
/// ThreadId that spawned this thread and backtrace to where this thread was spawned. |
// 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)); |
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.
This comment is not right, the first frame is not the error site.
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)); | ||
} else { | ||
let sm = sess.source_map(); | ||
let span = sm.span_to_embeddable_string(frame_info.span); | ||
err.note(format!("{frame_info} at {span}")); | ||
} | ||
} |
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.
This is duplicating existing logic. Can you move this into a shared helper fn?
= 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 |
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.
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 main
and don't go all the way to the start lang item. We should do something similar here to avoid drowning the user in noise.
I could imagine two options:
- we mark these frames as
#[caller_location]
in std (we have done this for a bunch of other functions to make backtraces prettier) - when pruning the stack for another thread, we also remove all non-local frames at the top
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I have posted rust-lang/rust#134560 to add the #[caller_location]
for this.
@rustbot author |
mri: add track_caller to thread spawning methods for better backtraces This is in preparation for rust-lang/miri#4093
mri: add track_caller to thread spawning methods for better backtraces This is in preparation for rust-lang/miri#4093
Rollup merge of rust-lang#134560 - RalfJung:miri-thread-spawn, r=jhpratt mri: add track_caller to thread spawning methods for better backtraces This is in preparation for rust-lang/miri#4093
Fixes #4066
When a thread is spawned we store the ID of the spawning thread as well as a backtrace to the spawn location. When there's an error we can traverse upwards, displaying a backtrace up to the main thread.
For instance, with the following program:
Whereas previously we would see:
We now have: