This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] Implement -list-thread-groups.
- From: Vladimir Prus <vladimir at codesourcery dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Wed, 12 Nov 2008 23:33:29 +0300
- Subject: [RFC] Implement -list-thread-groups.
This patch implements new -list-thread-groups command. See the MI doc
patch I've posted earlier for general explanations. With this patch,
the command essentially prints gdb inferiors table. The --available
option is not implemented, and will be posted separately.
I'll commit in a few days if there are no objections.
- Volodya
From 3a312c9177927097a50030700d6f3939c7d4a5a2 Mon Sep 17 00:00:00 2001
* thread.c (print_thread_info): New parameter pid, to print
threads of specific process.
* gdbthread.h (print_thread_info): New parameter pid.
* mi/mi-cmds.c (mi_cmds): Register -list-thread-groups.
* mi/mi-cmds.h (mi_cmd_list_thread_groups): New.
* mi/mi-main.c (mi_cmd_thread_info): Adjust.
(print_one_process, mi_cmd_list_thread_groups): New.
---
gdb/gdbthread.h | 3 ++-
gdb/mi/mi-cmds.c | 1 +
gdb/mi/mi-cmds.h | 1 +
gdb/mi/mi-main.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
gdb/thread.c | 11 +++++++----
5 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 55c848d..cac20f7 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -295,7 +295,8 @@ extern struct cmd_list_element *thread_cmd_list;
`set print thread-events'. */
extern int print_thread_events;
-extern void print_thread_info (struct ui_out *uiout, int thread);
+extern void print_thread_info (struct ui_out *uiout, int thread,
+ int pid);
extern struct cleanup *make_cleanup_restore_current_thread (void);
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index ca0f428..d38de35 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -90,6 +90,7 @@ struct mi_cmd mi_cmds[] =
{ "interpreter-exec", { NULL, 0 }, mi_cmd_interpreter_exec},
{ "list-features", { NULL, 0 }, mi_cmd_list_features},
{ "list-target-features", { NULL, 0 }, mi_cmd_list_target_features},
+ { "list-thread-groups", { NULL, 0 }, mi_cmd_list_thread_groups },
{ "overlay-auto", { NULL, 0 }, NULL },
{ "overlay-list-mapping-state", { NULL, 0 }, NULL },
{ "overlay-list-overlays", { NULL, 0 }, NULL },
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 16887ae..a9bb1e0 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -67,6 +67,7 @@ extern mi_cmd_argv_ftype mi_cmd_inferior_tty_show;
extern mi_cmd_argv_ftype mi_cmd_interpreter_exec;
extern mi_cmd_argv_ftype mi_cmd_list_features;
extern mi_cmd_argv_ftype mi_cmd_list_target_features;
+extern mi_cmd_argv_ftype mi_cmd_list_thread_groups;
extern mi_cmd_argv_ftype mi_cmd_stack_info_depth;
extern mi_cmd_argv_ftype mi_cmd_stack_info_frame;
extern mi_cmd_argv_ftype mi_cmd_stack_list_args;
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index a9fbcad..544fec6 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -46,6 +46,7 @@
#include "mi-main.h"
#include "language.h"
#include "valprint.h"
+#include "processes.h"
#include <ctype.h>
#include <sys/time.h>
@@ -245,7 +246,55 @@ mi_cmd_thread_info (char *command, char **argv, int argc)
if (argc == 1)
thread = atoi (argv[0]);
- print_thread_info (uiout, thread);
+ print_thread_info (uiout, thread, -1);
+}
+
+static int
+print_one_process (struct process_info *process, void *arg)
+{
+ struct cleanup *back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+
+ ui_out_field_fmt (uiout, "id", "p%d", process->pid);
+ ui_out_field_string (uiout, "type", "process");
+ ui_out_field_int (uiout, "pid", process->pid);
+
+ do_cleanups (back_to);
+ return 0;
+}
+
+void
+mi_cmd_list_thread_groups (char *command, char **argv, int argc)
+{
+ struct cleanup *back_to;
+ int available = 0;
+ char *id = NULL;
+
+ if (argc > 0 && strcmp (argv[0], "--available") == 0)
+ {
+ ++argv;
+ --argc;
+ available = 1;
+ }
+
+ if (argc > 0)
+ id = argv[0];
+
+ back_to = make_cleanup (&null_cleanup, NULL);
+
+ if (id)
+ {
+ int pid = atoi (id);
+ if (!in_process_list (pid))
+ error ("Invalid thread group id '%s'", id);
+ print_thread_info (uiout, -1, pid);
+ }
+ else
+ {
+ make_cleanup_ui_out_list_begin_end (uiout, "groups");
+ iterate_over_processes (print_one_process, NULL);
+ }
+
+ do_cleanups (back_to);
}
void
diff --git a/gdb/thread.c b/gdb/thread.c
index b1e318d..316319a 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -638,7 +638,7 @@ set_stop_requested (ptid_t ptid, int stop)
that should be printed. Otherwise, all threads are
printed. */
void
-print_thread_info (struct ui_out *uiout, int requested_thread)
+print_thread_info (struct ui_out *uiout, int requested_thread, int pid)
{
struct thread_info *tp;
ptid_t current_ptid;
@@ -658,9 +658,12 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
{
struct cleanup *chain2;
+ if (pid != -1 && PIDGET (tp->ptid) != pid)
+ continue;
+
if (requested_thread != -1 && tp->num != requested_thread)
continue;
-
+
if (ptid_equal (tp->ptid, current_ptid))
current_thread = tp->num;
@@ -715,7 +718,7 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
the "info threads" command. */
do_cleanups (old_chain);
- if (requested_thread == -1)
+ if (pid == -1 && requested_thread == -1 )
{
gdb_assert (current_thread != -1
|| !thread_list);
@@ -740,7 +743,7 @@ The current thread <Thread ID %d> has terminated. See `help thread'.\n",
static void
info_threads_command (char *arg, int from_tty)
{
- print_thread_info (uiout, -1);
+ print_thread_info (uiout, -1, -1);
}
/* Switch from one thread to another. */
--
1.5.3.5