From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12350 invoked by alias); 9 Feb 2012 09:32:01 -0000 Received: (qmail 12339 invoked by uid 22791); 9 Feb 2012 09:31:59 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Feb 2012 09:31:46 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q199VOQf009838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 Feb 2012 04:31:24 -0500 Received: from host2.jankratochvil.net (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q199VKKb009481 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 9 Feb 2012 04:31:22 -0500 Date: Thu, 09 Feb 2012 09:32:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [no-commit-intention] Naive unnamed fields for main_type [Re: [patch] Fix gdb-gdb.py for flds_bnds copy-pastes] Message-ID: <20120209093119.GA2722@host2.jankratochvil.net> References: <20120209092727.GA2664@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Disposition: inline In-Reply-To: <20120209092727.GA2664@host2.jankratochvil.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-02/txt/msg00135.txt.bz2 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 :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))