This is the mail archive of the archer@sourceware.org mailing list for the Archer 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]

[python] more varobj fixes


I'm checking this in on the python branch.

This fixes another problem reported by Vladimir.  The bug was that a
vector<string> would not pretty-print its children.  This was happening
because we were checking the result of update_dynamic_varobj_children,
and falling back to the non-pretty-printed code if it returned 0 -- but
it can do this if the printer does not have a children method.

Also, this fixes a few memory leaks I noticed along the way.

Tom

2009-08-18  Tom Tromey  <tromey@redhat.com>

	* varobj.c (varobj_list_children): Don't check result of
	update_dynamic_varobj_children.
	(varobj_pretty_printed_p): New function.
	(install_new_value): Don't fetch print value for a pretty-printed
	object.
	(my_value_of_variable): Special case pretty-printers.
	* varobj.h (varobj_pretty_printed_p): Declare.
	* mi/mi-cmd-var.c (print_varobj): Update for change to
	mi_print_value_p.  Free result of varobj_get_value.
	(mi_cmd_var_set_format): Likewise.
	(mi_parse_values_option): Likewise.
	(mi_cmd_var_evaluate_expression): Likewise.
	(mi_cmd_var_assign): Likewise.
	(varobj_update_one): Likewise.
	(mi_print_value_p): Use varobj_pretty_printed_p.  Change
	arguments.

diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 501b034..73c6482 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -41,7 +41,7 @@ static void varobj_update_one (struct varobj *var,
 			      enum print_values print_values,
 			      int explicit);
 
-static int mi_print_value_p (struct type *type, enum print_values print_values);
+static int mi_print_value_p (struct varobj *var, enum print_values print_values);
 
 /* Print variable object VAR.  The PRINT_VALUES parameter controls
    if the value should be printed.  The PRINT_EXPRESSION parameter
@@ -59,8 +59,12 @@ print_varobj (struct varobj *var, enum print_values print_values,
     ui_out_field_string (uiout, "exp", varobj_get_expression (var));
   ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
   
-  if (mi_print_value_p (varobj_get_gdb_type (var), print_values))
-    ui_out_field_string (uiout, "value", varobj_get_value (var));
+  if (mi_print_value_p (var, print_values))
+    {
+      char *val = varobj_get_value (var);
+      ui_out_field_string (uiout, "value", val);
+      xfree (val);
+    }
 
   type = varobj_get_type (var);
   if (type != NULL)
@@ -223,6 +227,7 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
 {
   enum varobj_display_formats format;
   struct varobj *var;
+  char *val;
 
   if (argc != 2)
     error (_("mi_cmd_var_set_format: Usage: NAME FORMAT."));
@@ -239,7 +244,9 @@ mi_cmd_var_set_format (char *command, char **argv, int argc)
   ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
  
   /* Report the value in the new format */
-  ui_out_field_string (uiout, "value", varobj_get_value (var));
+  val = varobj_get_value (var);
+  ui_out_field_string (uiout, "value", val);
+  xfree (val);
 }
 
 void
@@ -337,11 +344,12 @@ Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
 }
 
 /* Return 1 if given the argument PRINT_VALUES we should display
-   a value of type TYPE.  */
+   the varobj VAR.  */
 
 static int
-mi_print_value_p (struct type *type, enum print_values print_values)
+mi_print_value_p (struct varobj *var, enum print_values print_values)
 {
+  struct type *type;
 
   if (print_values == PRINT_NO_VALUES)
     return 0;
@@ -349,6 +357,10 @@ mi_print_value_p (struct type *type, enum print_values print_values)
   if (print_values == PRINT_ALL_VALUES)
     return 1;
 
+  if (varobj_pretty_printed_p (var))
+    return 1;
+
+  type = varobj_get_gdb_type (var);
   if (type == NULL)
     return 1;
   else
@@ -556,16 +568,24 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
   var = varobj_get_handle (argv[optind]);
    
   if (formatFound)
-    ui_out_field_string (uiout, "value", varobj_get_formatted_value (var, format));
+    {
+      char *val = varobj_get_formatted_value (var, format);
+      ui_out_field_string (uiout, "value", val);
+      xfree (val);
+    }
   else
-    ui_out_field_string (uiout, "value", varobj_get_value (var));
+    {
+      char *val = varobj_get_value (var);
+      ui_out_field_string (uiout, "value", val);
+      xfree (val);
+    }
 }
 
 void
 mi_cmd_var_assign (char *command, char **argv, int argc)
 {
   struct varobj *var;
-  char *expression;
+  char *expression, *val;
 
   if (argc != 2)
     error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION."));
@@ -581,7 +601,9 @@ mi_cmd_var_assign (char *command, char **argv, int argc)
   if (!varobj_set_value (var, expression))
     error (_("mi_cmd_var_assign: Could not assign expression to variable object"));
 
-  ui_out_field_string (uiout, "value", varobj_get_value (var));
+  val = varobj_get_value (var);
+  ui_out_field_string (uiout, "value", val);
+  xfree (val);
 }
 
 /* Type used for parameters passing to mi_cmd_var_update_iter.  */
@@ -696,8 +718,12 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
       switch (r->status)
 	{
 	case VAROBJ_IN_SCOPE:
-	  if (mi_print_value_p (varobj_get_gdb_type (r->varobj), print_values))
-	    ui_out_field_string (uiout, "value", varobj_get_value (r->varobj));
+	  if (mi_print_value_p (r->varobj, print_values))
+	    {
+	      char *val = varobj_get_value (r->varobj);
+	      ui_out_field_string (uiout, "value", val);
+	      xfree (val);
+	    }
 	  ui_out_field_string (uiout, "in_scope", "true");
 	  break;
         case VAROBJ_NOT_IN_SCOPE:
diff --git a/gdb/varobj.c b/gdb/varobj.c
index c64c628..306e2e8 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1074,13 +1074,13 @@ varobj_list_children (struct varobj *var, int *from, int *to)
 
   var->children_requested = 1;
 
-  if (var->pretty_printer
+  if (var->pretty_printer)
+    {
       /* This, in theory, can result in the number of children changing without
 	 frontend noticing.  But well, calling -var-list-children on the same
 	 varobj twice is not something a sane frontend would do.  */
-      && update_dynamic_varobj_children (var, NULL, NULL, &children_changed,
-					 0, *to))
-    {
+      update_dynamic_varobj_children (var, NULL, NULL, &children_changed,
+				      0, *to);
       restrict_range (var->children, from, to);
       return var->children;
     }
@@ -1184,6 +1184,12 @@ varobj_get_attributes (struct varobj *var)
   return attributes;
 }
 
+int
+varobj_pretty_printed_p (struct varobj *var)
+{
+  return var->pretty_printer != NULL;
+}
+
 char *
 varobj_get_formatted_value (struct varobj *var,
 			    enum varobj_display_formats format)
@@ -1457,7 +1463,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
      values.  Don't get string rendering if the value is
      lazy -- if it is, the code above has decided that the value
      should not be fetched.  */
-  if (value && !value_lazy (value))
+  if (value && !value_lazy (value) && !var->pretty_printer)
     print_value = value_get_print_value (value, var->format, var);
 
   /* If the type is changeable, compare the old and the new values.
@@ -2341,7 +2347,11 @@ static char *
 my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
 {
   if (var->root->is_valid)
-    return (*var->root->lang->value_of_variable) (var, format);
+    {
+      if (var->pretty_printer)
+	return value_get_print_value (var->value, var->format, var);
+      return (*var->root->lang->value_of_variable) (var, format);
+    }
   else
     return NULL;
 }
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 0744cc3..f43c593 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -173,4 +173,6 @@ extern void varobj_enable_pretty_printing (void);
 
 extern int varobj_has_more (struct varobj *var, int to);
 
+extern int varobj_pretty_printed_p (struct varobj *var);
+
 #endif /* VAROBJ_H */


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