From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12796 invoked by alias); 1 Apr 2011 21:03:59 -0000 Received: (qmail 12788 invoked by uid 22791); 1 Apr 2011 21:03:58 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_FN,TW_GD,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, 01 Apr 2011 21:03:49 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p31L3nmF005128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 1 Apr 2011 17:03:49 -0400 Received: from host1.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p31L3lch019915 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 1 Apr 2011 17:03:48 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p31L3kcH032601; Fri, 1 Apr 2011 23:03:46 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p31L3k8M032600; Fri, 1 Apr 2011 23:03:46 +0200 Date: Fri, 01 Apr 2011 21:03:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Tom Tromey , Dodji Seketeli Subject: [patch] DWARF-3+ DW_AT_accessibility defaults #3 (GCC PR debug/45124) Message-ID: <20110401210345.GA31785@host1.jankratochvil.net> References: <20110321154428.GA3761@host1.jankratochvil.net> <20110322095904.GA29625@host1.jankratochvil.net> <20110322181620.GA21984@host1.jankratochvil.net> <20110328091943.GA21984@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110328091943.GA21984@host1.jankratochvil.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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-04/txt/msg00020.txt.bz2 Hi, so here is a patch which works for everything but regresses gcc-4.5.x -gdwarf-4, as suggested/allowed by Jakub: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48229#c6 As it has been regression tested enough I will check it in in some time (and definitely for gdb-7.3). FSF GDB HEAD without the patch: -gdwarf-2 -gdwarf-3 -gdwarf-4 gcc-4.4.fsf pass pass pass gcc-4.5.fsf pass pass PASS gcc-4.6.fsf pass FAIL FAIL gcc-4.7.fsf pass FAIL FAIL gcc-4.4.fc13 pass gcc-4.5.fc14 pass gcc-4.6.fc15 FAIL FSF GDB HEAD with the patch: -gdwarf-2 -gdwarf-3 -gdwarf-4 gcc-4.4.fsf pass pass pass gcc-4.5.fsf pass pass FAIL gcc-4.6.fsf pass PASS PASS gcc-4.7.fsf pass PASS PASS gcc-4.4.fc13 pass gcc-4.5.fc14 pass gcc-4.6.fc15 PASS GNU gdb (GDB) 7.2.50.20110401-cvs gcc (GCC) 4.4.6 20110401 (prerelease) gcc (GCC) 4.5.3 20110401 (prerelease) gcc (GCC) 4.6.1 20110401 (prerelease) gcc (GCC) 4.7.0 20110401 (experimental) gcc-4.4.5-2.fc13 gcc-4.5.1-4.fc14 gcc-4.6.0-0.15.fc15 Only x86_64 host was being tested, the results match for both the default arch (-m64) and for explicit -m32 arch. DW_AT_accessibility affects also class's typedefs, these are implemented in GCCs but not in GDB (GDB PR c++/11757). The regression for gcc-4.5.x -gdwarf-3 could be fixed in the next gcc-4.5.x release but no such fix exists now for the filed GCC PR debug/48229. FSF GCCs default to -gdwarf-2; but they always had an explicit -gdwarf-* parameter under this test. Fedora notes: Fedora GCCs were tested only without any -gdwarf-* parameter, Fedora GCCs default to -gdwarf-3. Fedora GDB was not tested for this mail at all. Thanks, Jan gdb/ 2011-04-01 Jan Kratochvil * dwarf2read.c: Include ctype.h. (producer_is_gxx_lt_4_6, dwarf2_default_access_attribute): New functions. (dwarf2_add_field): Fix new_field->accessibility by calling dwarf2_default_access_attribute. Restructure setting accessibility vs. virtuality. (dwarf2_add_member_fn): New variable accessibility. Fix fnp is_private and is_protected by calling dwarf2_default_access_attribute. --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -57,6 +57,7 @@ #include "vec.h" #include "c-lang.h" #include "valprint.h" +#include #include #include "gdb_string.h" @@ -6209,6 +6210,81 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, } } +/* Check for GCC PR debug/45124 fix which is not present in any G++ version up + to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed + during 4.6.0 experimental. */ + +static int +producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) +{ + const char *cs; + int major, minor, release; + + if (cu->producer == NULL) + { + /* For unknown compilers expect their behavior is DWARF version + compliant. + + GCC started to support .debug_types sections by -gdwarf-4 since + gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer + for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 + combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility + interpreted incorrectly by GDB now - GCC PR debug/48229. */ + + return 0; + } + + /* Skip any identifier after "GNU " - such as "C++" or "Java". */ + + if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) + { + /* For non-GCC compilers expect their behavior is DWARF version + compliant. */ + + return 0; + } + cs = &cu->producer[strlen ("GNU ")]; + while (*cs && !isdigit (*cs)) + cs++; + if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) + { + /* Not recognized as GCC. */ + + return 0; + } + + return major < 4 || (major == 4 && minor < 6); +} + +/* Return the default accessibility type if it is not overriden by + DW_AT_accessibility. */ + +static enum dwarf_access_attribute +dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) +{ + if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) + { + /* The default DWARF 2 accessibility for members is public, the default + accessibility for inheritance is private. */ + + if (die->tag != DW_TAG_inheritance) + return DW_ACCESS_public; + else + return DW_ACCESS_private; + } + else + { + /* DWARF 3+ defines the default accessibility a different way. The same + rules apply now for DW_TAG_inheritance as for the members and it only + depends on the container kind. */ + + if (die->parent->tag == DW_TAG_class_type) + return DW_ACCESS_private; + else + return DW_ACCESS_public; + } +} + /* Add an aggregate field to the field list. */ static void @@ -6239,23 +6315,19 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, } fip->nfields++; - /* Handle accessibility and virtuality of field. - The default accessibility for members is public, the default - accessibility for inheritance is private. */ - if (die->tag != DW_TAG_inheritance) - new_field->accessibility = DW_ACCESS_public; - else - new_field->accessibility = DW_ACCESS_private; - new_field->virtuality = DW_VIRTUALITY_none; - attr = dwarf2_attr (die, DW_AT_accessibility, cu); if (attr) new_field->accessibility = DW_UNSND (attr); + else + new_field->accessibility = dwarf2_default_access_attribute (die, cu); if (new_field->accessibility != DW_ACCESS_public) fip->non_public_fields = 1; + attr = dwarf2_attr (die, DW_AT_virtuality, cu); if (attr) new_field->virtuality = DW_UNSND (attr); + else + new_field->virtuality = DW_VIRTUALITY_none; fp = &new_field->field; @@ -6571,6 +6643,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, char *fieldname; struct nextfnfield *new_fnfield; struct type *this_type; + enum dwarf_access_attribute accessibility; if (cu->language == language_ada) error (_("unexpected member function in Ada type")); @@ -6669,16 +6742,17 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, /* Get accessibility. */ attr = dwarf2_attr (die, DW_AT_accessibility, cu); if (attr) + accessibility = DW_UNSND (attr); + else + accessibility = dwarf2_default_access_attribute (die, cu); + switch (accessibility) { - switch (DW_UNSND (attr)) - { - case DW_ACCESS_private: - fnp->is_private = 1; - break; - case DW_ACCESS_protected: - fnp->is_protected = 1; - break; - } + case DW_ACCESS_private: + fnp->is_private = 1; + break; + case DW_ACCESS_protected: + fnp->is_protected = 1; + break; } /* Check for artificial methods. */