From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7626 invoked by alias); 18 Mar 2011 14:41:09 -0000 Received: (qmail 7616 invoked by uid 22791); 18 Mar 2011 14:41:07 -0000 X-SWARE-Spam-Status: No, hits=-6.9 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; Fri, 18 Mar 2011 14:40:56 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2IEettk029595 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 18 Mar 2011 10:40:55 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2IEesh2011359; Fri, 18 Mar 2011 10:40:54 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p2IEerwX008048; Fri, 18 Mar 2011 10:40:53 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 58A70378CA3; Fri, 18 Mar 2011 08:40:53 -0600 (MDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: RFC: update for GCC PR 47510 Date: Fri, 18 Mar 2011 14:59:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2011-03/txt/msg00918.txt.bz2 I would appreciate comments on this patch. In the absence of comments I plan to check it in. I think this is important for 7.3. There was an earlier thread about this bug: http://sourceware.org/ml/gdb-patches/2011-02/msg00029.html Since then, a different patch has gone into GCC. This new patch puts a linkage name onto the otherwise anonymous struct. This is a minor DWARF extension that we asked for because the other approaches were a pain to implement in GDB. With this new attribute, the patch becomes fairly straightforward. The valops.c change is from the earlier patch. It fixes a latent bug; I'm not sure whether there is any way to trigger it right now. Built and regtested on x86-64 (compile farm). New test case included. This test includes various cases we found while debugging earlier attempts at a patch. Tom 2011-03-18 Tom Tromey * dwarf2read.c (fixup_partial_die): Handle linkage name on otherwise anonymous types. (dwarf2_name): Likewise. * valops.c (value_struct_elt_for_reference): Refine artificial type logic. Call error if j==-1. 2011-03-18 Tom Tromey * gdb.cp/anon-struct.cc: New file. * gdb.cp/anon-struct.exp: New file. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 6a98d57..b48517a 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -9287,6 +9287,25 @@ fixup_partial_die (struct partial_die_info *part_die, || part_die->tag == DW_TAG_union_type)) guess_partial_die_structure_name (part_die, cu); + /* GCC might emit a nameless struct or union that has a linkage + name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ + if (part_die->name == NULL + && (part_die->tag == DW_TAG_structure_type + || part_die->tag == DW_TAG_union_type + || part_die->tag == DW_TAG_class_type) + && part_die->linkage_name != NULL) + { + char *demangled; + + demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); + if (demangled) + { + part_die->name = obsavestring (demangled, strlen (demangled), + &cu->objfile->objfile_obstack); + xfree (demangled); + } + } + part_die->fixup_called = 1; } @@ -11857,7 +11876,11 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) struct attribute *attr; attr = dwarf2_attr (die, DW_AT_name, cu); - if (!attr || !DW_STRING (attr)) + if ((!attr || !DW_STRING (attr)) + && die->tag != DW_TAG_class_type + && die->tag != DW_TAG_interface_type + && die->tag != DW_TAG_structure_type + && die->tag != DW_TAG_union_type) return NULL; switch (die->tag) @@ -11908,9 +11931,36 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) structures or unions. These were of the form "._%d" in GCC 4.1, or simply "" or "" in GCC 4.3 and GCC 4.4. We work around this problem by ignoring these. */ - if (strncmp (DW_STRING (attr), "._", 2) == 0 - || strncmp (DW_STRING (attr), "objfile->objfile_obstack); + DW_STRING_IS_CANONICAL (attr) = 1; + xfree (demangled); + } + } break; default: diff --git a/gdb/testsuite/gdb.cp/anon-struct.cc b/gdb/testsuite/gdb.cp/anon-struct.cc new file mode 100644 index 0000000..468ab47 --- /dev/null +++ b/gdb/testsuite/gdb.cp/anon-struct.cc @@ -0,0 +1,58 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 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 . + */ + +class C { +public: + C() {} + ~C() {} +}; + +typedef struct { + C m; +} t; + +t v; + +namespace X { + class C2 { + public: + C2() {} + }; + + typedef struct { + C2 m; + } t2; + + t2 v2; +} + +template +class C3 { +public: + ~C3() {} +}; + +typedef struct { + C3 m; +} t3; + +t3 v3; + +int main() +{ +} diff --git a/gdb/testsuite/gdb.cp/anon-struct.exp b/gdb/testsuite/gdb.cp/anon-struct.exp new file mode 100644 index 0000000..0afb99a --- /dev/null +++ b/gdb/testsuite/gdb.cp/anon-struct.exp @@ -0,0 +1,31 @@ +# Tests for anonymous union support. +# Copyright 2011 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 . + +set testfile anon-struct +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug c++}] } { + return -1 +} + +gdb_test "ptype t::t" "type = void \\(t \\* const\\)" \ + "print type of t::t" + +gdb_test "ptype X::t2::t2" "type = void \\(X::t2 \\* const\\)" \ + "print type of X::t2::t2" + +gdb_test "ptype t3::~t3" "type = void \\(t3 \\* const\\)" \ + "print type of t3::~t3" diff --git a/gdb/valops.c b/gdb/valops.c index 24c2269..0287092 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3238,25 +3238,32 @@ value_struct_elt_for_reference (struct type *domain, int offset, int ii; j = -1; - for (ii = 0; ii < TYPE_FN_FIELDLIST_LENGTH (t, i); - ++ii) + for (ii = 0; ii < len; ++ii) { /* Skip artificial methods. This is necessary if, for example, the user wants to "print subclass::subclass" with only one user-defined - constructor. There is no ambiguity in this - case. */ + constructor. There is no ambiguity in this case. + We are careful here to allow artificial methods + if they are the unique result. */ if (TYPE_FN_FIELD_ARTIFICIAL (f, ii)) - continue; + { + if (j == -1) + j = ii; + continue; + } /* Desired method is ambiguous if more than one method is defined. */ - if (j != -1) + if (j != -1 && !TYPE_FN_FIELD_ARTIFICIAL (f, j)) error (_("non-unique member `%s' requires " "type instantiation"), name); j = ii; } + + if (j == -1) + error (_("no matching member function")); } if (TYPE_FN_FIELD_STATIC_P (f, j))