--- gdb/valops.c (revision 3175) +++ gdb/valops.c (local) @@ -935,8 +935,7 @@ value_ind (struct value *arg1) if (TYPE_CODE (base_type) == TYPE_CODE_INT) return value_at_lazy (builtin_type_int, (CORE_ADDR) value_as_long (arg1)); - else if (TYPE_CODE (base_type) == TYPE_CODE_PTR - || TYPE_CODE (base_type) == TYPE_CODE_PTR) + else if (TYPE_CODE (base_type) == TYPE_CODE_PTR) { struct type *enc_type; /* We may be pointing to something embedded in a larger object */ --- gdb/value.c (revision 3175) +++ gdb/value.c (local) @@ -1006,7 +1006,7 @@ value_as_address (struct value *val) || TYPE_CODE (value_type (val)) == TYPE_CODE_METHOD) return VALUE_ADDRESS (val); - val = coerce_array_proper (val); + val = coerce_array (val); /* Some architectures (e.g. Harvard), map instruction and data addresses onto a single large unified address space. For @@ -1620,8 +1620,9 @@ coerce_ref (struct value *arg) } struct value * -coerce_array_proper (struct value *arg) +coerce_array (struct value *arg) { + arg = coerce_ref (arg); if (current_language->c_style_arrays && TYPE_CODE (value_type (arg)) == TYPE_CODE_ARRAY) arg = value_coerce_array (arg); @@ -1630,13 +1631,6 @@ coerce_array_proper (struct value *arg) return arg; } - -struct value * -coerce_array (struct value *arg) -{ - return coerce_array_proper (coerce_ref (arg)); -} - struct value * coerce_number (struct value *arg) { --- gdb/value.h (revision 3175) +++ gdb/value.h (local) @@ -224,8 +224,6 @@ extern short *deprecated_value_regnum_ha extern struct value *coerce_ref (struct value *value); -extern struct value *coerce_array_proper (struct value *arg); - /* If ARG is an array, convert it to a pointer. If ARG is an enum, convert it to an integer. If ARG is a function, convert it to a function pointer. --- gdb/varobj.c (revision 3175) +++ gdb/varobj.c (local) @@ -1749,10 +1749,10 @@ varobj_value_is_changeable_p (struct var return r; } -/* Given a value and a type of a variable object, - adjust those value and type to those necessary - for getting childrens of the variable object. - This includes dereferencing top-level reference +/* Given the value and the type of a variable object, + adjust the value and type to those necessary + for getting children of the variable object. + This includes dereferencing top-level references to all types and dereferencing pointers to structures. @@ -1761,29 +1761,18 @@ varobj_value_is_changeable_p (struct var *VALUE can be null as well -- if the parent value is not known. */ static void -adjust_value_for_children_access (struct value **value, +adjust_value_for_child_access (struct value **value, struct type **type) { gdb_assert (type && *type); *type = check_typedef (*type); - /* If the parent is reference, we always strip the - reference when getting children, since in C++, - reference is basically undistinguishable in - usage from a plain variable. */ + /* The type of value stored in varobj, that is passed + to us, is already supposed to be + reference-stripped. */ - if (TYPE_CODE (*type) == TYPE_CODE_REF) - { - struct type *target_type = get_target_type (*type); - if (value && *value) - gdb_value_ind (*value, value); - *type = get_target_type (*type); - } - - /* The 'get_target_type' function call check_typedef on - result, so we can immediately check type code. No - need to call check_typedef here. */ + gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF); /* Pointers to structures are treated just like structures when accessing children. Don't @@ -1799,17 +1788,21 @@ adjust_value_for_children_access (struct *type = target_type; } } + + /* The 'get_target_type' function calls check_typedef on + result, so we can immediately check type code. No + need to call check_typedef here. */ } /* C */ static int c_number_of_children (struct varobj *var) { - struct type *type = var->type; + struct type *type = get_value_type (var); int children = 0; struct type *target; - adjust_value_for_children_access (NULL, &type); + adjust_value_for_child_access (NULL, &type); target = get_target_type (type); switch (TYPE_CODE (type)) @@ -1908,7 +1901,7 @@ c_describe_child (struct varobj *parent, char **cname, struct value **cvalue, struct type **ctype) { struct value *value = parent->value; - struct type *type = get_type (parent); + struct type *type = get_value_type (parent); if (cname) *cname = NULL; @@ -1917,7 +1910,7 @@ c_describe_child (struct varobj *parent, if (ctype) *ctype = NULL; - adjust_value_for_children_access (&value, &type); + adjust_value_for_child_access (&value, &type); switch (TYPE_CODE (type)) { @@ -1965,12 +1958,11 @@ c_describe_child (struct varobj *parent, if (cvalue && value) gdb_value_ind (value, cvalue); - /* The get_target_type function calls check_typedef - on the result. I'm not sure if showing check_typedefed - type for the child as opposed to the declared type is - right. */ + /* Don't use get_target_type because it calls + check_typedef and here, we want to show the true + declared type of the variable. */ if (ctype) - *ctype = get_target_type (type); + *ctype = TYPE_TARGET_TYPE (type); break; @@ -2137,8 +2129,8 @@ cplus_number_of_children (struct varobj if (!CPLUS_FAKE_CHILD (var)) { - type = var->type; - adjust_value_for_children_access (NULL, &type); + type = get_value_type (var); + adjust_value_for_child_access (NULL, &type); if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) || ((TYPE_CODE (type)) == TYPE_CODE_UNION)) @@ -2164,8 +2156,8 @@ cplus_number_of_children (struct varobj { int kids[3]; - type = var->parent->type; - adjust_value_for_children_access (NULL, &type); + type = get_value_type (var->parent); + adjust_value_for_child_access (NULL, &type); cplus_class_num_children (type, kids); if (strcmp (var->name, "public") == 0) @@ -2253,15 +2245,15 @@ cplus_describe_child (struct varobj *par if (CPLUS_FAKE_CHILD (parent)) { value = parent->parent->value; - type = get_type (parent->parent); + type = get_value_type (parent->parent); } else { value = parent->value; - type = get_type (parent); + type = get_value_type (parent); } - adjust_value_for_children_access (&value, &type); + adjust_value_for_child_access (&value, &type); if (TYPE_CODE (type) == TYPE_CODE_STRUCT || TYPE_CODE (type) == TYPE_CODE_STRUCT) @@ -2293,7 +2285,7 @@ cplus_describe_child (struct varobj *par --type_index; if (cname) - *cname = TYPE_FIELD_NAME (type, type_index); + *cname = xstrdup (TYPE_FIELD_NAME (type, type_index)); if (cvalue && value) *cvalue = value_struct_element_index (value, type_index); @@ -2303,9 +2295,9 @@ cplus_describe_child (struct varobj *par } else if (index < TYPE_N_BASECLASSES (type)) { - /* This is baseclass. */ + /* This is a baseclass. */ if (cname) - *cname = TYPE_FIELD_NAME (type, index); + *cname = xstrdup (TYPE_FIELD_NAME (type, index)); if (cvalue && value) { @@ -2361,7 +2353,7 @@ cplus_describe_child (struct varobj *par } if (cname) - *cname = access; + *cname = xstrdup (access); /* Value and type are null here. */ }