[RFA] Output the Ada task name in more messages.

Philippe Waroquiers philippe.waroquiers@skynet.be
Sun Jun 9 08:46:00 GMT 2019


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]

This is just the Ada related changes in
https://sourceware.org/ml/gdb-patches/2019-05/msg00444.html
[RFA] Give thread names in thread events, give Ada task names in more output.

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

gdb/ChangeLog
2019-06-08  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Announce that Ada task names are now shown at more places.
	* gdb/ada-tasks.c (task_to_str): New function.
	(display_current_task_id): Call task_to_str.
	(task_command_1): Likewise.

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

	* gdb.texinfo (Ada Tasks): Tell the task name is printed, update
	examples.
---
 gdb/NEWS                                      |  3 ++
 gdb/ada-tasks.c                               | 31 ++++++++++++++++---
 gdb/doc/gdb.texinfo                           |  8 ++---
 gdb/testsuite/gdb.ada/rdv_wait.exp            |  2 +-
 gdb/testsuite/gdb.ada/task_switch_in_core.exp |  2 +-
 5 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 9e1462b6bf..afb74cbb96 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -21,6 +21,9 @@
 * Two new convenience functions $_cimag and $_creal that extract the
   imaginary and real parts respectively from complex numbers.
 
+* 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
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 9c07f0ca22..a18aa2a55e 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -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.
 
@@ -1255,7 +1267,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 +1293,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 +1315,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);
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 0df345338e..393662da98 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17369,7 +17369,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
@@ -17378,9 +17378,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}
@@ -17396,7 +17396,7 @@ 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]
 #0  0x8067726 in pthread_cond_wait ()
diff --git a/gdb/testsuite/gdb.ada/rdv_wait.exp b/gdb/testsuite/gdb.ada/rdv_wait.exp
index c0c4e29f5f..fa309a1341 100644
--- a/gdb/testsuite/gdb.ada/rdv_wait.exp
+++ b/gdb/testsuite/gdb.ada/rdv_wait.exp
@@ -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:.*"} ""]
diff --git a/gdb/testsuite/gdb.ada/task_switch_in_core.exp b/gdb/testsuite/gdb.ada/task_switch_in_core.exp
index 4c482834bc..f0ac8dbc98 100644
--- a/gdb/testsuite/gdb.ada/task_switch_in_core.exp
+++ b/gdb/testsuite/gdb.ada/task_switch_in_core.exp
@@ -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" \
-- 
2.20.1



More information about the Gdb-patches mailing list