@@ -160,9 +160,18 @@ pub type StackEmptyCallback<'mir, 'tcx> =
160160 Box < dyn FnMut ( & mut MiriInterpCx < ' mir , ' tcx > ) -> InterpResult < ' tcx , Poll < ( ) > > > ;
161161
162162impl < ' mir , ' tcx > Thread < ' mir , ' tcx > {
163- /// Get the name of the current thread, or `<unnamed>` if it was not set.
164- fn thread_name ( & self ) -> & [ u8 ] {
165- if let Some ( ref thread_name) = self . thread_name { thread_name } else { b"<unnamed>" }
163+ /// Get the name of the current thread if it was set.
164+ fn thread_name ( & self ) -> Option < & [ u8 ] > {
165+ self . thread_name . as_deref ( )
166+ }
167+
168+ /// Get the name of the current thread for display purposes; will include thread ID if not set.
169+ fn thread_display_name ( & self , id : ThreadId ) -> String {
170+ if let Some ( ref thread_name) = self . thread_name {
171+ String :: from_utf8_lossy ( thread_name) . into_owned ( )
172+ } else {
173+ format ! ( "unnamed-{}" , id. index( ) )
174+ }
166175 }
167176
168177 /// Return the top user-relevant frame, if there is one.
@@ -205,7 +214,7 @@ impl<'mir, 'tcx> std::fmt::Debug for Thread<'mir, 'tcx> {
205214 write ! (
206215 f,
207216 "{}({:?}, {:?})" ,
208- String :: from_utf8_lossy( self . thread_name( ) ) ,
217+ String :: from_utf8_lossy( self . thread_name( ) . unwrap_or ( b"<unnamed>" ) ) ,
209218 self . state,
210219 self . join_status
211220 )
@@ -572,10 +581,14 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
572581 }
573582
574583 /// Get the name of the given thread.
575- pub fn get_thread_name ( & self , thread : ThreadId ) -> & [ u8 ] {
584+ pub fn get_thread_name ( & self , thread : ThreadId ) -> Option < & [ u8 ] > {
576585 self . threads [ thread] . thread_name ( )
577586 }
578587
588+ pub fn get_thread_display_name ( & self , thread : ThreadId ) -> String {
589+ self . threads [ thread] . thread_display_name ( thread)
590+ }
591+
579592 /// Put the thread into the blocked state.
580593 fn block_thread ( & mut self , thread : ThreadId ) {
581594 let state = & mut self . threads [ thread] . state ;
@@ -980,7 +993,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
980993 }
981994
982995 #[ inline]
983- fn get_thread_name < ' c > ( & ' c self , thread : ThreadId ) -> & ' c [ u8 ]
996+ fn get_thread_name < ' c > ( & ' c self , thread : ThreadId ) -> Option < & [ u8 ] >
984997 where
985998 ' mir : ' c ,
986999 {
0 commit comments