From patchwork Mon Jan 6 20:40:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104198 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 2835C3858C56 for ; Mon, 6 Jan 2025 20:41:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2835C3858C56 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=KaVKEf7g X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 108263858C42 for ; Mon, 6 Jan 2025 20:40:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 108263858C42 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 108263858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d36 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736196040; cv=none; b=iJqtZOUUdtUsVfGQnt7wVVs4tvp7BH2Vfvbfy5D7/NIJvZK02IRtyWHf1+nNu5km1hstg1UGfmP1GFMX8D+XdpQRYzUZ7XmDZ3ETS2p5dfQLHT/zyLXslFbnHW1tNTZusm0EYLC8h7auL/QuqmHsr8OW6X6Rn8EqdzTv/naTnG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736196040; c=relaxed/simple; bh=/HTxYsarZuwsba45iiRHwOU9YTKAvAjp+CBVHYiw5L0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WwId+uCuNzAnFd3OR+yLBygbgd/SLeHurG8FE6g/w0eLDUoeZzfQ0wk11Hs5j7CkaTqHfG7YL0Oiekb28azqXQ9PpPjeaIdhp3WjsNwAzDqI5Ppy2yMixDF68L+A9nCgYoO3icBymZWAWShwOuOF+pT0/co/afDQsDHlrcYBfSU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 108263858C42 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-84a1ce51187so286828139f.1 for ; Mon, 06 Jan 2025 12:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1736196039; x=1736800839; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gX/1Ws1zq0qUIqtETp7aJj28O/H8ALjwWX4N3u0zgaA=; b=KaVKEf7gIaAHTbSoEPtenAjVPHBJMJc6+bGPgYS1xyM/vWaetNifnRoatatTS9PfTf TOBlvUDm3hgdwLmroev64GBl9l7R77Ajywo5gx5xpGmnXv9nkhzECD67m3zAEN+1xWKV 852YKwBdHxFJ78HeKigYMskKnBCEQ9r9pWSg2D85axi93YiJS9bdVZuutmkeyw2LOHsr ntwM9CFJJMV2Iq4yRajAAlXfu3gztrmtqefgvwlRSn1Ya7nT1hqL10Qc53mGAe4tUeC6 6ULQFshMNeFqT8Qe+gN6VSbkDAi7a0S42KE/BQ8uB24E0KYY8Ln5zz8xUL7B1kbSaKTm 32/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736196039; x=1736800839; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gX/1Ws1zq0qUIqtETp7aJj28O/H8ALjwWX4N3u0zgaA=; b=WUNmDZ8Mu1iG/Gv5FiHbfo1MO5GejyeQczqW0CUfoU70z/LjPGgJi8I5jdquSkooD1 2FTDr6Y12Ueu+54fTAIDKHKBh3If3i0SJY/t+7AGxJsQmmjmNRH9tcD2YuT0dZZqhZcL HJ/PAR+xU+w8bs+x402eVV9krm70v8TseF/h+aTHwaeh9D0b1KrpyPO0cV2QL0vdbBvs 79Pc3nPqO1gIzdspODdoLPoTXAYO8oGWoHT5ZZ5PAOZBoPae3MSCU7azVPt+R6/xGNOv 5kK2u6xUjoMyBYsDQh8QglBcPBTBQT4vvR8uyOiNLhXHW7RZLf36EWuvZom0hkgRouVk fafg== X-Gm-Message-State: AOJu0Yxc8Bk/eoh8+teIgwnBe4nyg4qfaxYy4sUY+4k2h+k/m8vhjfC+ Vj7iwZ7VVbwh+6ctofpGpcK8oGS+Bc2hISwfX3Mcn30ROowX4y5ynQUYNWrXL7XWXkahpyuiFLs = X-Gm-Gg: ASbGnctgoldddgD0VagV8LzSlV3DnaY22e9pGnbX5RclgtGIOUGaAlfaDsI00DAj2la 5Tu1rKBnN3T+wjT9Wuct95LH0iGm87o1iMZTVwnLsF8doUsgxNR6cOMOq5pReUCAdemnyvVGiIS xAlarZ6Hpyhoe33hfpjDb+H0SxnftgLZGB7IrorX7nKWglJp3s0pZVyP+ssuMGQt5h62nBlHOCZ HdNum+47GqDLdVZ4qqs0LJ3jgRoDq13k4A12O4yD1ovVioCAxRqX3tnxwGFtibzHMarl9RuKc9y y4Tzf7yIxfd/WtN2dQgT X-Google-Smtp-Source: AGHT+IGtRUPcOQIsCY4NTcS+oWW/5287PkgDknsq6WJtpo6JrNd0ynO01Qq4aSV6CtXOZeR+DRlLRQ== X-Received: by 2002:a05:6e02:3687:b0:3a7:6d14:cc29 with SMTP id e9e14a558f8ab-3c2d18b43aamr541464595ab.1.1736196039234; Mon, 06 Jan 2025 12:40:39 -0800 (PST) Received: from localhost.localdomain (97-118-36-154.hlrn.qwest.net. [97.118.36.154]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3cb713fb0casm80051215ab.47.2025.01.06.12.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 12:40:38 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix crash in DWARF indexer Date: Mon, 6 Jan 2025 13:40:28 -0700 Message-ID: <20250106204028.3587605-1-tromey@adacore.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 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. 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 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 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: 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 + +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"