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


 >       ...  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)

Nick


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

        * 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 (struct varobj): Move definition to...
	* varobj.h (struct varobj): ...here.

2005-07-06  Nick Roberts  <nickrob@snap.net.nz>

	* mi-var-child.exp: Adapt existing -var-update tests for
	--all-values and --simple-values options.
	Add -var-list-children test for --simple-values option.


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	6 Jul 2005 09:27:42 -0000
@@ -81,49 +81,6 @@ struct varobj_root
 /* Every variable in the system has a structure of this type defined
    for it. This structure holds all information necessary to manipulate
    a particular object variable. Members which must be freed are noted. */
-struct varobj
-{
-
-  /* Alloc'd name of the variable for this object.. If this variable is a
-     child, then this name will be the child's source name.
-     (bar, not foo.bar) */
-  /* NOTE: This is the "expression" */
-  char *name;
-
-  /* The alloc'd name for this variable's object. This is here for
-     convenience when constructing this object's children. */
-  char *obj_name;
-
-  /* Index of this variable in its parent or -1 */
-  int index;
-
-  /* The type of this variable. This may NEVER be NULL. */
-  struct type *type;
-
-  /* The value of this expression or subexpression.  This may be NULL. */
-  struct value *value;
-
-  /* Did an error occur evaluating the expression or getting its value? */
-  int error;
-
-  /* The number of (immediate) children this variable has */
-  int num_children;
-
-  /* If this object is a child, this points to its immediate parent. */
-  struct varobj *parent;
-
-  /* A list of this object's children */
-  struct varobj_child *children;
-
-  /* Description of the root variable. Points to root variable for children. */
-  struct varobj_root *root;
-
-  /* The format of the output for this object */
-  enum varobj_display_formats format;
-
-  /* Was this variable updated via a varobj_set_value operation */
-  int updated;
-};
 
 /* Every variable keeps a linked list of its children, described
    by the following structure. */


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	6 Jul 2005 09:28:01 -0000
@@ -52,7 +52,49 @@ enum varobj_languages
 extern char *varobj_language_string[];
 
 /* Struct thar describes a variable object instance */
-struct varobj;
+struct varobj
+{
+
+  /* Alloc'd name of the variable for this object.. If this variable is a
+     child, then this name will be the child's source name.
+     (bar, not foo.bar) */
+  /* NOTE: This is the "expression" */
+  char *name;
+
+  /* The alloc'd name for this variable's object. This is here for
+     convenience when constructing this object's children. */
+  char *obj_name;
+
+  /* Index of this variable in its parent or -1 */
+  int index;
+
+  /* The type of this variable. This may NEVER be NULL. */
+  struct type *type;
+
+  /* The value of this expression or subexpression.  This may be NULL. */
+  struct value *value;
+
+  /* Did an error occur evaluating the expression or getting its value? */
+  int error;
+
+  /* The number of (immediate) children this variable has */
+  int num_children;
+
+  /* If this object is a child, this points to its immediate parent. */
+  struct varobj *parent;
+
+  /* A list of this object's children */
+  struct varobj_child *children;
+
+  /* Description of the root variable. Points to root variable for children. */
+  struct varobj_root *root;
+
+  /* The format of the output for this object */
+  enum varobj_display_formats format;
+
+  /* Was this variable updated via a varobj_set_value operation */
+  int updated;
+};
 
 /* API functions */
 

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	6 Jul 2005 09:28:30 -0000
@@ -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,52 @@ 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 varobj *var, enum print_values print_values)
+{
+  struct type *type;
+  type = var->type;
+
+  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)
 {
@@ -258,27 +309,23 @@ mi_cmd_var_list_children (char *command,
   char *type;
   enum print_values print_values;
 
-  if (argc != 1 && argc != 2)
+  if (argc > 2)
     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 +342,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 (*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 +473,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."));
 
-  name = argv[0];
+  if (argc == 1)
+    name = argv[0];
+  else
+    name = (argv[1]);
+
+  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 +506,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 +523,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 +534,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 +580,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 (*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: testsuite/gdb.mi/mi-var-child.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-var-child.exp,v
retrieving revision 1.17
diff -u -p -r1.17 mi-var-child.exp
--- testsuite/gdb.mi/mi-var-child.exp	17 Aug 2004 09:38:29 -0000	1.17
+++ testsuite/gdb.mi/mi-var-child.exp	6 Jul 2005 09:56:25 -0000
@@ -9,7 +9,7 @@
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-#
+# 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -800,8 +800,8 @@ mi_step_to do_children_tests {} {.*var-c
 
 # Test: c_variable-5.6
 # Desc: check that long_array[1] changed
-mi_gdb_test "-var-update *" \
-	"\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.1\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
+mi_gdb_test "-var-update --all-values *" \
+	"\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.1\",value=\"2345\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
 	"update all vars struct_declarations.long_array.1 changed"
 
 # Step over "weird->long_array[2] = 3456;"
@@ -810,9 +810,9 @@ mi_step_to do_children_tests {} {.*var-c
 
 # Test: c_variable-5.7
 # Desc: check that long_array[2] changed
-mi_gdb_test "-var-update *" \
-	"\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.2\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
-	"update all vars struct_declarations.long_array.2 changed"
+mi_gdb_test "-var-update --simple-values *" \
+	"\\^done,changelist=\\\[\{name=\"struct_declarations.long_array.2\",value=\"3456\",in_scope=\"true\",type_changed=\"false\"\}\\\]" \
+	"update all vars struct_declarations.long_array.2 changed, print value"
 
 # Step over:
 #    struct_declarations.long_array[3] = 4567;
@@ -837,6 +837,10 @@ mi_gdb_test "-var-list-children --all-va
         "\\^done,numchild=\"10\",children=\\\[child=\{name=\"struct_declarations.long_array.0\",exp=\"0\",numchild=\"0\",value=\"1234\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.1\",exp=\"1\",numchild=\"0\",value=\"2345\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.2\",exp=\"2\",numchild=\"0\",value=\"3456\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.3\",exp=\"3\",numchild=\"0\",value=\"4567\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.4\",exp=\"4\",numchild=\"0\",value=\"5678\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.5\",exp=\"5\",numchild=\"0\",value=\"6789\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.6\",exp=\"6\",numchild=\"0\",value=\"7890\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.7\",exp=\"7\",numchild=\"0\",value=\"8901\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.8\",exp=\"8\",numchild=\"0\",value=\"9012\",type=\"long int\"\},child=\{name=\"struct_declarations.long_array.9\",exp=\"9\",numchild=\"0\",value=\"1234\",type=\"long int\"\}\\\]" \
                 "listing of names and values of children"
 
+mi_gdb_test "-var-list-children --simple-values struct_declarations" \
+        "\\^done,numchild=\"11\",children=\\\[child=\{name=\"var1.integer\",exp=\"integer\",numchild=\"0\",value=\"123\",type=\"int\"\},child=\{name=\"var1.character\",exp=\"character\",numchild=\"0\",value=\"0 '\\0'\",type=\"char\"\},child=\{name=\"var1.char_ptr\",exp=\"char_ptr\",numchild=\"1\",value=\"$hex \\\\\"hello\\\\\"\",type=\"char *\"\},child=\{name=\"var1.long_int\",exp=\"long_int\",numchild=\"0\",value=\"0\",type=\"long int\"\},child=\{name=\"var1.int_ptr_ptr\",exp=\"int_ptr_ptr\",numchild=\"1\",value=\"$hex\",type=\"int **\"\},child=\{name=\"var1.long_array\",exp=\"long_array\",numchild=\"10\",type=\"long int \\\[10\\\]\"\},child=\{name=\"var1.func_ptr\",exp=\"func_ptr\",numchild=\"0\",value=\"0\",type=\"void (*)(void)\"\},child=\{name=\"var1.func_ptr_struct\",exp=\"func_ptr_struct\",numchild=\"0\",value=\"0\",type=\"struct _struct_decl (*)(int, char *, long int)\"\},child=\{name=\"var1.func_ptr_ptr\",exp=\"func_ptr_ptr\",numchild=\"0\",value=\"0\",type=\"struct _struct_decl *(*)(int, char *, long int)\"\},child=\{name=\"var1.u1\",exp=\"u1\",numchild=\"4\",type=\"union \{...\}\"\},child=\{name=\"var1.s2\",exp=\"s2\",numchild=\"4\",type=\"struct \{...\}\"\}\\\]" \
+  "listing of children, simple types: names and values, complex types: values"
+
 # Step over "weird->func_ptr = nothing;"
 set line_dct_a0_0 [gdb_get_line_number "a0 = '0';"]
 mi_step_to do_children_tests {} {.*var-cmd.c} \

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