From patchwork Thu Sep 12 11:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 97485 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18E24385828B for ; Thu, 12 Sep 2024 11:53:53 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id ABF2E3858C98 for ; Thu, 12 Sep 2024 11:52:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABF2E3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ABF2E3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726141971; cv=none; b=rQ2FaBVJZIn5Mo7GV0oYJ5RH+NiWtzf67Kaa7deknFsdzrr2gPxYreIPbS3K1E7ZZWfVDGoZMsCHcGFb45Apt/kBm5FfzqG87SLnToLN+ZWbn+kycRvVU0GrTPTO/Aa9PNTTbri/6uz5eCgU/03KEBBw+6oLcDvWJkF7BE/qd38= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726141971; c=relaxed/simple; bh=c0P18H+ByEu1KHFbMv/QQMAT7yd1/aXs1ZPv0Acvj7M=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=L7NvUQD8JQkraKUIlrUW5/qvsnLbKwCMC1xSQI5IIeoPIx+prelfmb+jbc+tr9KVN3Ug1s++73K0aHJpmAvKwjuEvVRB4rz4AB5DxjIkGAZQ0g1WM4nIwQ/GOcdnY1UoTeQnkEd4Xtg4TO6YNot1bg0Lputc37GgtVJwLAwmKOY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C761621AFB for ; Thu, 12 Sep 2024 11:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1726141967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AQ8Ib3EswzY1YBb/B/xm1AQM6YNDqi35iDWjlPjgnLU=; b=zGpIxOjoqIoQqHUeps9//4jRsv+gB2fRwTkHTkSV7R3YwHEivJiTVX5OP6JhNyG5Xtu9qu sV2FBs+E6UqeBj/bkMdwI2ka94p6kUHxnV4MFTWS4eHDfha6lur/O7hxa7t4O00Z5PxD2d zokoqUDC/iDiOIa1XMN/5hIl9f6gw2s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1726141967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AQ8Ib3EswzY1YBb/B/xm1AQM6YNDqi35iDWjlPjgnLU=; b=ZAo0e+uvi0dz6B4EjfyXoswisRtm1Hmz1oP7jcpHIf9+JleG+Z3UWe6WdxJJEOqFaRr4cc zJZTnWxVD4sNLhAg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1726141967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AQ8Ib3EswzY1YBb/B/xm1AQM6YNDqi35iDWjlPjgnLU=; b=zGpIxOjoqIoQqHUeps9//4jRsv+gB2fRwTkHTkSV7R3YwHEivJiTVX5OP6JhNyG5Xtu9qu sV2FBs+E6UqeBj/bkMdwI2ka94p6kUHxnV4MFTWS4eHDfha6lur/O7hxa7t4O00Z5PxD2d zokoqUDC/iDiOIa1XMN/5hIl9f6gw2s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1726141967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AQ8Ib3EswzY1YBb/B/xm1AQM6YNDqi35iDWjlPjgnLU=; b=ZAo0e+uvi0dz6B4EjfyXoswisRtm1Hmz1oP7jcpHIf9+JleG+Z3UWe6WdxJJEOqFaRr4cc zJZTnWxVD4sNLhAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AD31D13AE5 for ; Thu, 12 Sep 2024 11:52:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2JzkKA/W4mbcTwAAD6G6ig (envelope-from ) for ; Thu, 12 Sep 2024 11:52:47 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 3/5] [gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner" Date: Thu, 12 Sep 2024 13:52:40 +0200 Message-Id: <20240912115242.17062-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240912115242.17062-1-tdevries@suse.de> References: <20240912115242.17062-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org After adding dwarf assembly to test-case gdb.dwarf2/enum-type.exp that adds this debug info: ... <1><11f>: Abbrev Number: 3 (DW_TAG_enumeration_type) <120> DW_AT_specification: <0x130> <2><124>: Abbrev Number: 4 (DW_TAG_enumerator) <125> DW_AT_name : val1 <12a> DW_AT_const_value : 1 <2><12b>: Abbrev Number: 0 <1><12c>: Abbrev Number: 5 (DW_TAG_namespace) <12d> DW_AT_name : ns <2><130>: Abbrev Number: 6 (DW_TAG_enumeration_type) <131> DW_AT_name : e <133> DW_AT_type : <0x118> <137> DW_AT_declaration : 1 ... I run into an assertion failure: ... (gdb) file enum-type^M Reading symbols from enum-type...^M cooked-index.h:214: internal-error: get_parent: \ Assertion `(flags & IS_PARENT_DEFERRED) == 0' failed.^M ... This was reported in PR32160 comment 1. This is a regression since commit 4e417d7bb1c ("Change handling of DW_TAG_enumeration_type in DWARF scanner"). Fix this by reverting the commit. [ Also drop the kfails for PR31900 and PR32158, which are regressions by that same commit. ] That allows us to look at the output of "maint print objfiles", and for val1 we get an entry without parent: ... [27] ((cooked_index_entry *) 0x7fbbb4002ef0) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0x124 parent: ((cooked_index_entry *) 0) ... which is incorrect, as noted in that same comment, but an improvement over the assertion failure, and I don't think that ever worked. This is to be addressed in a follow-up patch. Reverting the commit begs the question: what was it trying to fix in the first place, and do we need a different fix? I've investigated this and filed PR32160 to track this. My guess is that the commit was based on a misunderstand of what we track in cooked_indexer::m_die_range_map. Each DIE has two types of parent DIEs: - a DIE that is the parent as indicated by the tree structure in which DIEs occur, and - a DIE that represent the parent scope. In most cases, these two are the same, but some times they're not. The debug info above demonstrates such a case. The DIE at 0x11f: - has a tree-parent: the DIE representing the CU, and - has a scope-parent: DIE 0x12c representing namespace ns. In cooked_indexer::m_die_range_map, we track scope-parents, and the commit tried to add a tree-parent instead. So, I don't think we need a different fix, and propose we backport the reversal for gdb 15.2. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31900 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32158 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32160 --- gdb/dwarf2/read.c | 16 +++++----- gdb/testsuite/gdb.dwarf2/enum-type-c++.exp | 2 -- gdb/testsuite/gdb.dwarf2/enum-type.exp | 35 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e0dcf940402..bbd6bfbaf45 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16471,12 +16471,6 @@ cooked_indexer::index_dies (cutu_reader *reader, flags &= ~IS_STATIC; flags |= parent_entry->flags & IS_STATIC; } - /* If the parent is an enum, but not an enum class, then use the - grandparent instead. */ - if (this_parent_entry != nullptr - && this_parent_entry->tag == DW_TAG_enumeration_type - && !is_enum_class) - this_parent_entry = this_parent_entry->get_parent (); if (abbrev->tag == DW_TAG_namespace && m_language == language_cplus @@ -16536,7 +16530,15 @@ cooked_indexer::index_dies (cutu_reader *reader, break; case DW_TAG_enumeration_type: - info_ptr = recurse (reader, info_ptr, this_entry, fully); + /* We need to recurse even for an anonymous enumeration. + Which scope we record as the parent scope depends on + whether we're reading an "enum class". If so, we use + the enum itself as the parent, yielding names like + "enum_class::enumerator"; otherwise we inject the + names into our own parent scope. */ + info_ptr = recurse (reader, info_ptr, + is_enum_class ? this_entry : parent_entry, + fully); continue; case DW_TAG_module: diff --git a/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp b/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp index a3dfb4d2f74..8bf737ec506 100644 --- a/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp +++ b/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp @@ -32,7 +32,6 @@ require {string equal [have_index $binfile] ""} set re_ws "\[ \t\]" # Regression test for PR31900. -setup_kfail "gdb/31900" *-*-* set val1 ns::A::val1 gdb_test_lines "maint print objfiles" \ "val1 has a parent" \ @@ -44,7 +43,6 @@ gdb_test_lines "maint print objfiles" \ gdb_test "print $val1" " = $val1" # Regression test for PR32158. -setup_kfail "gdb/32158" *-*-* set val2 ns::ec::val2 gdb_test_lines "maint print objfiles" \ "val2 has correct parent" \ diff --git a/gdb/testsuite/gdb.dwarf2/enum-type.exp b/gdb/testsuite/gdb.dwarf2/enum-type.exp index 394d287738b..b2b3dc6c828 100644 --- a/gdb/testsuite/gdb.dwarf2/enum-type.exp +++ b/gdb/testsuite/gdb.dwarf2/enum-type.exp @@ -65,6 +65,41 @@ Dwarf::assemble $asm_file { } } } + + cu {} { + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_C_plus_plus} + {DW_AT_name tmp.c} + {DW_AT_comp_dir /tmp} + } { + declare_labels integer_label forward + + integer_label: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name int} + } + + DW_TAG_enumeration_type { + {DW_AT_specification :$forward} + } { + DW_TAG_enumerator { + {DW_AT_name val1} + {DW_AT_const_value 1 DW_FORM_sdata} + } + } + + DW_TAG_namespace { + {DW_AT_name ns} + } { + forward: DW_TAG_enumeration_type { + {DW_AT_name e} + {DW_AT_type :$integer_label} + {DW_AT_declaration 1 flag} + } + } + } + } } if { [prepare_for_testing "failed to prepare" ${testfile} \