@@ -235,6 +235,9 @@ pub struct Thread<'tcx> {
235
235
/// The join status.
236
236
join_status : ThreadJoinStatus ,
237
237
238
+ // ThreadId that spawned this thread and backtrace to where this thread was spawned
239
+ thread_spawn_context : Option < ( ThreadId , Vec < FrameInfo < ' tcx > > ) > ,
240
+
238
241
/// Stack of active panic payloads for the current thread. Used for storing
239
242
/// the argument of the call to `miri_start_unwind` (the panic payload) when unwinding.
240
243
/// This is pointer-sized, and matches the `Payload` type in `src/libpanic_unwind/miri.rs`.
@@ -321,13 +324,18 @@ impl<'tcx> std::fmt::Debug for Thread<'tcx> {
321
324
}
322
325
323
326
impl < ' tcx > Thread < ' tcx > {
324
- fn new ( name : Option < & str > , on_stack_empty : Option < StackEmptyCallback < ' tcx > > ) -> Self {
327
+ fn new (
328
+ name : Option < & str > ,
329
+ on_stack_empty : Option < StackEmptyCallback < ' tcx > > ,
330
+ thread_spawn_context : Option < ( ThreadId , Vec < FrameInfo < ' tcx > > ) > ,
331
+ ) -> Self {
325
332
Self {
326
333
state : ThreadState :: Enabled ,
327
334
thread_name : name. map ( |name| Vec :: from ( name. as_bytes ( ) ) ) ,
328
335
stack : Vec :: new ( ) ,
329
336
top_user_relevant_frame : None ,
330
337
join_status : ThreadJoinStatus :: Joinable ,
338
+ thread_spawn_context,
331
339
panic_payloads : Vec :: new ( ) ,
332
340
last_error : None ,
333
341
on_stack_empty,
@@ -345,6 +353,7 @@ impl VisitProvenance for Thread<'_> {
345
353
state : _,
346
354
thread_name : _,
347
355
join_status : _,
356
+ thread_spawn_context : _,
348
357
on_stack_empty : _, // we assume the closure captures no GC-relevant state
349
358
} = self ;
350
359
@@ -475,7 +484,7 @@ impl<'tcx> Default for ThreadManager<'tcx> {
475
484
fn default ( ) -> Self {
476
485
let mut threads = IndexVec :: new ( ) ;
477
486
// Create the main thread and add it to the list of threads.
478
- threads. push ( Thread :: new ( Some ( "main" ) , None ) ) ;
487
+ threads. push ( Thread :: new ( Some ( "main" ) , None , None ) ) ;
479
488
Self {
480
489
active_thread : ThreadId :: MAIN_THREAD ,
481
490
threads,
@@ -542,9 +551,13 @@ impl<'tcx> ThreadManager<'tcx> {
542
551
}
543
552
544
553
/// Create a new thread and returns its id.
545
- fn create_thread ( & mut self , on_stack_empty : StackEmptyCallback < ' tcx > ) -> ThreadId {
554
+ fn create_thread (
555
+ & mut self ,
556
+ on_stack_empty : StackEmptyCallback < ' tcx > ,
557
+ thread_spawn_context : Option < ( ThreadId , Vec < FrameInfo < ' tcx > > ) > ,
558
+ ) -> ThreadId {
546
559
let new_thread_id = ThreadId :: new ( self . threads . len ( ) ) ;
547
- self . threads . push ( Thread :: new ( None , Some ( on_stack_empty) ) ) ;
560
+ self . threads . push ( Thread :: new ( None , Some ( on_stack_empty) , thread_spawn_context ) ) ;
548
561
new_thread_id
549
562
}
550
563
@@ -711,6 +724,13 @@ impl<'tcx> ThreadManager<'tcx> {
711
724
self . threads [ thread] . thread_display_name ( thread)
712
725
}
713
726
727
+ pub fn get_thread_spawn_context (
728
+ & self ,
729
+ thread : ThreadId ,
730
+ ) -> Option < & ( ThreadId , Vec < FrameInfo < ' tcx > > ) > {
731
+ self . threads [ thread] . thread_spawn_context . as_ref ( )
732
+ }
733
+
714
734
/// Put the thread into the blocked state.
715
735
fn block_thread (
716
736
& mut self ,
@@ -924,10 +944,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
924
944
let this = self . eval_context_mut ( ) ;
925
945
926
946
// Create the new thread
927
- let new_thread_id = this. machine . threads . create_thread ( {
928
- let mut state = tls:: TlsDtorsState :: default ( ) ;
929
- Box :: new ( move |m| state. on_stack_empty ( m) )
930
- } ) ;
947
+ let new_thread_id = this. machine . threads . create_thread (
948
+ {
949
+ let mut state = tls:: TlsDtorsState :: default ( ) ;
950
+ Box :: new ( move |m| state. on_stack_empty ( m) )
951
+ } ,
952
+ Some ( ( this. machine . threads . active_thread ( ) , this. generate_stacktrace ( ) ) ) ,
953
+ ) ;
931
954
let current_span = this. machine . current_span ( ) ;
932
955
if let Some ( data_race) = & mut this. machine . data_race {
933
956
data_race. thread_created ( & this. machine . threads , new_thread_id, current_span) ;
0 commit comments