From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13365 invoked by alias); 12 Nov 2008 20:34:10 -0000 Received: (qmail 13225 invoked by uid 22791); 12 Nov 2008 20:34:08 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Nov 2008 20:33:32 +0000 Received: (qmail 27516 invoked from network); 12 Nov 2008 20:29:16 -0000 Received: from unknown (HELO localhost) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 12 Nov 2008 20:29:16 -0000 From: Vladimir Prus To: gdb-patches@sources.redhat.com Subject: [RFC] Implement -list-thread-groups. Date: Wed, 12 Nov 2008 21:01:00 -0000 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200811122333.29218.vladimir@codesourcery.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-11/txt/msg00246.txt.bz2 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 =46rom 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; =20 -extern void print_thread_info (struct ui_out *uiout, int thread); +extern void print_thread_info (struct ui_out *uiout, int thread, + int pid); =20 extern struct cleanup *make_cleanup_restore_current_thread (void); =20 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[] =3D { "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 },=20=20 { "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" =20 #include #include @@ -245,7 +246,55 @@ mi_cmd_thread_info (char *command, char **argv, int ar= gc) if (argc =3D=3D 1) thread =3D atoi (argv[0]); =20 - 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 =3D 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); +=20=20 + do_cleanups (back_to); + return 0; +} + +void +mi_cmd_list_thread_groups (char *command, char **argv, int argc) +{ + struct cleanup *back_to; + int available =3D 0; + char *id =3D NULL; + + if (argc > 0 && strcmp (argv[0], "--available") =3D=3D 0) + { + ++argv; + --argc; + available =3D 1; + } + + if (argc > 0) + id =3D argv[0]; + + back_to =3D make_cleanup (&null_cleanup, NULL); + + if (id) + { + int pid =3D atoi (id); + if (!in_process_list (pid)) + error ("Invalid thread group id '%s'", id); + print_thread_info (uiout, -1, pid);=20=20=20=20 + } + else + { + make_cleanup_ui_out_list_begin_end (uiout, "groups"); + iterate_over_processes (print_one_process, NULL); + } +=20=20 + do_cleanups (back_to); } =20 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; =20 + if (pid !=3D -1 && PIDGET (tp->ptid) !=3D pid) + continue; +=20=20=20=20=20=20 if (requested_thread !=3D -1 && tp->num !=3D requested_thread) continue; - +=09 if (ptid_equal (tp->ptid, current_ptid)) current_thread =3D tp->num; =20 @@ -715,7 +718,7 @@ print_thread_info (struct ui_out *uiout, int requested_= thread) the "info threads" command. */ do_cleanups (old_chain); =20 - if (requested_thread =3D=3D -1) + if (pid =3D=3D -1 && requested_thread =3D=3D -1 ) { gdb_assert (current_thread !=3D -1 || !thread_list); @@ -740,7 +743,7 @@ The current thread 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); } =20 /* Switch from one thread to another. */ --=20 1.5.3.5