From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15547 invoked by alias); 28 May 2010 10:11:32 -0000 Received: (qmail 15536 invoked by uid 22791); 28 May 2010 10:11:31 -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.158) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 May 2010 10:11:25 +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 o4SABBfv082233 ; Fri, 28 May 2010 12:11:11 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms2.u-strasbg.fr [IPv6:2001:660:2402:d::11]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o4SABBo1082404 ; Fri, 28 May 2010 12:11:11 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o4SABA2Z073532 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) ; Fri, 28 May 2010 12:11:10 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Cc: References: <38685.0063725889$1274473713@news.gmane.org> <002201caf93d$e6ea8190$b4bf84b0$@muller@ics-cnrs.unistra.fr> <34200.8848595016$1274864816@news.gmane.org> In-Reply-To: Subject: [RFA-v3] dwarf2read.c: Avoid complaint for char array of unspecified size Date: Fri, 28 May 2010 10:17:00 -0000 Message-ID: <000f01cafe4e$17eccea0$47c66be0$@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-05/txt/msg00680.txt.bz2 > Pierre> + if (die->num_attrs == 0) > > A DW_TAG_subrange_type might have attributes that we ignore. So, I > think there is no need for a check that is this specific; just > determine > the type according to the above algorithm, and remove the existing > complaint code. > > Tom OK, I tried to follow that route, the tricky part was that we don't really know which objfile type is the same size as an address, but the patch is a bit lengthy... At the same time, I discovered that DW_AT_count was not supported, (maybe no compiler uses that, but it can't hurt to add support for this). Pierre 2010-05-28 Pierre Muller * dwarf2read.c (read_subrange_type): Handle missing base type according to Dwarf-2 specifications. Also handle DW_AT_count attribute. Index: src/gdb/dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.388 diff -u -p -r1.388 dwarf2read.c --- src/gdb/dwarf2read.c 21 May 2010 20:45:19 -0000 1.388 +++ src/gdb/dwarf2read.c 28 May 2010 08:39:58 -0000 @@ -6129,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) { @@ -6156,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. @@ -6174,6 +6168,48 @@ 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_long_long; + + /* Test "long long int", "long int", and "int" objfile types, + and select the last 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; + int_type = objfile_type (objfile)->builtin_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + int_type = objfile_type (objfile)->builtin_int; + 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);