[Patch] Fix for -var-update to use natural format to compare

Marc Khouzam marc.khouzam@ericsson.com
Tue Jan 22 03:25:00 GMT 2008


This patch addresses a discussion titled "-var-update using formatted value" from
the GDB mailing list.
It modifies the variable object code to always uses the natural format to compare 
old and new values for the -var-update command (one line change).
It also renames the member print_value of varobj to natural_value.

### Eclipse Workspace Patch 1.0
#P gdb
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.99
diff -u -r1.99 varobj.c
--- varobj.c    1 Jan 2008 22:53:13 -0000       1.99
+++ varobj.c    22 Jan 2008 03:19:28 -0000
@@ -139,8 +139,8 @@
   /* Was this variable updated via a varobj_set_value operation */
   int updated;
 
-  /* Last print value.  */
-  char *print_value;
+  /* Last value in natural format.  */
+  char *natural_value;
 
   /* Is this variable frozen.  Frozen variables are never implicitly
      updated by -var-update * 
@@ -966,7 +966,7 @@
   int need_to_fetch;
   int changed = 0;
   int intentionally_not_fetched = 0;
-  char *print_value = NULL;
+  char *natural_value = NULL;
 
   /* We need to know the varobj's type to decide if the value should
      be fetched or not.  C++ fake children (public/protected/private) don't have
@@ -1025,11 +1025,15 @@
     }
 
   /* Below, we'll be comparing string rendering of old and new
-     values.  Don't get string rendering if the value is
+     values.  We only use the natural format to make sure we
+     catch changes that may affect some but not all formats.
+     E.g, float 1.1 and 1.2 are the same in all format except
+     natural; we don't want to miss this.
+     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))
-      print_value = value_get_print_value (value, var->format);
+      natural_value = value_get_print_value (value, FORMAT_NATURAL);
 
   /* If the type is changeable, compare the old and the new values.
      If this is the initial assignment, we don't have any old value
@@ -1069,8 +1073,8 @@
              gdb_assert (!value_lazy (var->value));
              gdb_assert (!value_lazy (value));
 
-             gdb_assert (var->print_value != NULL && print_value != NULL);
-             if (strcmp (var->print_value, print_value) != 0)
+             gdb_assert (var->natural_value != NULL && natural_value != NULL);
+             if (strcmp (var->natural_value, natural_value) != 0)
                changed = 1;
            }
        }
@@ -1080,9 +1084,9 @@
   if (var->value != NULL && var->value != value)
     value_free (var->value);
   var->value = value;
-  if (var->print_value)
-    xfree (var->print_value);
-  var->print_value = print_value;
+  if (var->natural_value)
+    xfree (var->natural_value);
+  var->natural_value = natural_value;
   if (value && value_lazy (value) && intentionally_not_fetched)
     var->not_fetched = 1;
   else
@@ -1489,7 +1493,7 @@
   var->format = 0;
   var->root = NULL;
   var->updated = 0;
-  var->print_value = NULL;
+  var->natural_value = NULL;
   var->frozen = 0;
   var->not_fetched = 0;
 
@@ -1526,7 +1530,7 @@
 
   xfree (var->name);
   xfree (var->obj_name);
-  xfree (var->print_value);
+  xfree (var->natural_value);
   xfree (var->path_expr);
   xfree (var);
 }



More information about the Gdb-patches mailing list