Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Vladimir Prus <vladimir@codesourcery.com>
To: gdb-patches@sources.redhat.com
Subject: [MI] -stack-list-variables
Date: Sat, 19 Sep 2009 10:12:00 -0000	[thread overview]
Message-ID: <200909191412.37692.vladimir@codesourcery.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 662 bytes --]


MI presently have two separate commands to list locals and arguments in
the current frame. Most often than not, frontend need both, so having
to emit two commands is inconvenience and and extra roundtrip. I believe
Nick has suggested having a single command, and Andre is in favour of
this idea, and I also think it's good. I actually recall than Nick planned
to write a patch, but I did not saw any, and this is fairly trivial
change, so here it goes. The new command is called -stack-list-variables,
and it's checked in into  CVS HEAD.

I'll post doc patch shortly; I will also merge this to 7.0 after a couple
of days, if no issues appear.


Thanks,
Volodya

[-- Attachment #2: stack-list-variables.diff --]
[-- Type: text/x-patch, Size: 6185 bytes --]

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.10882
diff -u -p -r1.10882 ChangeLog
--- ChangeLog	19 Sep 2009 09:46:45 -0000	1.10882
+++ ChangeLog	19 Sep 2009 09:58:45 -0000
@@ -1,3 +1,13 @@
+2009-09-19  Vladimir Prus  <vladimir@codesourcery.com>
+
+	* mi/mi-cmds.h (mi_cmd_stack_list_variables): Declare.
+	* mi/mi-cmds.c (mi_cmds): Register -stack-list-variables.
+	* mi/mi-cmd-stack.c (enum what_to_list): New.
+	(list_args_or_locals): Accept what_to_list parameter.
+	Use 'variables' as output name of all are requested.
+	(mi_cmd_stack_list_variables): New.
+	(mi_cmd_stack_list_locals, mi_cmd_stack_list_args): Adjust.
+
 2009-09-19  Eli Zaretskii  <eliz@gnu.org>
 
 	* config/djgpp/fnchange.lst: Add missing edits.
Index: mi/mi-cmd-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v
retrieving revision 1.44
diff -u -p -r1.44 mi-cmd-stack.c
--- mi/mi-cmd-stack.c	30 Jun 2009 09:37:23 -0000	1.44
+++ mi/mi-cmd-stack.c	19 Sep 2009 09:58:45 -0000
@@ -32,7 +32,11 @@
 #include "language.h"
 #include "valprint.h"
 
-static void list_args_or_locals (int locals, int values, struct frame_info *fi);
+
+enum what_to_list { locals, arguments, all };
+
+static void list_args_or_locals (enum what_to_list what, 
+				 int values, struct frame_info *fi);
 
 /* Print a list of the stack frames. Args can be none, in which case
    we want to print the whole backtrace, or a pair of numbers
@@ -148,7 +152,7 @@ mi_cmd_stack_list_locals (char *command,
 
    frame = get_selected_frame (NULL);
 
-   list_args_or_locals (1, parse_print_values (argv[0]), frame);
+   list_args_or_locals (locals, parse_print_values (argv[0]), frame);
 }
 
 /* Print a list of the arguments for the current frame. With argument
@@ -204,19 +208,37 @@ mi_cmd_stack_list_args (char *command, c
       QUIT;
       cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
       ui_out_field_int (uiout, "level", i);
-      list_args_or_locals (0, print_values, fi);
+      list_args_or_locals (arguments, print_values, fi);
       do_cleanups (cleanup_frame);
     }
 
   do_cleanups (cleanup_stack_args);
 }
 
+/* Print a list of the local variables (including arguments) for the 
+   current frame. With argument of 0, print only the names, with 
+   argument of 1 print also the values. */
+void
+mi_cmd_stack_list_variables (char *command, char **argv, int argc)
+{
+  struct frame_info *frame;
+  enum print_values print_values;
+
+  if (argc != 1)
+    error (_("Usage: PRINT_VALUES"));
+
+   frame = get_selected_frame (NULL);
+
+   list_args_or_locals (all, parse_print_values (argv[0]), frame);
+}
+
+
 /* Print a list of the locals or the arguments for the currently
    selected frame.  If the argument passed is 0, printonly the names
    of the variables, if an argument of 1 is passed, print the values
    as well. */
 static void
-list_args_or_locals (int locals, int values, struct frame_info *fi)
+list_args_or_locals (enum what_to_list what, int values, struct frame_info *fi)
 {
   struct block *block;
   struct symbol *sym;
@@ -225,12 +247,23 @@ list_args_or_locals (int locals, int val
   struct cleanup *cleanup_list;
   static struct ui_stream *stb = NULL;
   struct type *type;
+  char *name_of_result;
 
   stb = ui_out_stream_new (uiout);
 
   block = get_frame_block (fi, 0);
 
-  cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, locals ? "locals" : "args");
+  switch (what)
+    {
+    case locals:
+      name_of_result = "locals"; break;
+    case arguments:
+      name_of_result = "args"; break;
+    case all:
+      name_of_result = "variables"; break;
+    }
+
+  cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, name_of_result);
 
   while (block != 0)
     {
@@ -259,8 +292,12 @@ list_args_or_locals (int locals, int val
 	    case LOC_STATIC:	/* static                */
 	    case LOC_REGISTER:	/* register              */
 	    case LOC_COMPUTED:	/* computed location     */
-	      if (SYMBOL_IS_ARGUMENT (sym) ? !locals : locals)
+	      if (what == all)
 		print_me = 1;
+	      else if (what == locals)
+		print_me = !SYMBOL_IS_ARGUMENT (sym);
+	      else
+		print_me = SYMBOL_IS_ARGUMENT (sym);
 	      break;
 	    }
 	  if (print_me)
@@ -273,7 +310,7 @@ list_args_or_locals (int locals, int val
 		  make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
 	      ui_out_field_string (uiout, "name", SYMBOL_PRINT_NAME (sym));
 
-	      if (!locals)
+	      if (SYMBOL_IS_ARGUMENT (sym))
 		sym2 = lookup_symbol (SYMBOL_NATURAL_NAME (sym),
 				      block, VAR_DOMAIN,
 				      (int *) NULL);
Index: mi/mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.43
diff -u -p -r1.43 mi-cmds.c
--- mi/mi-cmds.c	15 Sep 2009 18:51:25 -0000	1.43
+++ mi/mi-cmds.c	19 Sep 2009 09:58:45 -0000
@@ -89,6 +89,7 @@ struct mi_cmd mi_cmds[] =
   { "stack-list-arguments", { NULL, 0 }, mi_cmd_stack_list_args},
   { "stack-list-frames", { NULL, 0 }, mi_cmd_stack_list_frames},
   { "stack-list-locals", { NULL, 0 }, mi_cmd_stack_list_locals},
+  { "stack-list-variables", { NULL, 0 }, mi_cmd_stack_list_variables},
   { "stack-select-frame", { NULL, 0 }, mi_cmd_stack_select_frame},
   { "symbol-list-lines", { NULL, 0 }, mi_cmd_symbol_list_lines},
   { "target-attach", { "attach", 1 }, NULL },
Index: mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.40
diff -u -p -r1.40 mi-cmds.h
--- mi/mi-cmds.h	15 Sep 2009 18:51:25 -0000	1.40
+++ mi/mi-cmds.h	19 Sep 2009 09:58:45 -0000
@@ -75,6 +75,7 @@ extern mi_cmd_argv_ftype mi_cmd_stack_in
 extern mi_cmd_argv_ftype mi_cmd_stack_list_args;
 extern mi_cmd_argv_ftype mi_cmd_stack_list_frames;
 extern mi_cmd_argv_ftype mi_cmd_stack_list_locals;
+extern mi_cmd_argv_ftype mi_cmd_stack_list_variables;
 extern mi_cmd_argv_ftype mi_cmd_stack_select_frame;
 extern mi_cmd_argv_ftype mi_cmd_symbol_list_lines;
 extern mi_cmd_argv_ftype mi_cmd_target_detach;

             reply	other threads:[~2009-09-19 10:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-19 10:12 Vladimir Prus [this message]
2009-09-19 10:13 ` Vladimir Prus
2009-09-19 10:38   ` Eli Zaretskii
2009-09-19 11:15 ` Vladimir Prus
2009-09-19 15:45 ` Joel Brobecker
2009-09-19 15:46 ` Joel Brobecker
2009-09-19 22:41 ` -stack-list-variables Nick Roberts
2009-09-20  6:18   ` [MI] -stack-list-variables Vladimir Prus
2009-09-20 22:05     ` Nick Roberts
2009-09-21  5:14       ` Vladimir Prus
2009-09-21  7:13         ` Nick Roberts
2009-09-21  7:39           ` Vladimir Prus
2009-09-21 15:29         ` Joel Brobecker
2009-09-21 16:02           ` Vladimir Prus
2009-09-21 16:27             ` Joel Brobecker
2009-09-21 16:54               ` Vladimir Prus
2009-09-21 17:04                 ` Tom Tromey
2009-09-21 17:17                   ` Vladimir Prus
2009-09-21 17:24                     ` Tom Tromey
2009-09-21 17:03               ` Marc Khouzam
2009-09-21 22:10             ` Nick Roberts
2009-09-22  5:31               ` Vladimir Prus
2009-09-22 14:50                 ` Daniel Jacobowitz
2009-09-29  6:35                 ` Vladimir Prus
2009-09-29 23:27                   ` Nick Roberts

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=200909191412.37692.vladimir@codesourcery.com \
    --to=vladimir@codesourcery.com \
    --cc=gdb-patches@sources.redhat.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