about summary refs log tree commit diff
path: root/src/test/debuginfo
diff options
context:
space:
mode:
authorWesley Wiser <wesleywiser@microsoft.com>2022-05-19 17:21:20 -0400
committerWesley Wiser <wesleywiser@microsoft.com>2022-05-27 10:39:54 -0400
commit820ffc8d7ad9741a078634a42f14ea373d565467 (patch)
tree15296c74ee21f2b411a186b6acff5aa81838668c /src/test/debuginfo
parentc0672870491e84362f76ddecd50fa229f9b06dff (diff)
downloadrust-820ffc8d7ad9741a078634a42f14ea373d565467.tar.gz
rust-820ffc8d7ad9741a078634a42f14ea373d565467.zip
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.
Diffstat (limited to 'src/test/debuginfo')
-rw-r--r--src/test/debuginfo/thread-names.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/debuginfo/thread-names.rs b/src/test/debuginfo/thread-names.rs
new file mode 100644
index 00000000000..f42a7aec3bd
--- /dev/null
+++ b/src/test/debuginfo/thread-names.rs
@@ -0,0 +1,40 @@
+// compile-flags:-g
+// We can't set the main thread name on Linux because it renames the process (#97191)
+// ignore-linux
+
+// === 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() {}