This is the mail archive of the gdb-patches@sourceware.org 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: RFC: MI - Detecting change of string contents with variable objects


 > > I'm not sure if we'll do that any more after your patch, e.g. if something
 > > beyond the limit of "set print elements" changes.  So, do you think any
 > > front end relies on the parent being marked updated if any of its children
 > > are?  Vlad, any opinion?
 > 
 > I think the code in question is never executed for structures or arrays --
 > only for "changeable" values.

I agree.  Below is my latest patch, incorporating some of your suggestions.


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


*** varobj.c	05 Jan 2007 13:16:30 +1300	1.74
--- varobj.c	05 Jan 2007 15:41:23 +1300	
*************** struct varobj
*** 132,137 ****
--- 132,140 ----
  
    /* Was this variable updated via a varobj_set_value operation */
    int updated;
+ 
+   /* Last print value.  */
+   char *print_value;
  };
  
  struct cpstack
*************** static int variable_editable (struct var
*** 206,211 ****
--- 209,217 ----
  
  static char *my_value_of_variable (struct varobj *var);
  
+ static char *value_get_print_value (struct value *value,
+ 				    enum varobj_display_formats format);
+ 
  static int varobj_value_is_changeable_p (struct varobj *var);
  
  static int is_root_p (struct varobj *var);
*************** install_new_value (struct varobj *var, s
*** 953,959 ****
    /* 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
       to compare with.  */
!   if (!initial && changeable)
      {
        /* If the value of the varobj was changed by -var-set-value, then the 
  	 value in the varobj and in the target is the same.  However, that value
--- 959,967 ----
    /* 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
       to compare with.  */
!   if (initial)
!     var->print_value = value_get_print_value (value, var->format);
!   else if (changeable)
      {
        /* If the value of the varobj was changed by -var-set-value, then the 
  	 value in the varobj and in the target is the same.  However, that value
*************** install_new_value (struct varobj *var, s
*** 974,999 ****
  	    changed = 1;
  	  else
  	    {
  	      gdb_assert (!value_lazy (var->value));
! 	      gdb_assert (!value_lazy (value));
! 	      
! 	      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
--- 982,1013 ----
  	    changed = 1;
  	  else
  	    {
+ 	      char *print_value;
  	      gdb_assert (!value_lazy (var->value));
! 	      print_value = value_get_print_value (value, var->format);
! 
! 	      if (strcmp (var->print_value, print_value))
! 		{
! 		  xfree (var->print_value);
! 		  var->print_value = print_value;
! 		  changed = 1;
! 		}
! 	      else
! 		xfree (print_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)
*** 1376,1381 ****
--- 1390,1396 ----
    var->format = 0;
    var->root = NULL;
    var->updated = 0;
+   var->print_value = NULL;
  
    return var;
  }
*************** free_variable (struct varobj *var)
*** 1409,1414 ****
--- 1424,1430 ----
  
    xfree (var->name);
    xfree (var->obj_name);
+   xfree (var->print_value);
    xfree (var);
  }
  
*************** my_value_of_variable (struct varobj *var
*** 1666,1671 ****
--- 1682,1701 ----
    return (*var->root->lang->value_of_variable) (var);
  }
  
+ static char *
+ value_get_print_value (struct value *value, enum varobj_display_formats format)
+ {
+   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, format_code[(int) format], 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
*************** c_value_of_variable (struct varobj *var)
*** 2038,2056 ****
  	  }
  	else
  	  {
- 	    long dummy;
- 	    struct ui_file *stb = mem_fileopen ();
- 	    struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
- 	    char *thevalue;
- 
  	    gdb_assert (varobj_value_is_changeable_p (var));
  	    gdb_assert (!value_lazy (var->value));
! 	    common_val_print (var->value, stb,
! 			      format_code[(int) var->format], 1, 0, 0);
! 	    thevalue = ui_file_xstrdup (stb, &dummy);
! 	    do_cleanups (old_chain);
! 	return thevalue;
!       }
        }
      }
  }
--- 2068,2077 ----
  	  }
  	else
  	  {
  	    gdb_assert (varobj_value_is_changeable_p (var));
  	    gdb_assert (!value_lazy (var->value));
! 	    return value_get_print_value (var->value, var->format);
! 	  }
        }
      }
  }


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