Mark Wielaard 088e48
commit 9d82d0f293c83ff2b8c3ab07065d8454059452be
Mark Wielaard 088e48
Author: mjw <mjw@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Mark Wielaard 088e48
Date:   Fri Jun 28 14:03:58 2013 +0000
Mark Wielaard 088e48
Mark Wielaard 088e48
    Bug 289360 parse_type_DIE confused by DW_TAG_enumeration_type.
Mark Wielaard 088e48
    
Mark Wielaard 088e48
    GCC allows incomplete enums as GNU extension.
Mark Wielaard 088e48
    http://gcc.gnu.org/onlinedocs/gcc/Incomplete-Enums.html
Mark Wielaard 088e48
    These are marked as DW_AT_declaration and won't have a size.
Mark Wielaard 088e48
    They can only be used in declaration or as pointer types.
Mark Wielaard 088e48
    You can't allocate variables or storage using such an enum type.
Mark Wielaard 088e48
    So don't require a size for such enum types.
Mark Wielaard 088e48
    
Mark Wielaard 088e48
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13433 a5019735-40e9-0310-863c-91ae7b9d1cf9
Mark Wielaard 088e48
Mark Wielaard 088e48
diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c
Mark Wielaard 088e48
index 8dbed5a..5e20ff0 100644
Mark Wielaard 088e48
--- a/coregrind/m_debuginfo/readdwarf3.c
Mark Wielaard 088e48
+++ b/coregrind/m_debuginfo/readdwarf3.c
Mark Wielaard 088e48
@@ -2501,6 +2501,7 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents,
Mark Wielaard 088e48
       VG_(memset)(&typeE, 0, sizeof(typeE));
Mark Wielaard 088e48
       typeE.cuOff = posn;
Mark Wielaard 088e48
       typeE.tag   = Te_TyEnum;
Mark Wielaard 088e48
+      Bool is_decl = False;
Mark Wielaard 088e48
       typeE.Te.TyEnum.atomRs
Mark Wielaard 088e48
          = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ptD.enum_type.1", 
Mark Wielaard 088e48
                        ML_(dinfo_free),
Mark Wielaard 088e48
@@ -2519,6 +2520,9 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents,
Mark Wielaard 088e48
          if (attr == DW_AT_byte_size && ctsSzB > 0) {
Mark Wielaard 088e48
             typeE.Te.TyEnum.szB = cts;
Mark Wielaard 088e48
          }
Mark Wielaard 088e48
+         if (attr == DW_AT_declaration) {
Mark Wielaard 088e48
+            is_decl = True;
Mark Wielaard 088e48
+         }
Mark Wielaard 088e48
       }
Mark Wielaard 088e48
 
Mark Wielaard 088e48
       if (!typeE.Te.TyEnum.name)
Mark Wielaard 088e48
@@ -2530,22 +2534,17 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents,
Mark Wielaard 088e48
       if (typeE.Te.TyEnum.szB == 0 
Mark Wielaard 088e48
           /* we must know the size */
Mark Wielaard 088e48
           /* but not for Ada, which uses such dummy
Mark Wielaard 088e48
-             enumerations as helper for gdb ada mode. */
Mark Wielaard 088e48
-          && parser->language != 'A') {
Mark Wielaard 088e48
-         /* GCC has been seen to put an odd DIE like this into
Mark Wielaard 088e48
-            .debug_types:
Mark Wielaard 088e48
-
Mark Wielaard 088e48
-            <1><cb72>: DW_TAG_enumeration_type (in .debug_types)
Mark Wielaard 088e48
-            DW_AT_name        : (indirect string, offset: 0x3374a): exec_direction_kind
Mark Wielaard 088e48
-            DW_AT_declaration : 1	
Mark Wielaard 088e48
-
Mark Wielaard 088e48
-            It isn't clear what this means, but we accept it and
Mark Wielaard 088e48
-            assume that the enum is int-sized.  */
Mark Wielaard 088e48
-         if (cc->is_type_unit) {
Mark Wielaard 088e48
-            typeE.Te.TyEnum.szB = sizeof(int);
Mark Wielaard 088e48
-         } else {
Mark Wielaard 088e48
-            goto bad_DIE;
Mark Wielaard 088e48
-         }
Mark Wielaard 088e48
+             enumerations as helper for gdb ada mode.
Mark Wielaard 088e48
+             Also GCC allows incomplete enums as GNU extension.
Mark Wielaard 088e48
+             http://gcc.gnu.org/onlinedocs/gcc/Incomplete-Enums.html
Mark Wielaard 088e48
+             These are marked as DW_AT_declaration and won't have
Mark Wielaard 088e48
+             a size. They can only be used in declaration or as
Mark Wielaard 088e48
+             pointer types.  You can't allocate variables or storage
Mark Wielaard 088e48
+             using such an enum type. (Also GCC seems to have a bug
Mark Wielaard 088e48
+             that will put such an enumeration_type into a .debug_types
Mark Wielaard 088e48
+             unit which should only contain complete types.) */
Mark Wielaard 088e48
+          && (parser->language != 'A' && !is_decl)) {
Mark Wielaard 088e48
+         goto bad_DIE;
Mark Wielaard 088e48
       }
Mark Wielaard 088e48
 
Mark Wielaard 088e48
       /* On't stack! */