Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFC: MI - Detecting change of string contents with variable objects
@ 2006-12-18  2:42 Nick Roberts
  2006-12-18  7:01 ` Vladimir Prus
  0 siblings, 1 reply; 33+ messages in thread
From: Nick Roberts @ 2006-12-18  2:42 UTC (permalink / raw)
  To: gdb-patches


This post follows on from a thread earlier this month on the GDB mailing list
called "memory address ranges (-var-create)"

Currently variable objects treat strings as pointers so -var-update only
detects a change of address or, if the child is created, when the first
character changes.  The patch below detects when the contents change which is
more useful.  I've only tested it for C, but I guess it could work for other
languages that variable objects handle (C++, Java).  The function
value_get_value gets both the address and string value but it's probably better
to just get the string value directly.

-- 
Nick                                           http://www.inet.net.nz/~nickrob


*** varobj.c	11 Dec 2006 08:13:03 +1300	1.65
--- varobj.c	18 Dec 2006 15:06:23 +1300	
*************** struct varobj
*** 101,106 ****
--- 101,107 ----
    /* The type of this variable. This may NEVER be NULL. */
    struct type *type;
  
+ 
    /* The value of this expression or subexpression.  This may be NULL. 
       Invariant: if type_changeable (this) is non-zero, the value is either
       NULL, or not lazy.  */
*************** struct varobj
*** 126,131 ****
--- 127,135 ----
  
    /* Was this variable updated via a varobj_set_value operation */
    int updated;
+ 
+   /* Last string value, if appropriate */
+   char *string_value;
  };
  
  /* Every variable keeps a linked list of its children, described
*************** static int variable_editable (struct var
*** 233,238 ****
--- 237,244 ----
  
  static char *my_value_of_variable (struct varobj *var);
  
+ static char *value_get_value (struct value* value);
+ 
  static int type_changeable (struct varobj *var);
  
  /* C implementation */
*************** install_new_value (struct varobj *var, s
*** 983,1003 ****
  	      
  	      if (!value_contents_equal (var->value, value))
  		changed = 1;
  	    }
  	}
      }
!     
    /* We must always keep the new value, since children depend on it.  */
    if (var->value != NULL)
      value_free (var->value);
    var->value = value;
    var->updated = 0;
!   
    gdb_assert (!var->value || value_type (var->value));
  
    return changed;
  }
-   
  
  /* Update the values for a variable and its children.  This is a
     two-pronged attack.  First, re-parse the value for the root's
--- 989,1025 ----
  	      
  	      if (!value_contents_equal (var->value, value))
  		changed = 1;
+ 
+ 	      if (variable_language (var) == vlang_c &&
+ 		  !strcmp (varobj_get_type (var), "char *"))
+ 		{
+ 		  if (var->string_value)
+ 		    {
+ 		      if (strcmp (var->string_value, value_get_value (value)))
+ 			{
+ 			  free (var->string_value);
+ 			  var->string_value =
+ 			    xstrdup (value_get_value (value));
+ 			  changed = 1;
+ 			}
+ 		    }
+ 		  else
+ 		    var->string_value = xstrdup (value_get_value (value));
+ 		}
  	    }
  	}
      }
! 
    /* We must always keep the new value, since children depend on it.  */
    if (var->value != NULL)
      value_free (var->value);
    var->value = value;
    var->updated = 0;
! 
    gdb_assert (!var->value || value_type (var->value));
  
    return changed;
  }
  
  /* Update the values for a variable and its children.  This is a
     two-pronged attack.  First, re-parse the value for the root's
*************** new_variable (void)
*** 1470,1475 ****
--- 1492,1498 ----
    var->format = 0;
    var->root = NULL;
    var->updated = 0;
+   var->string_value = NULL;
  
    return var;
  }
*************** my_value_of_variable (struct varobj *var
*** 1785,1790 ****
--- 1808,1827 ----
    return (*var->root->lang->value_of_variable) (var);
  }
  
+ static char *
+ value_get_value (struct value* value)
+ {
+   long dummy;
+   struct ui_file *stb = mem_fileopen ();
+   struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
+   char *thevalue;
+ 	    
+   common_val_print (value, stb, 0, 1, 0, 0);
+   thevalue = ui_file_xstrdup (stb, &dummy);
+   do_cleanups (old_chain);
+   return thevalue;
+ }
+ 
  /* Return non-zero if changes in value of VAR
     must be detected and reported by -var-update.
     Return zero is -var-update should never report


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2007-01-08 21:41 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-18  2:42 RFC: MI - Detecting change of string contents with variable objects Nick Roberts
2006-12-18  7:01 ` Vladimir Prus
2006-12-18  8:15   ` Nick Roberts
2006-12-18  8:36     ` Vladimir Prus
2006-12-18 13:38       ` Daniel Jacobowitz
2006-12-18 21:57         ` Nick Roberts
2006-12-21 15:25           ` Vladimir Prus
2006-12-21 22:28             ` Nick Roberts
2006-12-22  6:16               ` Vladimir Prus
2006-12-22  7:16                 ` Nick Roberts
2006-12-22  7:23                   ` Vladimir Prus
2007-01-03 22:46           ` Daniel Jacobowitz
2007-01-04  4:13             ` Nick Roberts
2007-01-04  4:20               ` Daniel Jacobowitz
2007-01-04  6:10                 ` Nick Roberts
2007-01-04 19:40                   ` Daniel Jacobowitz
2007-01-04 20:35                     ` Nick Roberts
2007-01-04 20:50                       ` Daniel Jacobowitz
2007-01-04 21:00                         ` Vladimir Prus
2007-01-05  4:46                           ` Nick Roberts
2007-01-05 14:49                             ` Daniel Jacobowitz
2007-01-05 21:54                               ` Nick Roberts
2007-01-06  7:07                                 ` Vladimir Prus
2007-01-08 15:51                                 ` Daniel Jacobowitz
2007-01-08 21:30                                   ` Nick Roberts
2007-01-08 21:41                                     ` Daniel Jacobowitz
2007-01-04 20:57                       ` Vladimir Prus
2007-01-05  2:26                         ` Nick Roberts
2007-01-04 21:05                   ` Vladimir Prus
2007-01-05  1:09                     ` Nick Roberts
2007-01-05 14:44                       ` Daniel Jacobowitz
2007-01-05 14:49                         ` Vladimir Prus
2007-01-05 16:04                       ` Jim Blandy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox