This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH: gdb/mi + doco] -var-update


On Wed, Jul 06, 2005 at 10:01:54PM +1200, Nick Roberts wrote:
>  >       ...  Nick, here's a copy of the patch with the bug you found
>  > stripped out of it.  Since you've got the current documentation, can
>  > you update that and add some testcases, when you get a chance?  I'd
>  > prefer to have all three go in together.
> 
> Daniel,
> 
> Eli has approved the documentation.  I have updated the source patch to work
> with --simple-values.  I put the definition of "struct varobj" into varobj.h
> to do this and modified mi_print_value_p.  You might prefer another way but
> this enabled me to add testcases.  These latest changes are attached.
> (existing patches for mi/mi-cmds.h and mi/mi-cmd-stack.c are also required)

For the future, I'd appreciate it if you didn't post partial patches
this way; I went back and dug up the right diffs, which isn't hard, but
is error-prone.  But I can handle it :-)

My version of TCL really did not like your testcase.  Did you attach
the right patch?  This one referenced var1 in the regexp but not in the
command, so it seems that it couldn't have passed.  And it added some
weird trailing whitespace.

This patch includes the missing files, and I redid the varobj change in
a pedantically different way.  Thanks for catching my goof there, by
the way.  And caught a bad argc check on -var-list-children that I
think you picked up from me at some point.

How's it look?  If it looks good to you, I'll check it in, and then you
can commit the documentation and we can work out what happened to your
testcase.

Also, this is for later, but I noticed some inconsistency in reviewing
the docs:

-stack-list-locals
   --no-values doesn't print types.
   --simple-value prints the types for everything, even complex values.
   --all-values doesn't print types.

-var-list-children always prints types, regardless of the PRINT_VALUES
option given.

-var-update never prints types, regardless of the PRINT_VALUES option.

Should some of those be cleaned up?  At a guess, I'd make
-stack-list-locals --all-values print types, and -var-update
--all-values or --simple-values.  Didn't think about it much though.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

2005-07-14  Nick Roberts  <nickrob@snap.net.nz>
	    Daniel Jacobowitz  <dan@codesourcery.com>

	* mi/mi-cmds.h (mi_no_values, mi_simple_values, mi_all_values): New
	declarations.
	* mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Use string
	constants instead of literals for MI command options.
	* mi/mi-cmd-var.c (mi_no_values, mi_simple_values, mi_all_values):
	New variables.
	(mi_parse_values_option, mi_print_value_p): New functions.
	(mi_cmd_var_list_children): Use mi_parse_values_option and
	mi_print_value_p.
	(mi_cmd_var_update): Support a PRINT_VALUES option.  Update calls
	to varobj_update_one.
	(varobj_update_one): Take a print_values argument.  Call
	mi_print_value_p.
	* varobj.c (varobj_get_gdb_type): New function.
	* varobj.h (varobj_get_gdb_type): New prototype.

Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.54
diff -u -p -r1.54 varobj.c
--- varobj.c	26 Apr 2005 05:03:37 -0000	1.54
+++ varobj.c	15 Jul 2005 01:40:23 -0000
@@ -1,6 +1,7 @@
 /* Implementation of the GDB variable objects API.
 
-   Copyright 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -760,6 +761,14 @@ varobj_get_type (struct varobj *var)
   return thetype;
 }
 
+/* Obtain the type of an object variable.  */
+
+struct type *
+varobj_get_gdb_type (struct varobj *var)
+{
+  return var->type;
+}
+
 enum varobj_languages
 varobj_get_language (struct varobj *var)
 {
Index: varobj.h
===================================================================
RCS file: /cvs/src/src/gdb/varobj.h,v
retrieving revision 1.4
diff -u -p -r1.4 varobj.h
--- varobj.h	17 Aug 2001 18:56:49 -0000	1.4
+++ varobj.h	15 Jul 2005 01:40:23 -0000
@@ -1,5 +1,5 @@
 /* GDB variable objects API.
-   Copyright 1999, 2000 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -85,6 +85,8 @@ extern int varobj_list_children (struct 
 
 extern char *varobj_get_type (struct varobj *var);
 
+extern struct type *varobj_get_gdb_type (struct varobj *var);
+
 extern enum varobj_languages varobj_get_language (struct varobj *var);
 
 extern int varobj_get_attributes (struct varobj *var);
Index: mi/mi-cmd-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v
retrieving revision 1.27
diff -u -p -r1.27 mi-cmd-stack.c
--- mi/mi-cmd-stack.c	19 Jun 2005 03:11:47 -0000	1.27
+++ mi/mi-cmd-stack.c	15 Jul 2005 01:40:23 -0000
@@ -1,5 +1,5 @@
 /* MI Command Set - stack commands.
-   Copyright 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Cygnus Solutions (a Red Hat company).
 
    This file is part of GDB.
@@ -136,16 +136,18 @@ mi_cmd_stack_list_locals (char *command,
    frame = get_selected_frame (NULL);
 
    if (strcmp (argv[0], "0") == 0
-       || strcmp (argv[0], "--no-values") == 0)
+       || strcmp (argv[0], mi_no_values) == 0)
      print_values = PRINT_NO_VALUES;
    else if (strcmp (argv[0], "1") == 0
-	    || strcmp (argv[0], "--all-values") == 0)
+	    || strcmp (argv[0], mi_all_values) == 0)
      print_values = PRINT_ALL_VALUES;
    else if (strcmp (argv[0], "2") == 0
-	    || strcmp (argv[0], "--simple-values") == 0)
+	    || strcmp (argv[0], mi_simple_values) == 0)
      print_values = PRINT_SIMPLE_VALUES;
    else
-     error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\", 2 or \"--simple-values\""));
+     error (_("Unknown value for PRINT_VALUES: must be: \
+0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
+	    mi_no_values, mi_all_values, mi_simple_values);
   list_args_or_locals (1, print_values, frame);
   return MI_CMD_DONE;
 }
Index: mi/mi-cmd-var.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v
retrieving revision 1.21
diff -u -p -r1.21 mi-cmd-var.c
--- mi/mi-cmd-var.c	11 Feb 2005 04:06:11 -0000	1.21
+++ mi/mi-cmd-var.c	15 Jul 2005 01:40:23 -0000
@@ -1,6 +1,6 @@
 /* MI Command Set - varobj commands.
 
-   Copyright 2000, 2002, 2004 Free Software Foundation, Inc.
+   Copyright 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions (a Red Hat company).
 
@@ -30,9 +30,14 @@
 #include <ctype.h>
 #include "gdb_string.h"
 
+const char mi_no_values[] = "--no-values";
+const char mi_simple_values[] = "--simple-values";
+const char mi_all_values[] = "--all-values";
+
 extern int varobjdebug;		/* defined in varobj.c */
 
-static int varobj_update_one (struct varobj *var);
+static int varobj_update_one (struct varobj *var,
+			      enum print_values print_values);
 
 /* VAROBJ operations */
 
@@ -247,6 +252,49 @@ mi_cmd_var_info_num_children (char *comm
   return MI_CMD_DONE;
 }
 
+/* Parse a string argument into a print_values value.  */
+
+static enum print_values
+mi_parse_values_option (const char *arg)
+{
+  if (strcmp (arg, "0") == 0
+      || strcmp (arg, mi_no_values) == 0)
+    return PRINT_NO_VALUES;
+  else if (strcmp (arg, "1") == 0
+	   || strcmp (arg, mi_all_values) == 0)
+    return PRINT_ALL_VALUES;
+  else if (strcmp (arg, "2") == 0
+	   || strcmp (arg, mi_simple_values) == 0)
+    return PRINT_SIMPLE_VALUES;
+  else
+    error (_("Unknown value for PRINT_VALUES\n\
+Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
+	   mi_no_values, mi_simple_values, mi_all_values);
+}
+
+/* Return 1 if given the argument PRINT_VALUES we should display
+   a value of type TYPE.  */
+
+static int
+mi_print_value_p (struct type *type, enum print_values print_values)
+{
+  if (type != NULL)
+    type = check_typedef (type);
+
+  if (print_values == PRINT_NO_VALUES)
+    return 0;
+
+  if (print_values == PRINT_ALL_VALUES)
+    return 1;
+
+  /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
+     and that type is not a compound type.  */
+
+  return (TYPE_CODE (type) != TYPE_CODE_ARRAY
+	  && TYPE_CODE (type) != TYPE_CODE_STRUCT
+	  && TYPE_CODE (type) != TYPE_CODE_UNION);
+}
+
 enum mi_cmd_result
 mi_cmd_var_list_children (char *command, char **argv, int argc)
 {
@@ -262,23 +310,19 @@ mi_cmd_var_list_children (char *command,
     error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME"));
 
   /* Get varobj handle, if a valid var obj name was specified */
-  if (argc == 1) var = varobj_get_handle (argv[0]);
-  else var = varobj_get_handle (argv[1]);
+  if (argc == 1)
+    var = varobj_get_handle (argv[0]);
+  else
+    var = varobj_get_handle (argv[1]);
   if (var == NULL)
     error (_("Variable object not found"));
 
   numchild = varobj_list_children (var, &childlist);
   ui_out_field_int (uiout, "numchild", numchild);
   if (argc == 2)
-    if (strcmp (argv[0], "0") == 0
-	|| strcmp (argv[0], "--no-values") == 0)
-      print_values = PRINT_NO_VALUES;
-    else if (strcmp (argv[0], "1") == 0
-	     || strcmp (argv[0], "--all-values") == 0)
-      print_values = PRINT_ALL_VALUES;
-    else
-     error (_("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\""));
-  else print_values = PRINT_NO_VALUES;
+    print_values = mi_parse_values_option (argv[0]);
+  else
+    print_values = PRINT_NO_VALUES;
 
   if (numchild <= 0)
     return MI_CMD_DONE;
@@ -295,12 +339,12 @@ mi_cmd_var_list_children (char *command,
       ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
       ui_out_field_string (uiout, "exp", varobj_get_expression (*cc));
       ui_out_field_int (uiout, "numchild", varobj_get_num_children (*cc));
-      if (print_values)
+      if (mi_print_value_p (varobj_get_gdb_type (*cc), print_values))
 	ui_out_field_string (uiout, "value", varobj_get_value (*cc));
       type = varobj_get_type (*cc);
       /* C++ pseudo-variables (public, private, protected) do not have a type */
       if (type)
-	ui_out_field_string (uiout, "type", varobj_get_type (*cc));
+	ui_out_field_string (uiout, "type", type);
       do_cleanups (cleanup_child);
       cc++;
     }
@@ -426,11 +470,20 @@ mi_cmd_var_update (char *command, char *
   struct cleanup *cleanup;
   char *name;
   int nv;
+  enum print_values print_values;
 
-  if (argc != 1)
-    error (_("mi_cmd_var_update: Usage: NAME."));
+  if (argc != 1 && argc != 2)
+    error (_("mi_cmd_var_update: Usage: [PRINT_VALUES] NAME."));
+
+  if (argc == 1)
+    name = argv[0];
+  else
+    name = (argv[1]);
 
-  name = argv[0];
+  if (argc == 2)
+    print_values = mi_parse_values_option (argv[0]);
+  else
+    print_values = PRINT_NO_VALUES;
 
   /* Check if the parameter is a "*" which means that we want
      to update all variables */
@@ -450,7 +503,7 @@ mi_cmd_var_update (char *command, char *
       cr = rootlist;
       while (*cr != NULL)
 	{
-	  varobj_update_one (*cr);
+	  varobj_update_one (*cr, print_values);
 	  cr++;
 	}
       xfree (rootlist);
@@ -467,7 +520,7 @@ mi_cmd_var_update (char *command, char *
         cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
       else
         cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");
-      varobj_update_one (var);
+      varobj_update_one (var, print_values);
       do_cleanups (cleanup);
     }
     return MI_CMD_DONE;
@@ -478,7 +531,7 @@ mi_cmd_var_update (char *command, char *
    scope), and 1 if it succeeds. */
 
 static int
-varobj_update_one (struct varobj *var)
+varobj_update_one (struct varobj *var, enum print_values print_values)
 {
   struct varobj **changelist;
   struct varobj **cc;
@@ -524,6 +577,8 @@ varobj_update_one (struct varobj *var)
 	  if (mi_version (uiout) > 1)
 	    cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
 	  ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
+	  if (mi_print_value_p (varobj_get_gdb_type (*cc), print_values))
+	    ui_out_field_string (uiout, "value", varobj_get_value (*cc));
 	  ui_out_field_string (uiout, "in_scope", "true");
 	  ui_out_field_string (uiout, "type_changed", "false");
 	  if (mi_version (uiout) > 1)
Index: mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.17
diff -u -p -r1.17 mi-cmds.h
--- mi/mi-cmds.h	6 Jul 2005 14:54:36 -0000	1.17
+++ mi/mi-cmds.h	15 Jul 2005 01:40:23 -0000
@@ -1,6 +1,6 @@
 /* MI Command Set for GDB, the GNU debugger.
 
-   Copyright 2000, 2003, 2004 Free Software Foundation, Inc.
+   Copyright 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
 
    Contributed by Cygnus Solutions (a Red Hat company).
 
@@ -50,6 +50,10 @@ enum print_values {
    PRINT_SIMPLE_VALUES
 };
 
+extern const char mi_no_values[];
+extern const char mi_simple_values[];
+extern const char mi_all_values[];
+
 typedef enum mi_cmd_result (mi_cmd_argv_ftype) (char *command, char **argv, int argc);
 
 /* Older MI commands have this interface. Retained until all old


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]