This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Handle DW_TAG_inheritance out of order
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Thu, 12 Nov 2009 14:08:55 -0500
- Subject: [commit] Handle DW_TAG_inheritance out of order
GDB's internal "struct type" organizes base classes first, followed by
fields, in a single list. This happens to match the way GCC generates
DWARF, but there's nothing in the DWARF-3 standard that says producers
are obligated to put all DW_TAG_inheritance entries before
DW_TAG_member entries. And in fact ARM's RealView compiler does not.
GDB crashes all over the place when it tries to treat field 0 as the
first base class, but field 0 is not even of class type.
(Actually, RealView may reverse the order of fields/baseclasses
entirely, but that's a separate problem...)
This patch builds up the list of baseclasses separately from the list
of fields. Then we attach baseclasses to the struct type before
attaching fields. This fixes a number of GDB crashes when running
tests with RealView.
Tested on arm-none-eabi (RealView and GCC) and on x86_64-linux. No
regressions with GCC. Checked in.
2009-11-12 Paul Brook <paul@codesourcery.com>
Daniel Jacobowitz <dan@codesourcery.com>
* dwarf2read.c (struct field_info): Add baseclasses.
(dwarf2_add_field): Add base classes to a separate list.
(dwarf2_attach_fields_to_type): Merge base classes and fields.
---
gdb/dwarf2read.c | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
Index: gdb-mainline/gdb/dwarf2read.c
===================================================================
--- gdb-mainline.orig/gdb/dwarf2read.c 2009-11-11 06:47:04.000000000 -0800
+++ gdb-mainline/gdb/dwarf2read.c 2009-11-11 09:00:32.000000000 -0800
@@ -639,9 +639,9 @@ struct field_info
int virtuality;
struct field field;
}
- *fields;
+ *fields, *baseclasses;
- /* Number of fields. */
+ /* Number of fields (including baseclasses). */
int nfields;
/* Number of baseclasses. */
@@ -4355,8 +4355,17 @@ dwarf2_add_field (struct field_info *fip
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.
@@ -4579,8 +4588,21 @@ dwarf2_attach_fields_to_type (struct fie
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);
@@ -4597,13 +4619,13 @@ dwarf2_attach_fields_to_type (struct fie
/* 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:
@@ -4611,7 +4633,6 @@ dwarf2_attach_fields_to_type (struct fie
break;
}
}
- fip->fields = fip->fields->next;
}
}
--
Daniel Jacobowitz
CodeSourcery