@@ -160,9 +160,18 @@ pub type StackEmptyCallback<'mir, 'tcx> =
160
160
Box < dyn FnMut ( & mut MiriInterpCx < ' mir , ' tcx > ) -> InterpResult < ' tcx , Poll < ( ) > > > ;
161
161
162
162
impl < ' 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
+ }
166
175
}
167
176
168
177
/// Return the top user-relevant frame, if there is one.
@@ -205,7 +214,7 @@ impl<'mir, 'tcx> std::fmt::Debug for Thread<'mir, 'tcx> {
205
214
write ! (
206
215
f,
207
216
"{}({:?}, {:?})" ,
208
- String :: from_utf8_lossy( self . thread_name( ) ) ,
217
+ String :: from_utf8_lossy( self . thread_name( ) . unwrap_or ( b"<unnamed>" ) ) ,
209
218
self . state,
210
219
self . join_status
211
220
)
@@ -572,10 +581,14 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
572
581
}
573
582
574
583
/// 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 ] > {
576
585
self . threads [ thread] . thread_name ( )
577
586
}
578
587
588
+ pub fn get_thread_display_name ( & self , thread : ThreadId ) -> String {
589
+ self . threads [ thread] . thread_display_name ( thread)
590
+ }
591
+
579
592
/// Put the thread into the blocked state.
580
593
fn block_thread ( & mut self , thread : ThreadId ) {
581
594
let state = & mut self . threads [ thread] . state ;
@@ -980,7 +993,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
980
993
}
981
994
982
995
#[ 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 ] >
984
997
where
985
998
' mir : ' c ,
986
999
{
0 commit comments