From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id A61443858402 for ; Tue, 14 Sep 2021 11:02:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A61443858402 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-out2.suse.de (Postfix) with ESMTPS id AD7211FDE4; Tue, 14 Sep 2021 11:02:00 +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 925D813D3F; Tue, 14 Sep 2021 11:02:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id FX+pIiiBQGH7eAAAMHmgww (envelope-from ); Tue, 14 Sep 2021 11:02:00 +0000 Subject: [committed][gdb/symtab] Fix CU list in .debug_names for dummy CUs From: Tom de Vries To: gdb-patches@sourceware.org Cc: Simon Marchi , Tom Tromey References: <20210826115901.GA22856@delia> Message-ID: <7964426a-5018-c32f-ef71-880d22c8c69f@suse.de> Date: Tue, 14 Sep 2021 13:01:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210826115901.GA22856@delia> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, OBFU_UNSUB_UL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Tue, 14 Sep 2021 11:02:03 -0000 On 8/26/21 1:59 PM, Tom de Vries wrote: > Hi, > > With current trunk and target board cc-with-debug-names we have: > ... > (gdb) file dw2-ranges-psym^M > Reading symbols from dw2-ranges-psym...^M > warning: Section .debug_names in dw2-ranges-psym has abbreviation_table of \ > size 1 vs. written as 28, ignoring .debug_names.^M > (gdb) set complaints 0^M > (gdb) FAIL: gdb.dwarf2/dw2-ranges-psym.exp: No complaints > ... > > The executable has 8 compilation units: > ... > $ readelf -wi dw2-ranges-psym | grep @ > Compilation Unit @ offset 0x0: > Compilation Unit @ offset 0x2e: > Compilation Unit @ offset 0xa5: > Compilation Unit @ offset 0xc7: > Compilation Unit @ offset 0xd2: > Compilation Unit @ offset 0x145: > Compilation Unit @ offset 0x150: > Compilation Unit @ offset 0x308: > ... > of which the ones at 0xc7 and 0x145 are dummy CUs (that is, they do not > contain a single DIE), which were added by recent commit 5ef670d81fd > "[gdb/testsuite] Add dummy start and end CUs in dwarf assembly". > > The .debug_names section contains this CU table: > ... > [ 0] 0x0 > [ 1] 0x2e > [ 2] 0xa5 > [ 3] 0xd2 > [ 4] 0x150 > [ 5] 0x308 > [ 6] 0x1 > [ 7] 0x0 > ... > The last two entries are incorrect, and the entries for the dummy CUs are > missing. > > The last two entries are incorrect because here in write_debug_names we write > the dimension of the CU list as 8: > ... > /* comp_unit_count - The number of CUs in the CU list. */ > header.append_uint (4, dwarf5_byte_order, > per_objfile->per_bfd->all_comp_units.size () > - per_objfile->per_bfd->tu_stats.nr_tus); > ... > while the actual dimension of the CU list is 6. > > The discrepancy is caused by this code which skips the dummy CUs: > ... > for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i) > { > ... > /* CU of a shared file from 'dwz -m' may be unused by this main > file. It may be referenced from a local scope but in such > case it does not need to be present in .debug_names. */ > if (psymtab == NULL) > continue; > ... > because they have a null partial symtab. > > We can fix this by writing the actual dimension of the CU list, but that still > leaves the dummy CUs out of the CU list. The purpose of having these is to > delimit the end of preceding CUs. > > So, fix this by: > - removing the code that skips the dummy CUs (note that the same change > was done for .gdb_index in commit efba5c2319d '[gdb/symtab] Handle PU > without import in "save gdb-index"'. > - verifying that all units are represented in the CU/TU lists > - using the actual CU list size when writing the dimension of the CU list > (and likewise for the TU list). > > Tested on x86_64-linux with native and target board cc-with-debug-names. > > Any comments? > I've committed this. Thanks, - Tom > [gdb/symtab] Fix CU list in .debug_names for dummy CUs > > --- > gdb/dwarf2/index-write.c | 20 ++++++++------------ > 1 file changed, 8 insertions(+), 12 deletions(-) > > diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c > index 4e00c716d91..0fe2bc4dd05 100644 > --- a/gdb/dwarf2/index-write.c > +++ b/gdb/dwarf2/index-write.c > @@ -1428,16 +1428,10 @@ write_debug_names (dwarf2_per_objfile *per_objfile, > = per_objfile->per_bfd->all_comp_units[i].get (); > partial_symtab *psymtab = per_cu->v.psymtab; > > - /* CU of a shared file from 'dwz -m' may be unused by this main > - file. It may be referenced from a local scope but in such > - case it does not need to be present in .debug_names. */ > - if (psymtab == NULL) > - continue; > - > int &this_counter = per_cu->is_debug_types ? types_counter : counter; > data_buf &this_list = per_cu->is_debug_types ? types_cu_list : cu_list; > > - if (psymtab->user == NULL) > + if (psymtab != nullptr && psymtab->user == nullptr) > nametable.recursively_write_psymbols (objfile, psymtab, psyms_seen, > this_counter); > > @@ -1447,6 +1441,11 @@ write_debug_names (dwarf2_per_objfile *per_objfile, > ++this_counter; > } > > + /* Verify that all units are represented. */ > + gdb_assert (counter == (per_objfile->per_bfd->all_comp_units.size () > + - per_objfile->per_bfd->tu_stats.nr_tus)); > + gdb_assert (types_counter == per_objfile->per_bfd->tu_stats.nr_tus); > + > nametable.build (); > > /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */ > @@ -1481,14 +1480,11 @@ write_debug_names (dwarf2_per_objfile *per_objfile, > header.append_uint (2, dwarf5_byte_order, 0); > > /* comp_unit_count - The number of CUs in the CU list. */ > - header.append_uint (4, dwarf5_byte_order, > - per_objfile->per_bfd->all_comp_units.size () > - - per_objfile->per_bfd->tu_stats.nr_tus); > + header.append_uint (4, dwarf5_byte_order, counter); > > /* local_type_unit_count - The number of TUs in the local TU > list. */ > - header.append_uint (4, dwarf5_byte_order, > - per_objfile->per_bfd->tu_stats.nr_tus); > + header.append_uint (4, dwarf5_byte_order, types_counter); > > /* foreign_type_unit_count - The number of TUs in the foreign TU > list. */ >