]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Mention gdb thread ID in thread messages
authorTom Tromey <tom@tromey.com>
Sun, 12 Jan 2025 00:57:28 +0000 (17:57 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 7 Jan 2026 18:33:05 +0000 (11:33 -0700)
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

gdb/testsuite/gdb.threads/infcall-thread-announce.exp
gdb/testsuite/gdb.threads/multiple-successive-infcall.exp
gdb/thread.c

index dc2c5197a09b6576a2fdadd68259bdcf38a0032f..17f233a099cebb20f5206295a753d717aeeddb8a 100644 (file)
@@ -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
 
index 4ae7ec17a3bdff6b5c12fc0a4d0671dc4774db99..ae3bcee0bee599f49051b9164423ca0479f08b59 100644 (file)
@@ -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.*" {
index 98228fc144ca74a733eab0ffe8ed8f7fb234ec1c..0788bea235a61d6566a68616b2bec726fce8a048 100644 (file)
@@ -203,12 +203,14 @@ notify_thread_exited (thread_info *t, std::optional<ULONGEST> 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;