-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #97191 - wesleywiser:main_thread_name, r=ChrisDenton
Call the OS function to set the main thread's name on program init Normally, `Thread::spawn` takes care of setting the thread's name, if one was provided, but since the main thread wasn't created by calling `Thread::spawn`, we need to call that function in `std::rt::init`. This is mainly useful for system tools like debuggers and profilers which might show the thread name to a user. Prior to these changes, gdb and WinDbg would show all thread names except the main thread's name to a user. I've validated that this patch resolves the issue for both debuggers.
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// compile-flags:-g | ||
// We can't set the main thread name on Linux because it renames the process (#97191) | ||
// ignore-linux | ||
// ignore-android | ||
// ignore-dragonfly | ||
// ignore-emscripten | ||
// ignore-freebsd | ||
// ignore-haiku | ||
// ignore-ios | ||
// ignore-netbsd | ||
// ignore-openbsd | ||
// ignore-solaris | ||
// ignore-sgx | ||
// ignore-windows-gnu | ||
|
||
// === GDB TESTS ================================================================================== | ||
// | ||
// gdb-command:run | ||
// | ||
// gdb-command:info threads | ||
// gdb-check: 1 Thread [...] [...] "main" [...] | ||
// gdb-check:* 2 Thread [...] [...] "my new thread" [...] | ||
|
||
// === LLDB TESTS ================================================================================= | ||
// | ||
// lldb-command:run | ||
// | ||
// lldb-command:thread info 1 | ||
// lldb-check:thread #1:[...]name = 'main'[...] | ||
// lldb-command:thread info 2 | ||
// lldb-check:thread #2:[...]name = 'my new thread'[...] | ||
|
||
// === CDB TESTS ================================================================================== | ||
// | ||
// cdb-command:g | ||
// | ||
// cdb-command:~ | ||
// cdb-check: 0 Id: [...] Suspend: 1 Teb: [...] Unfrozen "main" | ||
// cdb-check:. [...] Id: [...] Suspend: 1 Teb: [...] Unfrozen "my new thread" | ||
|
||
use std::thread; | ||
|
||
fn main() { | ||
let handle = thread::Builder::new().name("my new thread".into()).spawn(|| { | ||
zzz(); // #break | ||
}).unwrap(); | ||
|
||
handle.join().unwrap(); | ||
} | ||
|
||
fn zzz() {} |