aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarfread.c
diff options
context:
space:
mode:
authorFred Fish <fnf@specifix.com>1991-12-05 05:09:20 +0000
committerFred Fish <fnf@specifix.com>1991-12-05 05:09:20 +0000
commit98618bf78adc8b432655d41f088e66556538e5df (patch)
tree101640dfe2da3fc404fb8412cdfb25cc016ad95d /gdb/dwarfread.c
parent3c7cc3b70e09a3747bf0173a228314bd1c21c3b1 (diff)
downloadgdb-98618bf78adc8b432655d41f088e66556538e5df.zip
gdb-98618bf78adc8b432655d41f088e66556538e5df.tar.gz
gdb-98618bf78adc8b432655d41f088e66556538e5df.tar.bz2
Arrange for enumeration members to be manipulated in source code order,
since they are stored in the Dwarf info in reverse order.
Diffstat (limited to 'gdb/dwarfread.c')
-rw-r--r--gdb/dwarfread.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gdb/dwarfread.c b/gdb/dwarfread.c
index ad6c958..56907f3 100644
--- a/gdb/dwarfread.c
+++ b/gdb/dwarfread.c
@@ -1330,6 +1330,16 @@ DESCRIPTION
Given a pointer to a die information structure for the die which
starts an enumeration, process all the dies that define the members
of the enumeration and return a type pointer for the enumeration.
+
+ Note that the DWARF specification explicitly mandates that enum
+ constants occur in reverse order from the source program order,
+ for "consistency" and because this ordering is easier for many
+ compilers to generate. (Draft 5, sec 3.9.5, Enumeration type
+ Entries)
+
+ Because gdb wants to see the enum members in program source
+ order, we have to ensure that the order gets reversed while
+ we are processing them.
*/
static struct type *
@@ -1406,14 +1416,16 @@ DEFUN(enum_type, (dip), struct dieinfo *dip)
nfields++;
}
}
- /* Now create the vector of fields, and record how big it is. */
+ /* Now create the vector of fields, and record how big it is. This is where
+ we reverse the order, by pulling the members of the list in reverse order
+ from how they were inserted. */
TYPE_NFIELDS (type) = nfields;
TYPE_FIELDS (type) = (struct field *)
obstack_alloc (symbol_obstack, sizeof (struct field) * nfields);
/* Copy the saved-up fields into the field vector. */
- for (n = nfields; list; list = list -> next)
+ for (n = 0; (n < nfields) && (list != NULL); list = list -> next)
{
- TYPE_FIELD (type, --n) = list -> field;
+ TYPE_FIELD (type, n++) = list -> field;
}
return (type);
}