From patchwork Thu Mar 27 16:14:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 313 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (caibbdcaaahc.dreamhost.com [208.113.200.72]) by wilcox.dreamhost.com (Postfix) with ESMTP id CEC2F3604D6 for ; Thu, 27 Mar 2014 09:14:59 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14314964) id 82F79409B9630; Thu, 27 Mar 2014 09:14:59 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx20.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id 5B62540C1B4A4 for ; Thu, 27 Mar 2014 09:14:59 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; q=dns; s= default; b=hknD3kXZ68+XPbr2mjGo7vALoOCyEds3zVNnv8O5IDnbj5F4lVafg YthLBGVQsAQBg7sAhBMnSrhLHi5s4e6IjauPe4oF/NbadX+/m47mcRaibNIxSZIN WvC7q/ptmHJW3+C36Kd++oK5sbMHRQUgD2kQ+fwWRRAyEfPnUhkmfQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; s=default; bh=tNVTIFWcP9nGrxO1DEpN6DURjNI=; b=Q2anLvRerOxmwO5zIu2RodZKN198 +ff/JHtEpz3A2SfsvWQqMGMxZHVx/HE7/g++Ulp6SPgALK6s+O6dETRcwC2W8UYM yMnyu8dF3viE2kjXHRjSvkwuc3HGGlFp94VhJx6NEX/qQ1Cr2bpDlYIuKzlVP0ko V+vE4NKQIkXeqvA= Received: (qmail 5559 invoked by alias); 27 Mar 2014 16:14:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5542 invoked by uid 89); 27 Mar 2014 16:14:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Mar 2014 16:14:55 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2RGEr79014215 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 27 Mar 2014 12:14:53 -0400 Received: from barimba.redhat.com (ovpn-113-169.phx2.redhat.com [10.3.113.169]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2RGErjL029372; Thu, 27 Mar 2014 12:14:53 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Cc: mjw@redhat.com, Tom Tromey Subject: [PATCH] handle DW_AT_type on an enumeration Date: Thu, 27 Mar 2014 10:14:47 -0600 Message-Id: <1395936887-8173-1-git-send-email-tromey@redhat.com> X-DH-Original-To: gdb@patchwork.siddhesh.in DWARF allows an enumeration type to have a DW_AT_type. GDB doesn't recognize this, but there is a patch to change GCC to emit it, and a DWARF proposal to further allow an enum type with a DW_AT_type to omit the DW_AT_byte_size. This patch changes gdb to implement this. Built and regtested on x86-64 Fedora 20. 2014-03-27 Tom Tromey * dwarf2read.c (read_enumeration_type): Handle DW_AT_type. 2014-03-27 Tom Tromey * gdb.dwarf2/enum-type.exp: New file. --- gdb/ChangeLog | 4 +++ gdb/dwarf2read.c | 22 +++++++++++++ gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.dwarf2/enum-type.exp | 60 ++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/enum-type.exp diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 705dc2d..cc50f63 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13226,6 +13226,14 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) if (name != NULL) TYPE_TAG_NAME (type) = name; + attr = dwarf2_attr (die, DW_AT_type, cu); + if (attr != NULL) + { + struct type *underlying_type = die_type (die, cu); + + TYPE_TARGET_TYPE (type) = underlying_type; + } + attr = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr) { @@ -13247,6 +13255,20 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) /* Finish the creation of this type by using the enum's children. */ update_enumeration_type_from_children (die, type, cu); + /* If this type has an underlying type that is not a stub, then we + may use its attributes. We always use the "unsigned" attribute + in this situation, because ordinarily we guess whether the type + is unsigned -- but the guess can be wrong and the underlying type + can tell us the reality. However, we defer to a local size + attribute if one exists, because this lets the compiler override + the underlying type if needed. */ + if (TYPE_TARGET_TYPE (type) != NULL && !TYPE_STUB (TYPE_TARGET_TYPE (type))) + { + TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)); + if (TYPE_LENGTH (type) == 0) + TYPE_LENGTH (type) = TYPE_LENGTH (TYPE_TARGET_TYPE (type)); + } + return set_die_type (die, type, cu); } diff --git a/gdb/testsuite/gdb.dwarf2/enum-type.exp b/gdb/testsuite/gdb.dwarf2/enum-type.exp new file mode 100644 index 0000000..60457a6 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/enum-type.exp @@ -0,0 +1,60 @@ +# Copyright 2014 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile main.c enum-type-dw.S + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + cu {} { + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_C} + {DW_AT_name enum-type-dw.c} + {DW_AT_comp_dir /tmp} + } { + declare_labels integer_label array_elt_label array_label \ + big_array_label + + integer_label: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name integer} + } + + DW_TAG_enumeration_type { + {DW_AT_name E} + {DW_AT_type :$integer_label} + } { + DW_TAG_enumerator { + {DW_AT_name ONE} + {DW_AT_const_value 1} + } + } + } + } +} + +if { [prepare_for_testing ${testfile}.exp ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +gdb_test "print sizeof(enum E)" " = 4"