From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id zWofMYng1mIXcRYAWB0awg (envelope-from ) for ; Tue, 19 Jul 2022 12:49:13 -0400 Received: by simark.ca (Postfix, from userid 112) id B9F2A1E5EA; Tue, 19 Jul 2022 12:49:13 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=imu1xk+i; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 476FD1E222 for ; Tue, 19 Jul 2022 12:49:13 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E53853858293 for ; Tue, 19 Jul 2022 16:49:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E53853858293 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658249351; bh=mEHeK801BxnvHxHeyypTe8wq5r9Br3ekiSfJEhzpp4k=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=imu1xk+iMGZ3miimPKJ6TyqfQqAKclyXu47q6IXZUtSPyY3Qapn9IHQYtMcrG4UFg v1hFNrMQGAnpzCfCNLRey0M8l7HvHzQ3B1TMscaVKSBguZK88Pqq6RZda9jluoD7sS kGVf7u/oJ5EDXH/3WEkhjz012Z/xc6KuaoA4ZUkM= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 7ACC63858281 for ; Tue, 19 Jul 2022 16:48:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7ACC63858281 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7EF6433E20; Tue, 19 Jul 2022 16:48:51 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6723B13488; Tue, 19 Jul 2022 16:48:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nUoJGHPg1mLOMgAAMHmgww (envelope-from ); Tue, 19 Jul 2022 16:48:51 +0000 Date: Tue, 19 Jul 2022 18:48:45 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Fix duplicate CUs in all_comp_units Message-ID: <20220719164843.GA31207@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When running test-case gdb.cp/cpexprs-debug-types.exp with target board cc-with-debug-names on a system with gcc 12.1.1 (defaulting to dwarf 5), I run into: ... (gdb) file cpexprs-debug-types^M Reading symbols from cpexprs-debug-types...^M warning: Section .debug_aranges in cpexprs-debug-types has duplicate \ debug_info_offset 0x0, ignoring .debug_aranges.^M gdb/dwarf2/read.h:309: internal-error: set_length: \ Assertion `m_length == length' failed.^M ... The exec contains a .debug_names section, which gdb rejects due to .debug_names containing a list of TUs, while the exec doesn't contain a .debug_types section (which is what you'd expect for dwarf 4). Filed as PR29385. Gdb then falls back onto the cooked index, which calls create_all_comp_units to create all_comp_units. However, the failed index reading left some elements in all_comp_units, so we end up with duplicates in all_comp_units, which causes the misleading complaint and the assert. Fix this by: - asserting at the start of create_all_comp_units that all_comp_units is empty, as we do in create_cus_from_index and create_cus_from_debug_names, and - cleaning up all_comp_units when failing in dwarf2_read_debug_names. Add a similar cleanup in dwarf2_read_gdb_index. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29381 Any comments? Thanks, - Tom [gdb/symtab] Fix duplicate CUs in all_comp_units --- gdb/dwarf2/read.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 143bcfb5374..cfa15e166bb 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2696,7 +2696,10 @@ dwarf2_read_gdb_index /* We can only handle a single .debug_types when we have an index. */ if (per_bfd->types.size () != 1) - return 0; + { + per_bfd->all_comp_units.clear (); + return 0; + } dwarf2_section_info *section = &per_bfd->types[0]; @@ -4701,7 +4704,10 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) /* We can only handle a single .debug_types when we have an index. */ if (per_bfd->types.size () != 1) - return false; + { + per_bfd->all_comp_units.clear (); + return false; + } dwarf2_section_info *section = &per_bfd->types[0]; @@ -7213,6 +7219,7 @@ static void create_all_comp_units (dwarf2_per_objfile *per_objfile) { htab_up types_htab; + gdb_assert (per_objfile->per_bfd->all_comp_units.empty ()); read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info, &per_objfile->per_bfd->abbrev, 0,