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

Daniel Jacobowitz drow@false.org
Mon Jul 4 05:02:00 GMT 2005


On Mon, Jul 04, 2005 at 07:55:13AM +0200, Eli Zaretskii wrote:
> It's okay with me, but I hope we won't forget the doco changes to go
> with these.

Absolutely!  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 Jacobowitz
CodeSourcery, LLC

2005-07-03  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.

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	3 Jul 2005 19:51:35 -0000
@@ -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	3 Jul 2005 19:51:35 -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,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 (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.  */
+
+  if (type == NULL)
+    return 0;
+  type = check_typedef (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,9 +339,9 @@ 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)
-	ui_out_field_string (uiout, "value", varobj_get_value (*cc));
       type = varobj_get_type (*cc);
+      if (mi_print_value_p (type, print_values))
+	ui_out_field_string (uiout, "value", varobj_get_value (*cc));
       /* C++ pseudo-variables (public, private, protected) do not have a type */
       if (type)
 	ui_out_field_string (uiout, "type", varobj_get_type (*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."));
 
-  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 +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_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.16
diff -u -p -r1.16 mi-cmds.h
--- mi/mi-cmds.h	19 Jun 2005 03:12:15 -0000	1.16
+++ mi/mi-cmds.h	3 Jul 2005 19:51:35 -0000
@@ -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



More information about the Gdb-patches mailing list