From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14181 invoked by alias); 25 Mar 2010 10:22:15 -0000 Received: (qmail 14171 invoked by uid 22791); 25 Mar 2010 10:22:14 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,MSGID_FROM_MTA_HEADER,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from mtagate6.de.ibm.com (HELO mtagate6.de.ibm.com) (195.212.17.166) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 25 Mar 2010 10:22:08 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate6.de.ibm.com (8.13.1/8.13.1) with ESMTP id o2PAM5q5006336 for ; Thu, 25 Mar 2010 10:22:05 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PAM4vX1478838 for ; Thu, 25 Mar 2010 11:22:04 +0100 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o2PAM4nR017275 for ; Thu, 25 Mar 2010 11:22:04 +0100 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id o2PAM3dl017253 for ; Thu, 25 Mar 2010 11:22:03 +0100 Message-Id: <201003251022.o2PAM3dl017253@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Thu, 25 Mar 2010 11:22:03 +0100 Subject: [rfc] Work around invalid G++ DWARF for unnamed aggregates To: gdb-patches@sourceware.org Date: Thu, 25 Mar 2010 10:22:00 -0000 From: "Ulrich Weigand" 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-03/txt/msg00843.txt.bz2 Hello, a couple of tests in gdb.cp/inherit.exp relating to unnamed aggregates have been failing for quite some time for me. One of these is caused by a GCC problem that has recently been fixed (PR debug/41828), where GCC would generate spurious DW_AT_name attributes of the form "._%d" or "", instead of providing no DW_AT_name at all for unnamed entities. It should be easy to work around this problem with older GCC versions by simply ignoring DW_AT_name attributes with such names in dwarf2_name. The patch below implements this. It also fixes a logic bug in completer.c exposed by this change, where in an unnamed struct *every* method was considered to be a constructor (instead of none). However, the test in test_print_anon_union would still fail for me because it tests for "long int b", while I'd see just "long b". Elsewhere, both versions are accepted, but it proved difficult to implement this within the cp_test_ptype_class framework, which doesn't support regular expressions. As this particular test was somewhat of an abuse of that framework (as already mentioned in a comment), I've replaced this by a direct test. Also, an earlier test assumed that the "long" member of a union has the same value as the "int" member. This is not true in general, and in particular not true on big-endian 64-bit systems like ppc64. I've fixed the test to not make any assumptions on the value of the "long" member. Finally, a different test (test_ptype_si) fails for me because G++ 4.1 does not provide *any* reference to the tagless_struct type name in its generated DWARF info for the following source code: typedef struct { int one; int two; } tagless_struct; (If compiled as C instead of C++, we see a DW_TAG_typedef. If compiled with a recent G++, we see "tagless_struct" used as DW_AT_name of the DW_TAG_structure_type.) As the information is just not there, there's no way for GDB to work around the problem. I've XFAILed the test case if that situation is detected. Tested on powerpc64-linux with no regression, fixes: FAIL: gdb.cp/inherit.exp: ptype tagless struct FAIL: gdb.cp/inherit.exp: print variable of type anonymous union FAIL: gdb.cp/inherit.exp: print type of anonymous union // unrecognized line type 1: class_with_anon_union::._0; Does this look reasonable? Bye, Ulrich ChangeLog: * dwarf2read.c (dwarf2_name): Work around GCC bugzilla debug/41828 by ignoring spurious DW_AT_name attributes for unnamed structs or unions. * completer.c (add_struct_fields): Fix inverted logic. testsuite/ChangeLog: * gdb.cp/inherit.exp (test_ptype_si): XFAIL test for GCC versions that do not provide the tagless_struct type name at all. (test_print_anon_union): Do not check value of uninitialized union member. Do not use cp_test_ptype_class, so we can accept "long" as well as "long int". Index: gdb/completer.c =================================================================== RCS file: /cvs/src/src/gdb/completer.c,v retrieving revision 1.36 diff -u -p -r1.36 completer.c --- gdb/completer.c 1 Jan 2010 07:31:30 -0000 1.36 +++ gdb/completer.c 25 Mar 2010 09:37:44 -0000 @@ -401,7 +401,7 @@ add_struct_fields (struct type *type, in computed_type_name = 1; } /* Omit constructors from the completion list. */ - if (type_name && strcmp (type_name, name)) + if (!type_name || strcmp (type_name, name)) { output[*nextp] = xstrdup (name); ++*nextp; Index: gdb/dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.372 diff -u -p -r1.372 dwarf2read.c --- gdb/dwarf2read.c 22 Mar 2010 13:21:39 -0000 1.372 +++ gdb/dwarf2read.c 25 Mar 2010 09:37:48 -0000 @@ -9159,6 +9159,18 @@ dwarf2_name (struct die_info *die, struc /* These tags always have simple identifiers already; no need to canonicalize them. */ return DW_STRING (attr); + case DW_TAG_class_type: + case DW_TAG_interface_type: + case DW_TAG_structure_type: + case DW_TAG_union_type: + /* Some GCC versions emit spurious DW_AT_name attributes for unnamed + 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), "