Print thread name in thread apply headers

Message ID 20150820191033.GD2251@work-vm
State New, archived
Headers

Commit Message

Dr. David Alan Gilbert Aug. 20, 2015, 7:10 p.m. UTC
  The thread name is currently shown in 'info thread' but not in
thread apply.  Adding it to thread apply makes it easier to figure out
what's happening in backtraces of multithreaded programs gathered with
a  'thread apply all bt full'.

gdb/ChangeLog:

	* thread.c: Add thread name to thread apply headers.
---
 gdb/thread.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
  

Patch

diff --git a/gdb/thread.c b/gdb/thread.c
index 4dde722..257e082 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1640,10 +1640,17 @@  thread_apply_all_command (char *cmd, int from_tty)
       for (k = 0; k != i; k++)
         if (thread_alive (tp_array[k]))
           {
-            switch_to_thread (tp_array[k]->ptid);
-            printf_filtered (_("\nThread %d (%s):\n"), 
-			     tp_array[k]->num,
-			     target_pid_to_str (inferior_ptid));
+            const char *name;
+
+            tp = tp_array[k];
+            switch_to_thread (tp->ptid);
+
+            name = tp->name ? tp->name : target_thread_name (tp);
+
+            printf_filtered (_("\nThread %d (%s/'%s'):\n"),
+			     tp->num,
+			     target_pid_to_str (inferior_ptid),
+			     name ? name : "");
             execute_command (cmd, from_tty);
 
             /* Restore exact command used previously.  */
@@ -1693,10 +1700,15 @@  thread_apply_command (char *tidlist, int from_tty)
 	warning (_("Thread %d has terminated."), start);
       else
 	{
+	  const char *name;
+
 	  switch_to_thread (tp->ptid);
 
-	  printf_filtered (_("\nThread %d (%s):\n"), tp->num,
-			   target_pid_to_str (inferior_ptid));
+	  name = tp->name ? tp->name : target_thread_name (tp);
+
+	  printf_filtered (_("\nThread %d (%s/'%s'):\n"), tp->num,
+			   target_pid_to_str (inferior_ptid),
+			   name ? name : "");
 	  execute_command (cmd, from_tty);
 
 	  /* Restore exact command used previously.  */