Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: vladimir@codesourcery.com,	Joel Brobecker <brobecker@adacore.com>
Subject: [PATCH 2/3] [Ada] Add field "thread-id" in -ada-task-info output
Date: Fri, 16 Sep 2011 22:44:00 -0000	[thread overview]
Message-ID: <1316205921-18702-3-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1316205921-18702-1-git-send-email-brobecker@adacore.com>

This patch enhances the -ada-task-info command, adding a new
field called "thread-id" in the command output.  This field
provides the ID of the task's corresponding thread (if that
information could not be determined, the field is omitted).

This field is useful in the context of GDB/MI users, because
it allows a quick translation from Ada task to thread, and
thus easy use of all the commands that take a --thread argument.

gdb/ChangeLog:

        * ada-tasks.c (print_ada_task_info): Add "thread-id" field
        in output of -ada-task-info GDB/MI command.

Tested on x86_64-linux.

Thanks,
-- 
Joel

---
 gdb/ada-tasks.c |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 7dff8f8..2673fed 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -938,6 +938,7 @@ print_ada_task_info (struct ui_out *uiout,
   int taskno, nb_tasks;
   int taskno_arg = 0;
   struct cleanup *old_chain;
+  int nb_columns;
 
   if (ada_build_task_list () == 0)
     {
@@ -949,14 +950,29 @@ print_ada_task_info (struct ui_out *uiout,
   if (arg_str != NULL && arg_str[0] != '\0')
     taskno_arg = value_as_long (parse_and_eval (arg_str));
 
+  if (ui_out_is_mi_like_p (uiout))
+    /* In GDB/MI mode, we want to provide the thread ID corresponding
+       to each task.  This allows clients to quickly find the thread
+       associated to any task, which is helpful for commands that
+       take a --thread argument.  However, in order to be able to
+       provide that thread ID, the thread list must be up to date
+       first.  */
+    target_find_new_threads ();
+
   data = get_ada_tasks_inferior_data (inf);
   nb_tasks = VEC_length (ada_task_info_s, data->task_list);
 
-  old_chain = make_cleanup_ui_out_table_begin_end (uiout, 7, nb_tasks,
-                                                   "tasks");
+  nb_columns = ui_out_is_mi_like_p (uiout) ? 8 : 7;
+  old_chain = make_cleanup_ui_out_table_begin_end (uiout, nb_columns,
+						   nb_tasks, "tasks");
   ui_out_table_header (uiout, 1, ui_left, "current", "");
   ui_out_table_header (uiout, 3, ui_right, "id", "ID");
   ui_out_table_header (uiout, 9, 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.  */
+  if (ui_out_is_mi_like_p (uiout))
+    ui_out_table_header (uiout, 4, ui_right, "thread-id", "");
   ui_out_table_header (uiout, 4, ui_right, "parent-id", "P-ID");
   ui_out_table_header (uiout, 3, ui_right, "priority", "Pri");
   ui_out_table_header (uiout, 22, ui_left, "state", "State");
@@ -996,6 +1012,19 @@ print_ada_task_info (struct ui_out *uiout,
       /* Print the Task ID.  */
       ui_out_field_fmt (uiout, "task-id", "%9lx", (long) task_info->task_id);
 
+      /* Print the associated Thread ID.  */
+      if (ui_out_is_mi_like_p (uiout))
+        {
+	  const int thread_id = pid_to_thread_id (task_info->ptid);
+
+	  if (thread_id != 0)
+	    ui_out_field_int (uiout, "thread-id", thread_id);
+	  else
+	    /* This should never happen unless there is a bug somewhere,
+	       but be resilient when that happens.  */
+	    ui_out_field_skip (uiout, "thread-id");
+	}
+
       /* Print the ID of the parent task.  */
       parent_id = get_task_number_from_id (task_info->parent, inf);
       if (parent_id)
-- 
1.7.1


  parent reply	other threads:[~2011-09-16 20:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-16 20:45 [GDB/MI Ada] New GDB/MI command: -ada-tasks-info Joel Brobecker
2011-09-16 20:46 ` [PATCH 3/3] [Ada/doco] Document the new -ada-task-info GDB/MI command Joel Brobecker
2011-09-17  8:59   ` Eli Zaretskii
2011-09-16 20:46 ` [RFA 1/3] [Ada] New GDB/MI command: -ada-tasks-info Joel Brobecker
2011-09-19 17:52   ` Vladimir Prus
2011-09-20  4:12     ` Joel Brobecker
2011-09-16 22:44 ` Joel Brobecker [this message]
2011-10-03 21:40 ` [GDB/MI Ada] " Joel Brobecker
     [not found] <1316201377-14830-1-git-send-email-brobecker@adacore.com>
2011-09-16 19:30 ` [PATCH 2/3] [Ada] Add field "thread-id" in -ada-task-info output Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316205921-18702-3-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=vladimir@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox