This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] MI: lvalues and variable_editable
- From: Nick Roberts <nickrob at snap dot net dot nz>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 27 Oct 2007 11:28:33 +1300
- Subject: [PATCH] MI: lvalues and variable_editable
I'm representing a patch from before the release of GDB 6.7. The change to
c_name_of_variable is unrelated and I can commit it separately, if wished.
I also attach a test for the main change.
--
Nick http://www.inet.net.nz/~nickrob
2007-10-27 Nick Roberts <nickrob@snap.net.nz>
* varobj.c (c_variable_editable, cplus_variable_editable)
(java_variable_editable, variable_editable): Delete.
(varobj_editable_p): Replace above functions with one language
independent function. Check for an lvalue.
(varobj_get_attributes, varobj_set_value): Use varobj_editable_p.
(struct language_specific): Delete variable_editable field.
(varobj_value_is_changeable_p): Simplify.
(c_name_of_variable): Remove memory leak.
* mi-var-cmd.exp: Add test for assigning to varobjs that aren't
lvalues.
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.96
diff -p -c -p -r1.96 varobj.c
*** varobj.c 27 Sep 2007 18:04:12 -0000 1.96
--- varobj.c 26 Oct 2007 22:23:27 -0000
*************** static struct value *value_of_root (stru
*** 221,227 ****
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);
--- 221,227 ----
static struct value *value_of_child (struct varobj *parent, int index);
! static int varobj_editable_p (struct varobj *var);
static char *my_value_of_variable (struct varobj *var);
*************** static struct value *c_value_of_child (s
*** 248,255 ****
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 */
--- 248,253 ----
*************** static struct value *cplus_value_of_chil
*** 270,277 ****
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 */
--- 268,273 ----
*************** static struct value *java_value_of_child
*** 290,297 ****
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 */
--- 286,291 ----
*************** struct language_specific
*** 324,332 ****
/* 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);
};
--- 318,323 ----
*************** static struct language_specific language
*** 343,349 ****
c_value_of_root,
c_value_of_child,
c_type_of_child,
- c_variable_editable,
c_value_of_variable}
,
/* C */
--- 334,339 ----
*************** static struct language_specific language
*** 356,362 ****
c_value_of_root,
c_value_of_child,
c_type_of_child,
- c_variable_editable,
c_value_of_variable}
,
/* C++ */
--- 346,351 ----
*************** static struct language_specific language
*** 369,375 ****
cplus_value_of_root,
cplus_value_of_child,
cplus_type_of_child,
- cplus_variable_editable,
cplus_value_of_variable}
,
/* Java */
--- 358,363 ----
*************** static struct language_specific language
*** 382,388 ****
java_value_of_root,
java_value_of_child,
java_type_of_child,
- java_variable_editable,
java_value_of_variable}
};
--- 370,375 ----
*************** varobj_get_attributes (struct varobj *va
*** 856,862 ****
{
int attributes = 0;
! if (var->root->is_valid && variable_editable (var))
/* FIXME: define masks for attributes */
attributes |= 0x00000001; /* Editable */
--- 843,849 ----
{
int attributes = 0;
! if (var->root->is_valid && varobj_editable_p (var))
/* FIXME: define masks for attributes */
attributes |= 0x00000001; /* Editable */
*************** varobj_set_value (struct varobj *var, ch
*** 887,893 ****
struct value *value;
int saved_input_radix = input_radix;
! if (var->value != NULL && variable_editable (var))
{
char *s = expression;
int i;
--- 874,880 ----
struct value *value;
int saved_input_radix = input_radix;
! if (var->value != NULL && varobj_editable_p (var))
{
char *s = expression;
int i;
*************** value_of_child (struct varobj *parent, i
*** 1801,1814 ****
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)
--- 1788,1793 ----
*************** value_get_print_value (struct value *val
*** 1840,1845 ****
--- 1819,1862 ----
return thevalue;
}
+
+ static int
+ varobj_editable_p (struct varobj *var)
+ {
+ struct type *type;
+ struct expression *exp;
+ struct value *value;
+
+ if (CPLUS_FAKE_CHILD (var))
+ return 0;
+
+ 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;
+
+ 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;
+ }
+ }
+
/* 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
*** 1852,1858 ****
static int
varobj_value_is_changeable_p (struct varobj *var)
{
- int r;
struct type *type;
if (CPLUS_FAKE_CHILD (var))
--- 1869,1874 ----
*************** varobj_value_is_changeable_p (struct var
*** 1865,1878 ****
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,
--- 1881,1893 ----
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
case TYPE_CODE_ARRAY:
! return 0;
break;
default:
! return 1;
! break;
}
}
/* Given the value and the type of a variable object,
*************** c_number_of_children (struct varobj *var
*** 1983,1991 ****
}
static char *
! c_name_of_variable (struct varobj *parent)
{
! return savestring (parent->name, strlen (parent->name));
}
/* Return the value of element TYPE_INDEX of a structure
--- 1998,2006 ----
}
static char *
! c_name_of_variable (struct varobj *var)
{
! return var->name;
}
/* Return the value of element TYPE_INDEX of a structure
*************** c_type_of_child (struct varobj *parent,
*** 2212,2236 ****
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 vWrite failed flushing stdout buffer.
write stdout: Broken pipe
arobj *var)
{
--- 2227,2232 ----
*************** cplus_type_of_child (struct varobj *pare
*** 2602,2616 ****
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)
{
--- 2598,2603 ----
*************** java_type_of_child (struct varobj *paren
*** 2694,2705 ****
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)
{
--- 2681,2686 ----
Index: mi-var-cmd.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-var-cmd.exp,v
retrieving revision 1.33
diff -p -c -p -r1.33 mi-var-cmd.exp
*** mi-var-cmd.exp 1 Oct 2007 14:07:45 -0000 1.33
--- mi-var-cmd.exp 26 Oct 2007 22:25:07 -0000
*************** mi_gdb_test "113-var-create argc * argc"
*** 68,73 ****
--- 68,77 ----
"&\"mi_cmd_var_create: unable to create variable object\\\\n\".*113\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
"create out of scope variable"
+ mi_gdb_test "-var-create castfloat * (float)global_simple.integer" \
+ "\\^done,name=\"castfloat\",numchild=\"0\",value=\".*\",type=\"float\"" \
+ "create float cast of an int"
+
mi_runto do_locals_tests
set line_dlt_first_real [gdb_get_line_number "linteger = 1234;"]
*************** mi_gdb_test "-var-assign global_simple 0
*** 278,283 ****
--- 282,291 ----
"&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msgWrite failed flushing stdout buffer.
write stdout: Broken pipe
=\"mi_cmd_var_assign: Variable object is not editable\"" \
"assign to global_simple"
+ mi_gdb_test "-var-assign castfloat 5.0" \
+ "&\"mi_cmd_var_assign: Variable object is not editable\\\\n\".*\\^error,msg=\"mi_cmd_var_assign: Variable object is not editable\"" \
+ "assign to a cast"
+
mi_gdb_test "-var-assign linteger 3333" \
"\\^done,value=\"3333\"" \
"assign to linteger"