Arrange for enumeration members to be manipulated in source code order,
authorFred Fish <fnf@specifix.com>
Thu, 5 Dec 1991 05:09:20 +0000 (05:09 +0000)
committerFred Fish <fnf@specifix.com>
Thu, 5 Dec 1991 05:09:20 +0000 (05:09 +0000)
since they are stored in the Dwarf info in reverse order.

gdb/ChangeLog
gdb/dwarfread.c

index a5117bb53155b27b4b4aa5a3d61d48ed69fb1a9e..a1cabeb13da633b81f41f839240ff597b93ff447 100644 (file)
@@ -1,3 +1,9 @@
+Wed Dec  4 21:05:30 1991  Fred Fish  (fnf at cygnus.com)
+
+       * dwarfread (enum_type):  Arrange for the order of enumeration
+       members to match the source code order; not the order in the
+       Dwarf information, which is explicitly reverse order.
+
 Wed Dec  4 18:24:39 1991  John Gilmore  (gnu at cygnus.com)
 
        * main.c (input_from_terminal_p):  Check whether GDB has a
index ad6c958772b3a41470b119536b82c1c48554ec67..56907f3b7bbb3dc06f706b6d446ff65b07f1d74b 100644 (file)
@@ -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);
 }
This page took 0.028706 seconds and 4 git commands to generate.