From: Tom Tromey Date: Sun, 12 Jan 2025 00:57:28 +0000 (-0700) Subject: Mention gdb thread ID in thread messages X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f99be06dbd698fdfd6c6b8f22128c187057b6d91;p=thirdparty%2Fbinutils-gdb.git Mention gdb thread ID in thread messages Currently the "new thread" message that gdb might print does not include gdb's own thread ID -- so, if you want to reference the thread, you must first use "thread find" or "info threads". This patch changes the announcement to mention the thread. The thread-exit message is also updated. I chose to have it display like this: [New Thread 0x7ffff7cbe6c0 (LWP 1267702) (id 2)] [Thread 0x7ffff6cbd6c0 (LWP 1267703) (id 3) exited] ... with the 'id' coming later, because it's somewhat of a pain to wedge the thread id just after the "thread" string where (IMO) it would more naturally belong. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19584 --- diff --git a/gdb/testsuite/gdb.threads/infcall-thread-announce.exp b/gdb/testsuite/gdb.threads/infcall-thread-announce.exp index dc2c5197a09..17f233a099c 100644 --- a/gdb/testsuite/gdb.threads/infcall-thread-announce.exp +++ b/gdb/testsuite/gdb.threads/infcall-thread-announce.exp @@ -55,7 +55,7 @@ with_test_prefix "starting threads" { with_test_prefix "stopping threads" { gdb_test "call (void) stop_thread()" \ - "\\\[Thread \[^\r\n\]+ exited\\\]" \ + "\\\[Thread \[^\r\n\]+ \\\(id $decimal\\\) exited\\\]" \ "stop a thread, return value discarded" check_thread_count -1 diff --git a/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp b/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp index 4ae7ec17a3b..ae3bcee0bee 100644 --- a/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp +++ b/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp @@ -37,7 +37,7 @@ gdb_continue_to_breakpoint "prethreadcreationmarker" set after_new_thread_message "created new thread" foreach_with_prefix thread {5 4 3} { gdb_test_multiple "continue" "${after_new_thread_message}" { - -re "\\\[New Thread ${hex} \\\(LWP \[0-9\]+\\\)\\\].*${gdb_prompt}" { + -re "\\\[New Thread ${hex} \\\(LWP \[0-9\]+\\\) \\\(id $decimal\\\)\\\].*${gdb_prompt}" { pass "${after_new_thread_message}" } -re -wrap "\\\[New Thread $decimal\\.$decimal\\\]\r\n.*" { diff --git a/gdb/thread.c b/gdb/thread.c index 98228fc144c..0788bea235a 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -203,12 +203,14 @@ notify_thread_exited (thread_info *t, std::optional exit_code, if (!silent && print_thread_events) { if (exit_code.has_value ()) - gdb_printf (_("[%s exited with code %s]\n"), + gdb_printf (_("[%s (id %s) exited with code %s]\n"), target_pid_to_str (t->ptid).c_str (), + print_thread_id (t), pulongest (*exit_code)); else - gdb_printf (_("[%s exited]\n"), - target_pid_to_str (t->ptid).c_str ()); + gdb_printf (_("[%s (id %s) exited]\n"), + target_pid_to_str (t->ptid).c_str (), + print_thread_id (t)); } interps_notify_thread_exited (t, exit_code, silent); @@ -329,7 +331,8 @@ add_thread_with_info (process_stratum_target *targ, ptid_t ptid, result->priv = std::move (priv); if (print_thread_events) - gdb_printf (_("[New %s]\n"), target_pid_to_str (ptid).c_str ()); + gdb_printf (_("[New %s (id %s)]\n"), target_pid_to_str (ptid).c_str (), + print_thread_id (result)); annotate_new_thread (); return result;