From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RWOlHSwafWeeDwYAWB0awg (envelope-from ) for ; Tue, 07 Jan 2025 07:12:28 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=qXd0WYLR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=a8zKkcpr; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=p6PorcSt; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=txIcUIqT; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6CC371E0C0; Tue, 7 Jan 2025 07:12:28 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id EC65C1E05C for ; Tue, 7 Jan 2025 07:12:23 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6CB7B3858D29 for ; Tue, 7 Jan 2025 12:12:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CB7B3858D29 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=qXd0WYLR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=a8zKkcpr; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=p6PorcSt; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=txIcUIqT 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 F11283858C66 for ; Tue, 7 Jan 2025 12:10:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F11283858C66 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 F11283858C66 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=1736251847; cv=none; b=bkTeC2ZvTiwxeVsT1/4dcVnx8A3vbA5D4YMTzUfAEJsq5ZQSWlrLOv4QDP4gnDRL8iwKzDkbzWcSTI9n5ApFR+wV04kJZjgHSXiRJtgvQRvr6JNNu59z1vxYxOW3uTZVuy+cd9ioXKuX4P8h4MFAxXstMEQKPwmmPa9jKU2OGjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736251847; c=relaxed/simple; bh=aG4qoMgtkVXvvR5IvvtYddq+BimiKIQjwobVpkBMWHQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=i4eGVuTT0ukNXLxMgIcVSrDL4MVF74uK5/jcQmOBk6RvtN7tZEctO12AtqWcEbkMMyTFb3QMk2RxJhckZrIAiWdpD3KmC3LVdXVLeGFFfYPwS9NEoWYpF97c8fJw1IzrBeGbkepxHf+BiaGm4vngxmszSXCfBGs+squGqSMzOjI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F11283858C66 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 AF08521157; Tue, 7 Jan 2025 12:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1736251846; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqgCBpPD+yKZL9ZmvKEPMh3w1ERGVXjZimXGWT+sdZE=; b=qXd0WYLReANiXgixAbW1aOGYijiF6yw6BVvkQBpIWsSVQv02WDYteVVGJhhbHfG+Ozdhzs wFB3fArfWdBr55OoSvPET4WlY85oU8YJKSTgaA6UpWT0Pk1ScWRUW5G6KW9q364/vlTVAI ZQ+zjor/hqOm8zMunXIptNG7Dlq3mT8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1736251846; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqgCBpPD+yKZL9ZmvKEPMh3w1ERGVXjZimXGWT+sdZE=; b=a8zKkcpruKU9ONcPam85JL8Ulg7JKzDTeMJhQm5ESX1ejsoeA3OR70uHo6tZCrW/293jk3 XXh2VWNlk/VhMBDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=p6PorcSt; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=txIcUIqT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1736251844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqgCBpPD+yKZL9ZmvKEPMh3w1ERGVXjZimXGWT+sdZE=; b=p6PorcStqCvJg/rteT/4W1w599wR1eyRMBHt92Mlns0j6+ha2NYmtO3dm9W9dzPBzL0Xvo bFh9kYmP+wN+/ccQwiv+ds3abHAWKrzw0zH8cu+zRa6/BNLEG8/I/794LxAeSsKRvZ2MQ0 tZGdyu9I+ol87JIfD5u9NURyp2KJdM4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1736251844; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqgCBpPD+yKZL9ZmvKEPMh3w1ERGVXjZimXGWT+sdZE=; b=txIcUIqTfcDAEvcs+rRfjNEGF3Ox5IBic42O2Tpz5sBO9MJULL48c33YuxXAm4w5yR7/ut vFZghmubadtCH/Cg== 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 9333C13A6A; Tue, 7 Jan 2025 12:10:44 +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 FCsZIsQZfWeLCQAAD6G6ig (envelope-from ); Tue, 07 Jan 2025 12:10:44 +0000 Message-ID: <5b9ee29a-a5f8-46e7-bbe6-976633c1b209@suse.de> Date: Tue, 7 Jan 2025 13:10:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix crash in DWARF indexer To: Tom Tromey , gdb-patches@sourceware.org References: <20250106204028.3587605-1-tromey@adacore.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <20250106204028.3587605-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: AF08521157 X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,sourceware.org:url,suse.de:email,suse.de:dkim,suse.de:mid]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action 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~public-inbox=simark.ca@sourceware.org On 1/6/25 21:40, Tom Tromey wrote: > Iain pointed out a crash in the DWARF indexer when run on a certain D > program. The DWARF in this case has a nameless enum class; this > causes an assertion failure. > > This patch arranges to simply ignore such types. The fact that an > enum class is nameless in this case appears to be a compiler bug. > Hi Tom, thanks for fixing this. I've: - applied the patch, - ran the test-case and verified that it failed, then - rebuild and ran the test-case again, and - verified that it passes. Approved-By: Tom de Vries I've got two nits, one in read.c and one in nameless-enum.exp. > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32518 > --- > gdb/dwarf2/read.c | 35 ++++++------ > gdb/testsuite/gdb.dwarf2/nameless-enum.exp | 62 ++++++++++++++++++++++ > 2 files changed, 82 insertions(+), 15 deletions(-) > create mode 100644 gdb/testsuite/gdb.dwarf2/nameless-enum.exp > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index a008f0ee88b..034bba01ad6 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -16814,22 +16814,27 @@ cooked_indexer::index_dies (cutu_reader *reader, > 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. */ > - { > - std::variant - parent_map::addr_type> recurse_parent; > - if (is_enum_class) > - { > - gdb_assert (this_entry != nullptr); > - recurse_parent = this_entry; > - } > - else if (defer != 0) > - recurse_parent = defer; > - else > - recurse_parent = this_parent_entry; > + names into our own parent scope. > > - info_ptr = recurse (reader, info_ptr, recurse_parent, fully); > - } > + Some versions of gdc could emit an "enum class" > + without a name, which is nonsensical. These are > + skipped. */ > + if (!is_enum_class || this_entry != nullptr) > + { > + std::variant + parent_map::addr_type> recurse_parent; > + if (is_enum_class) > + { > + gdb_assert (this_entry != nullptr); > + recurse_parent = this_entry; > + } > + else if (defer != 0) > + recurse_parent = defer; > + else > + recurse_parent = this_parent_entry; > + > + info_ptr = recurse (reader, info_ptr, recurse_parent, fully); > + } > continue; > > case DW_TAG_module: I think that indenting the code makes it harder to read. Also, I think that the comment describing an exception is better added in an if-clause matching the exception condition, rather than appended to the earlier comment. But these may be a personal preferences. Anyway, FWIW I prefer something like this: ... diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a008f0ee88b..3392dfa1aa2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16818,11 +16818,14 @@ cooked_indexer::index_dies (cutu_reader *reader, { std::variant recurse_parent; - if (is_enum_class) + if (is_enum_class && this_entry == nullptr) { - gdb_assert (this_entry != nullptr); - recurse_parent = this_entry; + /* Some versions of gdc could emit an "enum class" + without a name, which is nonsensical. Skip this + DIE. */ } + else if (is_enum_class) + recurse_parent = this_entry; else if (defer != 0) recurse_parent = defer; else ... or: ... diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a008f0ee88b..b512ac84c5c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16809,6 +16809,14 @@ cooked_indexer::index_dies (cutu_reader *reader, break; case DW_TAG_enumeration_type: + if (is_enum_class && this_entry == nullptr) + { + /* Some versions of gdc could emit an "enum class" + without a name, which is nonsensical. Skip this + DIE. */ + continue; + } + /* 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 @@ -16819,10 +16827,7 @@ cooked_indexer::index_dies (cutu_reader *reader, std::variant recurse_parent; if (is_enum_class) - { - gdb_assert (this_entry != nullptr); - recurse_parent = this_entry; - } + recurse_parent = this_entry; else if (defer != 0) recurse_parent = defer; else ... > diff --git a/gdb/testsuite/gdb.dwarf2/nameless-enum.exp b/gdb/testsuite/gdb.dwarf2/nameless-enum.exp > new file mode 100644 > index 00000000000..c2eda994984 > --- /dev/null > +++ b/gdb/testsuite/gdb.dwarf2/nameless-enum.exp > @@ -0,0 +1,62 @@ > +# Copyright 2025 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 . > + > +# Test a nameless "enum class". This is nonsensical but previously > +# made gdb crash. > + > +load_lib dwarf.exp > +require dwarf2_support > + > +standard_testfile main.c nameless-enum.S > + Using nameless-enum.S is not necessary, we can just use: ... standard_testfile main.c .S ... Thanks, - Tom > +set asm_file [standard_output_file $srcfile2] > +Dwarf::assemble $asm_file { > + global srcfile > + > + cu {} { > + DW_TAG_compile_unit { > + {DW_AT_language @DW_LANG_D} > + {DW_AT_name $srcfile} > + {DW_AT_comp_dir /tmp} > + } { > + declare_labels integer_label > + > + 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_type :$integer_label} > + {DW_AT_enum_class 1 DW_FORM_flag} > + } { > + DW_TAG_enumerator { > + {DW_AT_name VALUE} > + {DW_AT_const_value 17 DW_FORM_sdata} > + } > + } > + } > + } > +} > + > +if {[prepare_for_testing "failed to prepare" ${testfile} \ > + [list $srcfile $asm_file] {nodebug}]} { > + return -1 > +} > + > +# The bug was a crash, so just do anything here to verify gdb is still > +# alive. > +gdb_test "print 23" " = 23"