File tree 3 files changed +55
-1
lines changed
3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 1
1
#![ allow( missing_docs, nonstandard_style) ]
2
2
3
+ use crate :: ffi:: CStr ;
3
4
use crate :: io:: ErrorKind ;
4
5
5
6
pub use self :: rand:: hashmap_random_keys;
@@ -66,6 +67,15 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
66
67
stack_overflow:: init ( ) ;
67
68
args:: init ( argc, argv) ;
68
69
70
+ // Normally, `thread::spawn` will call `Thread::set_name` but since this thread
71
+ // already exists, we have to call it ourselves. We only do this on macos
72
+ // because some unix-like operating systems such as Linux share process-id and
73
+ // thread-id for the main thread and so renaming the main thread will rename the
74
+ // process and we only want to enable this on platforms we've tested.
75
+ if cfg ! ( target_os = "macos" ) {
76
+ thread:: Thread :: set_name ( & CStr :: from_bytes_with_nul_unchecked ( b"main\0 " ) ) ;
77
+ }
78
+
69
79
unsafe fn sanitize_standard_fds ( ) {
70
80
#[ cfg( not( miri) ) ]
71
81
// The standard fds are always available in Miri.
Original file line number Diff line number Diff line change 1
1
#![ allow( missing_docs, nonstandard_style) ]
2
2
3
- use crate :: ffi:: { OsStr , OsString } ;
3
+ use crate :: ffi:: { CStr , OsStr , OsString } ;
4
4
use crate :: io:: ErrorKind ;
5
5
use crate :: os:: windows:: ffi:: { OsStrExt , OsStringExt } ;
6
6
use crate :: path:: PathBuf ;
@@ -49,6 +49,10 @@ cfg_if::cfg_if! {
49
49
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
50
50
pub unsafe fn init ( _argc : isize , _argv : * const * const u8 ) {
51
51
stack_overflow:: init ( ) ;
52
+
53
+ // Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
54
+ // exists, we have to call it ourselves.
55
+ thread:: Thread :: set_name ( & CStr :: from_bytes_with_nul_unchecked ( b"main\0 " ) ) ;
52
56
}
53
57
54
58
// SAFETY: must be called only once during runtime cleanup.
Original file line number Diff line number Diff line change
1
+ // compile-flags:-g
2
+ // We can't set the main thread name on Linux because it renames the process (#97191)
3
+ // ignore-linux
4
+
5
+ // === GDB TESTS ==================================================================================
6
+ //
7
+ // gdb-command:run
8
+ //
9
+ // gdb-command:info threads
10
+ // gdb-check: 1 Thread [...] [...] "main" [...]
11
+ // gdb-check:* 2 Thread [...] [...] "my new thread" [...]
12
+
13
+ // === LLDB TESTS =================================================================================
14
+ //
15
+ // lldb-command:run
16
+ //
17
+ // lldb-command:thread info 1
18
+ // lldb-check:thread #1:[...]name = 'main'[...]
19
+ // lldb-command:thread info 2
20
+ // lldb-check:thread #2:[...]name = 'my new thread'[...]
21
+
22
+ // === CDB TESTS ==================================================================================
23
+ //
24
+ // cdb-command:g
25
+ //
26
+ // cdb-command:~
27
+ // cdb-check: 0 Id: [...] Suspend: 1 Teb: [...] Unfrozen "main"
28
+ // cdb-check:. [...] Id: [...] Suspend: 1 Teb: [...] Unfrozen "my new thread"
29
+
30
+ use std:: thread;
31
+
32
+ fn main ( ) {
33
+ let handle = thread:: Builder :: new ( ) . name ( "my new thread" . into ( ) ) . spawn ( || {
34
+ zzz ( ) ; // #break
35
+ } ) . unwrap ( ) ;
36
+
37
+ handle. join ( ) . unwrap ( ) ;
38
+ }
39
+
40
+ fn zzz ( ) { }
You can’t perform that action at this time.
0 commit comments