From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22953 invoked by alias); 2 Jun 2010 06:25:36 -0000 Received: (qmail 22927 invoked by uid 22791); 2 Jun 2010 06:25:34 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT,TW_BJ X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.156) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Jun 2010 06:25:29 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o526PDb4002335 ; Wed, 2 Jun 2010 08:25:13 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms1.u-strasbg.fr [IPv6:2001:660:2402:d::10]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o526PDNe006661 ; Wed, 2 Jun 2010 08:25:13 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o526PBU8027710 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) ; Wed, 2 Jun 2010 08:25:12 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'Tom Tromey'" Cc: References: <38685.0063725889$1274473713@news.gmane.org> <002201caf93d$e6ea8190$b4bf84b0$@muller@ics-cnrs.unistra.fr> <34200.8848595016$1274864816@news.gmane.org> <000f01cafe4e$17eccea0$47c66be0$@muller@ics-cnrs.unistra.fr> In-Reply-To: Subject: RE: [RFA-v3] dwarf2read.c: Avoid complaint for char array of unspecified size Date: Wed, 02 Jun 2010 06:25:00 -0000 Message-ID: <001201cb021c$5e5723a0$1b056ae0$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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: 2010-06/txt/msg00036.txt.bz2 > Pierre> + /* Test "long long int", "long int", and "int" objfile > types, > Pierre> + and select the last one having a size above or equal to > the > Pierre> + architecture address size. */ > > I think you should test these in the reverse order: int, then long, > then > long long. This assures you will find the smallest type that matches. > > This patch is ok with that change. Thanks for the approval, I modified as you suggested, even if I don't think that it makes any difference in the chosen integer type... Pierre For the record, here is what I checked in rev 1.390 of dwarf2-read.c: ChangeLog entry: 2010-06-02 Pierre Muller * dwarf2read.c (read_subrange_type): Handle missing base type according to Dwarf-2 specifications. Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.389 diff -u -p -r1.389 dwarf2read.c --- dwarf2read.c 1 Jun 2010 21:34:15 -0000 1.389 +++ dwarf2read.c 2 Jun 2010 06:19:23 -0000 @@ -6131,16 +6131,8 @@ read_subrange_type (struct die_info *die LONGEST high = -1; char *name; LONGEST negative_mask; - + base_type = die_type (die, cu); - if (TYPE_CODE (base_type) == TYPE_CODE_VOID) - { - complaint (&symfile_complaints, - _("DW_AT_type missing from DW_TAG_subrange_type")); - base_type - = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, - 0, NULL, cu->objfile); - } if (cu->language == language_fortran) { @@ -6158,10 +6150,10 @@ read_subrange_type (struct die_info *die attr = dwarf2_attr (die, DW_AT_upper_bound, cu); if (attr) { - if (attr->form == DW_FORM_block1) + if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) { /* GCC encodes arrays with unspecified or dynamic length - with a DW_FORM_block1 attribute. + with a DW_FORM_block1 attribute or a reference attribute. FIXME: GDB does not yet know how to handle dynamic arrays properly, treat them as arrays with unspecified length for now. @@ -6176,6 +6168,54 @@ read_subrange_type (struct die_info *die else high = dwarf2_get_attr_constant_value (attr, 1); } + else + { + attr = dwarf2_attr (die, DW_AT_count, cu); + if (attr) + { + int count = dwarf2_get_attr_constant_value (attr, 1); + high = low + count - 1; + } + } + + /* Dwarf-2 specifications explicitly allows to create subrange types + without specifying a base type. + In that case, the base type must be set to the type of + the lower bound, upper bound or count, in that order, if any of these + three attributes references an object that has a type. + If no base type is found, the Dwarf-2 specifications say that + a signed integer type of size equal to the size of an address should + be used. + For the following C code: `extern char gdb_int [];' + GCC produces an empty range DIE. + FIXME: muller/2010-05-28: Possible references to object for low bound, + high bound or count are not yet handled by this code. + */ + if (TYPE_CODE (base_type) == TYPE_CODE_VOID) + { + struct objfile *objfile = cu->objfile; + struct gdbarch *gdbarch = get_objfile_arch (objfile); + int addr_size = gdbarch_addr_bit (gdbarch) /8; + struct type *int_type = objfile_type (objfile)->builtin_int; + + /* Test "int", "long int", and "long long int" objfile types, + and select the first one having a size above or equal to the + architecture address size. */ + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + else + { + int_type = objfile_type (objfile)->builtin_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + else + { + int_type = objfile_type (objfile)->builtin_long_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + } + } + } negative_mask = (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);