Output the Ada task name in more messages.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 8 Jun 2019 17:47:51 +0000 (19:47 +0200)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 12 Sep 2019 19:57:10 +0000 (21:57 +0200)
With this patch, we e.g. get:
      [Switching to task 2 "task_list(1)"]
      [Current task is 2 "task_list(1)"]
    instead of
      [Switching to task 2]
      [Current task is 2]

The logic to produce the taskno optionally followed
by the task name has been factorized in the task_to_str function.

Task names are output between double quotes in the new messages,
similarly to what GDB does for thread names.
However, no quotes are put around task names in 'info tasks' Name column.
This was discussed with Tom, that preferred no quotes there, while I
was more in favour of visual consistency.
I discussed with a few more users, which led to (exactly) 50% preferring
quotes and 50% preferring no quotes :).
To arrive to the decision to remove the quotes, the following "killing args"
were used:
 * To have quotes or to not have quotes, that is the question; yes
   but not *THE* question :).
 * If there is not a clear majority that prefers quotes, better to
   not disturb the existing user basis for a (somewhat) irrelevant
   aspect.
 * The opinion of the reviewer has more weight.

So, compared to the previous version, this version remotes the quotes
in 'info tasks'.

It improves the alignement of 'info tasks' output.
With this patch, we get:
      (gdb) info task
         ID           TID P-ID Pri State                  Name
      *   1  555555759030       48 Runnable               main_task
          2  555555759e30    1  48 Selective Wait         mit
      (gdb)
   instead of
      (gdb) info task
         ID       TID P-ID Pri State                  Name
      *   1 555555759030       48 Runnable               main_task
          2 555555759e30    1  48 Selective Wait         mit
      (gdb)
(e.g. the first one properly shows parent and priority under the
correct header).

This is version 4 of the 'task name' patch.
Compared to version 3, the changes are:
   output task names between quotes but not in 'info tasks'

gdb/ChangeLog
2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

* NEWS: Announce that Ada task names are now shown at more places,
and between quotes (except in info task output).
* gdb/ada-tasks.c (task_to_str): New function.
(display_current_task_id): Call task_to_str.
(task_command_1): Likewise.
(print_ada_task_info): In non-mi mode, Properly align headers and data
when task-id length is > 9 (9 is the default for a 32 bits CORE_ADDR).

gdb/doc/ChangeLog
2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

* gdb.texinfo (Ada Tasks): Tell the task name is printed, update
examples.

gdb/testsuite/ChangeLog
2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

* gdb.ada/rdv_wait.exp: Update to new task names.
* gdb.base/task_switch_in_core.exp: Likewise.
* gdb.base/info_sources_base.c: Likewise.

gdb/ChangeLog
gdb/NEWS
gdb/ada-tasks.c
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/rdv_wait.exp
gdb/testsuite/gdb.ada/task_switch_in_core.exp

index 6d5f19d04bbf9046c9df418c0824864da03f9d76..986a701c2fa7f864999945f72ebb2aa95d93b9ba 100644 (file)
@@ -1,3 +1,13 @@
+2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+       * NEWS: Announce that Ada task names are now shown at more places,
+       and between quotes (except in info task output).
+       * gdb/ada-tasks.c (task_to_str): New function.
+       (display_current_task_id): Call task_to_str.
+       (task_command_1): Likewise.
+       (print_ada_task_info): In non-mi mode, Properly align headers and data
+       when task-id length is > 9 (9 is the default for a 32 bits CORE_ADDR).
+
 2019-09-12  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * procfs.c (procfs_target::wait) <PR_FAULTED>: Get signal from
index f382e887c0c203ac51765c0f04c81d7011021ed6..d502f08984cd06ed6197d8e21c0aebd369aa6e1d 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -29,6 +29,9 @@
 
 * The RX port now supports XML target descriptions.
 
+* GDB now shows the Ada task names at more places, e.g. in task switching
+  messages.
+
 * Python API
 
   ** The gdb.Value type has a new method 'format_string' which returns a
index 99458aadb2cde3d77d96d41f32861a58f3c453e3..34da786eb7cd8374aef778e1c7ed39a79af282de 100644 (file)
@@ -240,6 +240,18 @@ struct ada_tasks_inferior_data
 static const struct inferior_key<ada_tasks_inferior_data>
   ada_tasks_inferior_data_handle;
 
+/* Return a string with TASKNO followed by the task name if TASK_INFO
+   contains a name.  */
+
+static std::string
+task_to_str (int taskno, const ada_task_info *task_info)
+{
+  if (task_info->name[0] == '\0')
+    return string_printf ("%d", taskno);
+  else
+    return string_printf ("%d \"%s\"", taskno, task_info->name);
+}
+
 /* Return the ada-tasks module's data for the given program space (PSPACE).
    If none is found, add a zero'ed one now.
 
@@ -1047,7 +1059,26 @@ print_ada_task_info (struct ui_out *uiout,
   ui_out_emit_table table_emitter (uiout, nb_columns, nb_tasks, "tasks");
   uiout->table_header (1, ui_left, "current", "");
   uiout->table_header (3, ui_right, "id", "ID");
-  uiout->table_header (9, ui_right, "task-id", "TID");
+  {
+    size_t tid_width = 9;
+    /* Grown below in case the largest entry is bigger.  */
+
+    if (!uiout->is_mi_like_p ())
+      {
+       for (taskno = 1; taskno <= data->task_list.size (); taskno++)
+         {
+           const struct ada_task_info *const task_info
+             = &data->task_list[taskno - 1];
+
+           gdb_assert (task_info != NULL);
+
+           tid_width = std::max (tid_width,
+                                 1 + strlen (phex_nz (task_info->task_id,
+                                                      sizeof (CORE_ADDR))));
+         }
+      }
+    uiout->table_header (tid_width, ui_right, "task-id", "TID");
+  }
   /* The following column is provided in GDB/MI mode only because
      it is only really useful in that mode, and also because it
      allows us to keep the CLI output shorter and more compact.  */
@@ -1129,10 +1160,12 @@ print_ada_task_info (struct ui_out *uiout,
       else
        uiout->field_string ("state", task_states[task_info->state]);
 
-      /* Finally, print the task name.  */
+      /* Finally, print the task name, without quotes around it, as mi like
+        is not expecting quotes, and in non mi-like no need for quotes
+         as there is a specific column for the name.  */
       uiout->field_string ("name",
-                          task_info->name[0] != '\0' ? task_info->name
-                          : _("<no name>"));
+                          task_info->name[0] != '\0' ? task_info->name
+                          : _("<no name>"));
 
       uiout->text ("\n");
     }
@@ -1166,7 +1199,7 @@ info_task (struct ui_out *uiout, const char *taskno_str, struct inferior *inf)
 
   /* Print the name of the task.  */
   if (task_info->name[0] != '\0')
-    printf_filtered (_("Name: %s\n"), task_info->name);
+    printf_filtered (_("Name: \"%s\"\n"), task_info->name);
   else
     printf_filtered (_("<no name>\n"));
 
@@ -1187,7 +1220,7 @@ info_task (struct ui_out *uiout, const char *taskno_str, struct inferior *inf)
 
       printf_filtered (_("Parent: %d"), parent_taskno);
       if (parent->name[0] != '\0')
-        printf_filtered (" (%s)", parent->name);
+        printf_filtered (" (\"%s\")", parent->name);
       printf_filtered ("\n");
     }
   else
@@ -1220,7 +1253,7 @@ info_task (struct ui_out *uiout, const char *taskno_str, struct inferior *inf)
         ada_task_info *target_task_info = &data->task_list[target_taskno - 1];
 
         if (target_task_info->name[0] != '\0')
-          printf_filtered (" (%s)", target_task_info->name);
+          printf_filtered (" (\"%s\")", target_task_info->name);
       }
 
     printf_filtered ("\n");
@@ -1255,7 +1288,14 @@ display_current_task_id (void)
   if (current_task == 0)
     printf_filtered (_("[Current task is unknown]\n"));
   else
-    printf_filtered (_("[Current task is %d]\n"), current_task);
+    {
+      struct ada_tasks_inferior_data *data
+       = get_ada_tasks_inferior_data (current_inferior ());
+      struct ada_task_info *task_info = &data->task_list[current_task - 1];
+
+      printf_filtered (_("[Current task is %s]\n"),
+                      task_to_str (current_task, task_info).c_str ());
+    }
 }
 
 /* Parse and evaluate TIDSTR into a task id, and try to switch to
@@ -1274,7 +1314,8 @@ task_command_1 (const char *taskno_str, int from_tty, struct inferior *inf)
   task_info = &data->task_list[taskno - 1];
 
   if (!ada_task_is_alive (task_info))
-    error (_("Cannot switch to task %d: Task is no longer running"), taskno);
+    error (_("Cannot switch to task %s: Task is no longer running"),
+          task_to_str (taskno, task_info).c_str ());
    
   /* On some platforms, the thread list is not updated until the user
      performs a thread-related operation (by using the "info threads"
@@ -1295,13 +1336,14 @@ task_command_1 (const char *taskno_str, int from_tty, struct inferior *inf)
      it's nicer for the user to just refuse to perform the task switch.  */
   thread_info *tp = find_thread_ptid (task_info->ptid);
   if (tp == NULL)
-    error (_("Unable to compute thread ID for task %d.\n"
+    error (_("Unable to compute thread ID for task %s.\n"
              "Cannot switch to this task."),
-           taskno);
+           task_to_str (taskno, task_info).c_str ());
 
   switch_to_thread (tp);
   ada_find_printable_frame (get_selected_frame (NULL));
-  printf_filtered (_("[Switching to task %d]\n"), taskno);
+  printf_filtered (_("[Switching to task %s]\n"),
+                  task_to_str (taskno, task_info).c_str ());
   print_stack_frame (get_selected_frame (NULL),
                      frame_relative_level (get_selected_frame (NULL)),
                     SRC_AND_LOC, 1);
index 96c040919735d9d709a2118c26cd5fc9f0a3d3aa..4705fbc54103e586858b197b539bae2e33f19cae 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+       * gdb.texinfo (Ada Tasks): Tell the task name is printed, update
+       examples.
+
 2019-09-10  Tom Tromey  <tromey@adacore.com>
 
        * gdb.texinfo (Index Files): Update Ada text.
index 79824a0226a3143401c6d491bc4bdfcd60bcafda..eee0c9d4dd79666f288f6cc796f5b5ee4d27df47 100644 (file)
@@ -17751,10 +17751,10 @@ the following example:
 *  2   807c468    1  15 Runnable               task_1
 (@value{GDBP}) info task 2
 Ada Task: 0x807c468
-Name: task_1
+Name: "task_1"
 Thread: 0
 LWP: 0x1fac
-Parent: 1 (main_task)
+Parent: 1 ("main_task")
 Base Priority: 15
 State: Runnable
 @end smallexample
@@ -17762,7 +17762,7 @@ State: Runnable
 @item task
 @kindex task@r{ (Ada)}
 @cindex current Ada task ID
-This command prints the ID of the current task.
+This command prints the ID and name of the current task.
 
 @smallexample
 @iftex
@@ -17771,9 +17771,9 @@ This command prints the ID of the current task.
 (@value{GDBP}) info tasks
   ID       TID P-ID Pri State                  Name
    1   8077870    0  15 Child Activation Wait  main_task
-*  2   807c458    1  15 Runnable               t
+*  2   807c458    1  15 Runnable               some_task
 (@value{GDBP}) task
-[Current task is 2]
+[Current task is 2 "some_task"]
 @end smallexample
 
 @item task @var{taskno}
@@ -17789,9 +17789,9 @@ from the current task to the given task.
 (@value{GDBP}) info tasks
   ID       TID P-ID Pri State                  Name
    1   8077870    0  15 Child Activation Wait  main_task
-*  2   807c458    1  15 Runnable               t
+*  2   807c458    1  15 Runnable               some_task
 (@value{GDBP}) task 1
-[Switching to task 1]
+[Switching to task 1 "main_task"]
 #0  0x8067726 in pthread_cond_wait ()
 (@value{GDBP}) bt
 #0  0x8067726 in pthread_cond_wait ()
index a51d22ce22faa8ffd715b03df42a4134c7a16cf8..bf3fcc7d844bc34d4d403125f5926e665fb5fa89 100644 (file)
@@ -1,3 +1,9 @@
+2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+       * gdb.ada/rdv_wait.exp: Update to new task names.
+       * gdb.base/task_switch_in_core.exp: Likewise.
+       * gdb.base/info_sources_base.c: Likewise.
+
 2019-09-10  Tom Tromey  <tromey@adacore.com>
 
        * boards/cc-with-tweaks.exp: Set GNATMAKE_FOR_TARGET.
index c0c4e29f5f97b8c1426f3bc2ecb9483ad6f96712..fe6aec3bcda34bf5a14cb5c71c904ec21c5a3d19 100644 (file)
@@ -31,5 +31,5 @@ runto "break_me"
 # Switch to task 2, and verify that GDB is able to unwind all the way
 # to foo.T.
 gdb_test "task 2" \
-         [join {"\\\[Switching to task 2\\\].*" \
+         [join {"\\\[Switching to task 2 \"mit\"\\\].*" \
                 ".*foo\\.t \\(.*\\).*foo\\.adb:.*"} ""]
index 4c482834bc845d57b82d0c44a855a0c6b00bdb94..fb9aef284096dfb372fbbd881afc48dc5f9f351f 100644 (file)
@@ -71,7 +71,7 @@ gdb_test "info tasks" \
 # we will verify right after with an additional test that the current
 # task is now task 2.
 gdb_test "task 2" \
-         "\\\[Switching to task 2\\\].*"
+         "\\\[Switching to task 2 \"my_t\"\\\].*"
 
 gdb_test "info tasks" \
          [multi_line "\\s+ID\\s+TID\\s+P-ID\\s+Pri\\s+State\\s+Name" \
This page took 0.052536 seconds and 4 git commands to generate.