[MI] lvalues and variable_editable

Nick Roberts nickrob@snap.net.nz
Mon Jul 9 05:51:00 GMT 2007


(Me)

 > Anyway let me submit a more complete patch, in due course, for consideration
 > after the release.

This is what I have in mind.  There are no regressions, at least with MI (I
can't test Insight).  If there's still time, this could go in before the
branch.  I also have a (much smaller) change, that I've submitted earlier, for
after the release which adds the editable field to the output of -var-create
and -var-list-children, .

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


2007-07-09  Nick Roberts  <nickrob@snap.net.nz>

	* varobj.c (c_variable_editable, cplus_variable_editable)
	(java_variable_editable, variable_editable): Delete.
	(variable_editable_p): Replace above functions with one language
	independent function.  Check for an lvalue.  Derive from
	varobj_value_is_changeable_p.
	(varobj_get_attributes, varobj_set_value): Use variable_editable_p.
	(struct language_specific): Delete variable_editable field.

*** varobj.c	14 Apr 2007 21:51:29 +1200	1.89
--- varobj.c	04 Jul 2007 17:45:21 +1200	
*************** static struct value *value_of_root (stru
*** 217,229 ****
  
  static struct value *value_of_child (struct varobj *parent, int index);
  
- static int variable_editable (struct varobj *var);
- 
  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);
--- 217,229 ----
  
  static struct value *value_of_child (struct varobj *parent, int index);
  
  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 variable_editable_p (struct varobj *var);
+ 
  static int varobj_value_is_changeable_p (struct varobj *var);
  
  static int is_root_p (struct varobj *var);
*************** static struct value *c_value_of_child (s
*** 242,249 ****
  
  static struct type *c_type_of_child (struct varobj *parent, int index);
  
- static int c_variable_editable (struct varobj *var);
- 
  static char *c_value_of_variable (struct varobj *var);
  
  /* C++ implementation */
--- 242,247 ----
*************** static struct value *cplus_value_of_chil
*** 262,269 ****
  
  static struct type *cplus_type_of_child (struct varobj *parent, int index);
  
- static int cplus_variable_editable (struct varobj *var);
- 
  static char *cplus_value_of_variable (struct varobj *var);
  
  /* Java implementation */
--- 260,265 ----
*************** static struct value *java_value_of_child
*** 280,287 ****
  
  static struct type *java_type_of_child (struct varobj *parent, int index);
  
- static int java_variable_editable (struct varobj *var);
- 
  static char *java_value_of_variable (struct varobj *var);
  
  /* The language specific vector */
--- 276,281 ----
*************** struct language_specific
*** 310,318 ****
    /* The type of the INDEX'th child of PARENT. */
    struct type *(*type_of_child) (struct varobj * parent, int index);
  
-   /* Is VAR editable? */
-   int (*variable_editable) (struct varobj * var);
- 
    /* The current value of VAR. */
    char *(*value_of_variable) (struct varobj * var);
  };
--- 304,309 ----
*************** static struct language_specific language
*** 328,334 ****
     c_value_of_root,
     c_value_of_child,
     c_type_of_child,
-    c_variable_editable,
     c_value_of_variable}
    ,
    /* C */
--- 319,324 ----
*************** static struct language_specific language
*** 340,346 ****
     c_value_of_root,
     c_value_of_child,
     c_type_of_child,
-    c_variable_editable,
     c_value_of_variable}
    ,
    /* C++ */
--- 330,335 ----
*************** static struct language_specific language
*** 352,358 ****
     cplus_value_of_root,
     cplus_value_of_child,
     cplus_type_of_child,
-    cplus_variable_editable,
     cplus_value_of_variable}
    ,
    /* Java */
--- 341,346 ----
*************** static struct language_specific language
*** 364,370 ****
     java_value_of_root,
     java_value_of_child,
     java_type_of_child,
-    java_variable_editable,
     java_value_of_variable}
  };
  
--- 352,357 ----
*************** varobj_get_attributes (struct varobj *va
*** 817,823 ****
  {
    int attributes = 0;
  
!   if (var->root->is_valid && variable_editable (var))
      /* FIXME: define masks for attributes */
      attributes |= 0x00000001;	/* Editable */
  
--- 804,810 ----
  {
    int attributes = 0;
  
!   if (var->root->is_valid && variable_editable_p (var))
      /* FIXME: define masks for attributes */
      attributes |= 0x00000001;	/* Editable */
  
*************** varobj_set_value (struct varobj *var, ch
*** 848,854 ****
    struct value *value;
    int saved_input_radix = input_radix;
  
!   if (var->value != NULL && variable_editable (var))
      {
        char *s = expression;
        int i;
--- 835,841 ----
    struct value *value;
    int saved_input_radix = input_radix;
  
!   if (var->value != NULL && variable_editable_p (var))
      {
        char *s = expression;
        int i;
*************** value_of_child (struct varobj *parent, i
*** 1760,1773 ****
    return value;
  }
  
- /* Is this variable editable? Use the variable's type to make
-    this determination. */
- static int
- variable_editable (struct varobj *var)
- {
-   return (*var->root->lang->variable_editable) (var);
- }
- 
  /* GDB already has a command called "value_of_variable". Sigh. */
  static char *
  my_value_of_variable (struct varobj *var)
--- 1747,1752 ----
*************** value_get_print_value (struct value *val
*** 1799,1804 ****
--- 1778,1808 ----
    return thevalue;
  }
  
+ 
+ static int
+ variable_editable_pv (struct varobj *var)
+ {
+   struct expression *exp;
+   struct value *value;
+ 
+   if (CPLUS_FAKE_CHILD (var))
+     return 0;
+ 
+   if (is_root_p (var))
+     {
+       if (!gdb_evaluate_expression (var->root->exp, &value))
+ 	{
+ 	  /* We cannot proceed without a valid expression. */
+ 	  xfree (exp);
+ 	  return 0;
+ 	}
+       if (!VALUE_LVAL(value))
+ 	return 0;
+     }
+ 
+   return varobj_value_is_changeable_p (var);
+ }
+ 
  /* 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
*************** value_get_print_value (struct value *val
*** 1811,1817 ****
  static int
  varobj_value_is_changeable_p (struct varobj *var)
  {
-   int r;
    struct type *type;
  
    if (CPLUS_FAKE_CHILD (var))
--- 1815,1820 ----
*************** varobj_value_is_changeable_p (struct var
*** 1819,1837 ****
  
    type = get_value_type (var);
  
    switch (TYPE_CODE (type))
      {
      case TYPE_CODE_STRUCT:
      case TYPE_CODE_UNION:
      case TYPE_CODE_ARRAY:
!       r = 0;
        break;
  
      default:
!       r = 1;
      }
- 
-   return r;
  }
  
  /* Given the value and the type of a variable object,
--- 1822,1842 ----
  
    type = get_value_type (var);
  
+ 
    switch (TYPE_CODE (type))
      {
      case TYPE_CODE_STRUCT:
      case TYPE_CODE_UNION:
      case TYPE_CODE_ARRAY:
!     case TYPE_CODE_FUNC:
!     case TYPE_CODE_METHOD:
!       return 0;
        break;
  
      default:
!       return 1;
!       break;
      }
  }
  
  /* Given the value and the type of a variable object,
*************** c_type_of_child (struct varobj *parent, 
*** 2128,2152 ****
    return type;
  }
  
- static int
- c_variable_editable (struct varobj *var)
- {
-   switch (TYPE_CODE (get_value_type (var)))
-     {
-     case TYPE_CODE_STRUCT:
-     case TYPE_CODE_UNION:
-     case TYPE_CODE_ARRAY:
-     case TYPE_CODE_FUNC:
-     case TYPE_CODE_METHOD:
-       return 0;
-       break;
- 
-     default:
-       return 1;
-       break;
-     }
- }
- 
  static char *
  c_value_of_variable (struct varobj *var)
  {
--- 2133,2138 ----
*************** cplus_type_of_child (struct varobj *pare
*** 2477,2491 ****
    return type;
  }
  
- static int
- cplus_variable_editable (struct varobj *var)
- {
-   if (CPLUS_FAKE_CHILD (var))
-     return 0;
- 
-   return c_variable_editable (var);
- }
- 
  static char *
  cplus_value_of_variable (struct varobj *var)
  {
--- 2463,2468 ----
*************** java_type_of_child (struct varobj *paren
*** 2563,2574 ****
    return cplus_type_of_child (parent, index);
  }
  
- static int
- java_variable_editable (struct varobj *var)
- {
-   return cplus_variable_editable (var);
- }
- 
  static char *
  java_value_of_variable (struct varobj *var)
  {
--- 2540,2545 ----



More information about the Gdb-patches mailing list