From e4c0545d139f932aca0dcc5ec9550c23bfadde8e Mon Sep 17 00:00:00 2001 From: vprus Date: Wed, 24 Jan 2007 10:49:27 +0000 Subject: [PATCH] Fix computation of the 'editable' attribute and value changeability for for references. * varobj.c (get_value_type): New function. (c_variable_editable): Use get_value_type. (varobj_value_is_changeable): Likewise. --- gdb/ChangeLog | 8 ++++++++ gdb/testsuite/ChangeLog | 10 ++++++++++ gdb/testsuite/gdb.mi/mi-var-cp.cc | 28 +++++++++++++++++++++++++++- gdb/testsuite/gdb.mi/mi-var-cp.exp | 1 + gdb/testsuite/lib/mi-support.exp | 7 +++++++ gdb/varobj.c | 37 +++++++++++++++++++++++++++++++++++-- 6 files changed, 88 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 52025a7177..46302c0205 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2007-01-24 Vladimir Prus + + Fix computation of the 'editable' attribute and + value changeability for for references. + * varobj.c (get_value_type): New function. + (c_variable_editable): Use get_value_type. + (varobj_value_is_changeable): Likewise. + 2007-01-24 Joel Brobecker * source.c (find_and_open_source): Try rewriting the source diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c4ec97d8bd..a6c18a248d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2007-01-24 Vladimir Prus + + * lib/mi-support.exp (mi_delete_varobj): New. + * gdb.mi/mi-var-cp.exp: Run the reference_to_struct + testcase. + * gdb.mi/mi-var-cp.cc (reference_to_struct): New function. + (main): Call the above. + (reference_update_test, base_in_reference_test) + (reference_to_pointer): Delete the created varobjs. + 2007-01-23 Daniel Jacobowitz * Makefile.in (ALL_SUBDIRS): Add gdb.xml. diff --git a/gdb/testsuite/gdb.mi/mi-var-cp.cc b/gdb/testsuite/gdb.mi/mi-var-cp.cc index 33f84e6fc3..6f4fae057d 100644 --- a/gdb/testsuite/gdb.mi/mi-var-cp.cc +++ b/gdb/testsuite/gdb.mi/mi-var-cp.cc @@ -30,6 +30,7 @@ void reference_update_tests () :*/ x = 567; /*: mi_varobj_update RX {} "update RX (3)" + mi_delete_varobj RX "delete RX" :*/ /* Dummy assignment to keep 'x' in scope. */ x = 444; @@ -59,7 +60,8 @@ int base_in_reference_test (S2& s2) mi_check_varobj_value "S2.S.public.i" "67" "check S2.S.public.i" mi_check_varobj_value "S2.S.public.j" "89" "check S2.S.public.j" - + mi_delete_varobj S2 "delete S2" + :*/ /*: END: base_in_reference :*/ } @@ -91,15 +93,39 @@ int reference_to_pointer () mi_check_varobj_value RPTR.public.i 67 "check i member" mi_check_varobj_value RPTR.public.j 89 "check j member" + mi_delete_varobj RPTR "delete RPTR" :*/ return 99; /*: END: reference_to_pointer :*/ } +int reference_to_struct () +{ + /*: BEGIN: reference_to_struct :*/ + S s = {7, 8}; + S& r = s; + /*: + mi_create_varobj S s "create varobj for s" + mi_create_varobj R r "create varobj for s" + mi_gdb_test "-var-show-attributes S" \ + "\\^done,attr=\"noneditable\"" \ + "check attributes of S" + mi_gdb_test "-var-show-attributes R" \ + "\\^done,attr=\"noneditable\"" \ + "check attributes of R" + :*/ + s.i = 56; + /*: mi_varobj_update * [] "-var-update should not list structure varobjs" + :*/ + return 99; + /*: END: reference_to_struct :*/ +} + int main () { reference_update_tests (); base_in_reference_test_main (); reference_to_pointer (); + reference_to_struct (); return 0; } diff --git a/gdb/testsuite/gdb.mi/mi-var-cp.exp b/gdb/testsuite/gdb.mi/mi-var-cp.exp index 0f602769c9..8ccd4b6741 100644 --- a/gdb/testsuite/gdb.mi/mi-var-cp.exp +++ b/gdb/testsuite/gdb.mi/mi-var-cp.exp @@ -44,6 +44,7 @@ mi_prepare_inline_tests $srcfile mi_run_inline_test reference_update mi_run_inline_test base_in_reference mi_run_inline_test reference_to_pointer +mi_run_inline_test reference_to_struct mi_gdb_exit return 0 diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index d0957de304..181d405442 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -1023,6 +1023,13 @@ proc mi_create_varobj { name expression testname } { $testname } +# Deletes the specified NAME. +proc mi_delete_varobj { name testname } { + mi_gdb_test "-var-delete $name" \ + "\\^done,ndeleted=.*" \ + $testname +} + # Updates varobj named NAME and checks that all varobjs in EXPECTED # are reported as updated, and no other varobj is updated. # Assumes that no varobj is out of scope and that no varobj changes diff --git a/gdb/varobj.c b/gdb/varobj.c index dc1c356a0b..f97c090905 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -176,6 +176,8 @@ static struct cleanup *make_cleanup_free_variable (struct varobj *var); static struct type *get_type (struct varobj *var); +static struct type *get_value_type (struct varobj *var); + static struct type *get_type_deref (struct varobj *var); static struct type *get_target_type (struct type *); @@ -1459,6 +1461,37 @@ get_type (struct varobj *var) return type; } +/* Return the type of the value that's stored in VAR, + or that would have being stored there if the + value were accessible. + + This differs from VAR->type in that VAR->type is always + the true type of the expession in the source language. + The return value of this function is the type we're + actually storing in varobj, and using for displaying + the values and for comparing previous and new values. + + For example, top-level references are always stripped. */ +static struct type * +get_value_type (struct varobj *var) +{ + struct type *type; + + if (var->value) + type = value_type (var->value); + else + type = var->type; + + type = check_typedef (type); + + if (TYPE_CODE (type) == TYPE_CODE_REF) + type = get_target_type (type); + + type = check_typedef (type); + + return type; +} + /* This returns the type of the variable, dereferencing references, pointers and references to pointers, too. */ static struct type * @@ -1723,7 +1756,7 @@ varobj_value_is_changeable_p (struct varobj *var) if (CPLUS_FAKE_CHILD (var)) return 0; - type = get_type (var); + type = get_value_type (var); switch (TYPE_CODE (type)) { @@ -2020,7 +2053,7 @@ c_type_of_child (struct varobj *parent, int index) static int c_variable_editable (struct varobj *var) { - switch (TYPE_CODE (get_type (var))) + switch (TYPE_CODE (get_value_type (var))) { case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: -- 2.11.0