This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[no-commit-intention] Naive unnamed fields for main_type [Re: [patch] Fix gdb-gdb.py for flds_bnds copy-pastes]


Hi,

I naively tried first to just use unnamed field which makes everything great:

(gdb) p *type.main_type
$2 =
{name = 0x0,
[...]
 fields[0]:
 #########
  {name = 0x2115978 "i",
[...]
   bitpos = 0},
 cplus_stuff = 0xf33b80}
(gdb) p/r *type.main_type
$3 = {code = TYPE_CODE_STRUCT, [...]
  target_type = 0x0, {fields = 0x21161f0, bounds = 0x21161f0},
                     ########################################
  [...], func_stuff = 0xf33b80}}
(gdb) p type.main_type.fields[0]
                       #########
$4 = {loc = {bitpos = 0, physaddr = 0, [...], name = 0x2115978 "i"}

But apparently we cannot:
$ echo 'struct { int a; struct { int b; }; } s;'|gcc -c -x c - -Wall -std=c90 -pedantic
<stdin>:1:34: warning: ISO C90 doesn’t support unnamed structs/unions [-pedantic]

We could with C99 (after GCC PR c/52182) but GDB sources are still
C90-compatible anyway and C90 spec really does not support unnamed fields.

(Plus everything should be in singular form like the databases do but that is
unrelated.)


Regards,
Jan


--- a/gdb/gdb-gdb.py
+++ b/gdb/gdb-gdb.py
@@ -165,8 +165,8 @@ class StructMainTypePrettyPrinter:
     def struct_field_img(self, fieldno):
         """Return an image of the main_type field number FIELDNO.
         """
-        f = self.val['flds_bnds']['fields'][fieldno]
-        label = "field[%d]:" % fieldno
+        f = self.val['fields'][fieldno]
+        label = "fields[%d]:" % fieldno
         if f['artificial']:
             label += " (artificial)"
         fields = []
@@ -179,7 +179,7 @@ class StructMainTypePrettyPrinter:
     def bounds_img(self):
         """Return an image of the main_type bounds.
         """
-        b = self.val['flds_bnds']['bounds'].dereference()
+        b = self.val['bounds'].dereference()
         low = str(b['low'])
         if b['low_undefined'] != 0:
             low += " (undefined)"
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -582,7 +582,7 @@ struct main_type
 
     } *bounds;
 
-  } flds_bnds;
+  };
 
   /* For types with virtual functions (TYPE_CODE_STRUCT), VPTR_BASETYPE
      is the base class which defined the virtual function table pointer.  
@@ -1029,10 +1029,10 @@ extern void allocate_gnat_aux_type (struct type *);
    type, you need to do TYPE_CODE (check_type (this_type)).  */
 #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
 #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
+#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
 
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
-#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
+#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->bounds
 #define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
 #define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
@@ -1113,7 +1113,7 @@ extern void allocate_gnat_aux_type (struct type *);
 #define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
-#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields[n]
+#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->fields[n]
 #define TYPE_FIELD_TYPE(thistype, n) FIELD_TYPE(TYPE_FIELD(thistype, n))
 #define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n))
 #define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND (TYPE_FIELD (thistype, n))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]