+2006-05-03 Paul Brook <paul@codesourcery.com>
+
+ * gdb/dwarf2read.c (field_info): Add baseclasses.
+ (dwarf2_add_field): Check base classes.
+ (dwarf2_attach_fields_to_type): Ditto.
+
+ * gdb/gnu-v3-abi.c (gnuv3_rtti_type): Check for NULL base_type.
+ (gnuv3_virtual_fn_field): Handle missing base.
+ (gnuv3_baseclass_offset): Handle missing vptr.
+ * gdb/varobj.c (cplus_class_num_children): Call fill_in_vptr_fieldno.
+ (cplus_name_of_child): Ditto.
+ * gdb/eval.c (evaluate_subexp_standard): Ditto.
+ * gdb/dwarf2read.c (read_structure_type): Search for vtable pointer
+ by name in objects built by ARM compiler.
+
+ * gdb/dwarf2read.c (dwarf2_add_member_fn): Calculate virtual function
+ offset for classes without DW_AT_containing_type.
+
2006-04-28 Mark Mitchell <mark@codesourcery.com>
* gdb/mt-tdep.c (mt_register_name): Correct out-of-range logic to
int virtuality;
struct field field;
}
- *fields;
+ *fields, *baseclasses;
- /* Number of fields. */
+ /* Number of fields (including baseclasses). */
int nfields;
/* Number of baseclasses. */
new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
make_cleanup (xfree, new_field);
memset (new_field, 0, sizeof (struct nextfield));
- new_field->next = fip->fields;
- fip->fields = new_field;
+
+ if (die->tag == DW_TAG_inheritance)
+ {
+ new_field->next = fip->baseclasses;
+ fip->baseclasses = new_field;
+ }
+ else
+ {
+ new_field->next = fip->fields;
+ fip->fields = new_field;
+ }
fip->nfields++;
/* Handle accessibility and virtuality of field.
up in the same order in the array in which they were added to the list. */
while (nfields-- > 0)
{
- TYPE_FIELD (type, nfields) = fip->fields->field;
- switch (fip->fields->accessibility)
+ struct nextfield *fieldp;
+
+ if (fip->fields)
+ {
+ fieldp = fip->fields;
+ fip->fields = fieldp->next;
+ }
+ else
+ {
+ fieldp = fip->baseclasses;
+ fip->baseclasses = fieldp->next;
+ }
+
+ TYPE_FIELD (type, nfields) = fieldp->field;
+ switch (fieldp->accessibility)
{
case DW_ACCESS_private:
SET_TYPE_FIELD_PRIVATE (type, nfields);
/* Unknown accessibility. Complain and treat it as public. */
{
complaint (&symfile_complaints, _("unsupported accessibility %d"),
- fip->fields->accessibility);
+ fieldp->accessibility);
}
break;
}
if (nfields < fip->nbaseclasses)
{
- switch (fip->fields->virtuality)
+ switch (fieldp->virtuality)
{
case DW_VIRTUALITY_virtual:
case DW_VIRTUALITY_pure_virtual:
break;
}
}
- fip->fields = fip->fields->next;
}
}
if (attr && DW_UNSND (attr) != 0)
fnp->is_artificial = 1;
- /* Get index in virtual function table if it is a virtual member function. */
+ /* Get index in virtual function table if it is a virtual member
+ function. For GCC, this is an offset in the appropriate
+ virtual table, as specified by DW_AT_containing_type. For
+ everyone else, it is an expression to be evaluated relative
+ to the object address. */
+
attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
- if (attr)
+ if (attr && fnp->fcontext)
{
/* Support the .debug_loc offsets */
if (attr_form_is_block (attr))
dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
fieldname);
}
- }
+ }
+ else if (attr)
+ {
+ /* We only support trivial expressions here. This hack will work
+ for v3 classes, which always start with the vtable pointer. */
+ if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0
+ && DW_BLOCK (attr)->data[0] == DW_OP_deref)
+ {
+ struct dwarf_block blk;
+ blk.size = DW_BLOCK (attr)->size - 1;
+ blk.data = DW_BLOCK (attr)->data + 1;
+ fnp->voffset = decode_locdesc (&blk, cu);
+ if ((fnp->voffset % cu->header.addr_size) != 0)
+ dwarf2_complex_location_expr_complaint ();
+ else
+ fnp->voffset /= cu->header.addr_size;
+ fnp->voffset += 2;
+ fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (die->type, 0));
+ }
+ else
+ dwarf2_complex_location_expr_complaint ();
+ }
}
/* Create the vector of member function fields, and attach it to the type. */
/* Get the type which refers to the base class (possibly this
class itself) which contains the vtable pointer for the current
- class from the DW_AT_containing_type attribute. */
+ class from the DW_AT_containing_type attribute. This use of
+ DW_AT_containing_type is a GNU extension. */
if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
{
}
}
}
+ else if (cu->producer
+ && strncmp (cu->producer,
+ "ARM/Thumb C/C++ Compiler, RVCT", 30) == 0)
+ {
+ /* The ARM compiler does not provide direct indication
+ of the containing type, but the vtable pointer is
+ always named __vptr. */
+
+ int i;
+
+ for (i = TYPE_NFIELDS (type) - 1;
+ i >= TYPE_N_BASECLASSES (type);
+ --i)
+ {
+ if (strcmp (TYPE_FIELD_NAME (type, i), "__vptr") == 0)
+ {
+ TYPE_VPTR_FIELDNO (type) = i;
+ TYPE_VPTR_BASETYPE (type) = type;
+ break;
+ }
+ }
+ }
}
do_cleanups (back_to);
/* Fetch VALUE's virtual table pointer, and tweak it to point at
an instance of our imaginary gdb_gnu_v3_abi_vtable structure. */
- base_type = check_typedef (TYPE_VPTR_BASETYPE (values_type));
+ base_type = TYPE_VPTR_BASETYPE (values_type);
+ if (base_type == NULL)
+ return NULL;
+ base_type = check_typedef (base_type);
if (values_type != base_type)
{
value = value_cast (base_type, value);
multiple inheritance, but it's better than nothing. */
vfn_base = TYPE_VPTR_BASETYPE (type);
+ if (! vfn_base)
+ error (_("Could not find virtual table pointer for class \"%s\"."),
+ TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<unknown>");
+
/* This type may have been defined before its virtual function table
was. If so, fill in the virtual function table entry for the
type now. */
start of whichever baseclass it resides in, as a sanity measure - iff
we have debugging information for that baseclass. */
+ if (TYPE_VPTR_FIELDNO (type) < 0)
+ fill_in_vptr_fieldno (type);
+ if (TYPE_VPTR_FIELDNO (type) < 0)
+ error (_("Could not find virtual table pointer for class \"%s\"."),
+ TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<unknown>");
+
vbasetype = TYPE_VPTR_BASETYPE (type);
- if (TYPE_VPTR_FIELDNO (vbasetype) < 0)
- fill_in_vptr_fieldno (vbasetype);
if (TYPE_VPTR_FIELDNO (vbasetype) >= 0
&& TYPE_FIELD_BITPOS (vbasetype, TYPE_VPTR_FIELDNO (vbasetype)) != 0)