Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Snyder <msnyder@vmware.com>
To: Vladimir Prus <vladimir@codesourcery.com>
Cc: "gdb-patches@sources.redhat.com" <gdb-patches@sources.redhat.com>
Subject: Re: [RFC] Implement -list-thread-groups.
Date: Mon, 17 Nov 2008 19:48:00 -0000	[thread overview]
Message-ID: <4920D43A.6060202@vmware.com> (raw)
In-Reply-To: <200811162036.48822.vladimir@codesourcery.com>

Vladimir Prus wrote:
> On Sunday 16 November 2008 01:14:01 Michael Snyder wrote:
>> Excuse the top post.  Yes, calling error then.
> 
> Here's the final patch. OK?

I'm OK with the thread.c/gdbthread.h parts.
Thanks Volodya


> ------------------------------------------------------------------------
> 
> commit 58e34ce9109b3dfc10ddba4fe21476caa373f764
> Author: vladimir <vladimir@e7755896-6108-0410-9592-8049d3e74e28>
> Date:   Thu Jul 31 13:23:28 2008 +0000
> 
>     Implement -list-thread-groups.
>     
>     	* 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.
> 
> 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..43ec0b4 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 "inferior.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_inferior (struct inferior *inferior, void *arg)
> +{
> +  struct cleanup *back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
> +
> +  ui_out_field_fmt (uiout, "id", "%d", inferior->pid);
> +  ui_out_field_string (uiout, "type", "process");
> +  ui_out_field_int (uiout, "pid", inferior->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_inferior_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_inferiors (print_one_inferior, NULL);
> +    }
> +  
> +  do_cleanups (back_to);
>  }
>  
>  void
> diff --git a/gdb/thread.c b/gdb/thread.c
> index b1e318d..1f50e6a 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -636,9 +636,14 @@ set_stop_requested (ptid_t ptid, int stop)
>     use from MI.  
>     If REQUESTED_THREAD is not -1, it's the GDB id of the thread
>     that should be printed.  Otherwise, all threads are
> -   printed.  */
> +   printed.  
> +   If PID is not -1, only print threads from the process PID.
> +   Otherwise, threads from all attached PIDs are printed.   
> +   If both REQUESTED_THREAD and PID are not -1, then the thread
> +   is printed if it belongs to the specified process.  Otherwise,
> +   an error is raised.  */
>  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;
> @@ -661,6 +666,13 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
>        if (requested_thread != -1 && tp->num != requested_thread)
>  	continue;
>  
> +      if (pid != -1 && PIDGET (tp->ptid) != pid)
> +	{
> +	  if (requested_thread != -1)
> +	    error (_("Requested thread not found in requested process"));
> +	  continue;
> +	}
> +
>        if (ptid_equal (tp->ptid, current_ptid))
>  	current_thread = tp->num;
>  
> @@ -715,7 +727,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 +752,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. */


  reply	other threads:[~2008-11-17  2:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-12 21:01 Vladimir Prus
2008-11-14 11:46 ` Joel Brobecker
2008-11-14 11:58   ` Michael Snyder
2008-11-14 19:43   ` Vladimir Prus
2008-11-14 19:44     ` Michael Snyder
2008-11-14 21:45       ` Vladimir Prus
2008-11-15  4:58         ` Michael Snyder
2008-11-15  9:00           ` Vladimir Prus
2008-11-15 16:10             ` Michael Snyder
2008-11-15 19:06               ` Vladimir Prus
2008-11-16  8:22                 ` Michael Snyder
2008-11-16  8:22                   ` Vladimir Prus
     [not found]                     ` <29E9E827072C404C88A05DDC42B45997199E0503FF@PA-EXMBX14.vmware.com>
2008-11-17  9:42                       ` Vladimir Prus
2008-11-17 19:48                         ` Michael Snyder [this message]
2008-11-17 22:02                           ` Vladimir Prus
2008-11-14 20:46     ` Pedro Alves
2008-11-16  1:14     ` Joel Brobecker
2008-11-16  8:20       ` 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=4920D43A.6060202@vmware.com \
    --to=msnyder@vmware.com \
    --cc=gdb-patches@sources.redhat.com \
    --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