From 289fe36d373c5a13fa7f1b93f39ff88425ab2351 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 11 Sep 2023 00:59:31 -0400 Subject: Print thread ID in panic message if thread name is unknown `panic!` does not print any identifying information for threads that are unnamed. However, in many cases, the thread ID can be determined. This changes the panic message from something like this: thread '' panicked at src/main.rs:3:5: explicit panic To something like this: thread '' (0xff9bf) panicked at src/main.rs:3:5: explicit panic Stack overflow messages are updated as well. This change applies to both named and unnamed threads. The ID printed is the OS integer thread ID rather than the Rust thread ID, which should also be what debuggers print. --- library/std/src/sys/pal/unix/stack_overflow.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'library/std/src/sys/pal/unix/stack_overflow.rs') diff --git a/library/std/src/sys/pal/unix/stack_overflow.rs b/library/std/src/sys/pal/unix/stack_overflow.rs index d89100e6919..0d2100d66bc 100644 --- a/library/std/src/sys/pal/unix/stack_overflow.rs +++ b/library/std/src/sys/pal/unix/stack_overflow.rs @@ -119,7 +119,8 @@ mod imp { && thread_info.guard_page_range.contains(&fault_addr) { let name = thread_info.thread_name.as_deref().unwrap_or(""); - rtprintpanic!("\nthread '{name}' has overflowed its stack\n"); + let tid = crate::thread::current_os_id(); + rtprintpanic!("\nthread '{name}' ({tid}) has overflowed its stack\n"); rtabort!("stack overflow"); } }) @@ -696,7 +697,8 @@ mod imp { if code == c::EXCEPTION_STACK_OVERFLOW { crate::thread::with_current_name(|name| { let name = name.unwrap_or(""); - rtprintpanic!("\nthread '{name}' has overflowed its stack\n"); + let tid = crate::thread::current_os_id(); + rtprintpanic!("\nthread '{name}' ({tid}) has overflowed its stack\n"); }); } c::EXCEPTION_CONTINUE_SEARCH -- cgit 1.4.1-3-g733a5