From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 72B45385624F for ; Mon, 2 Oct 2023 12:50:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72B45385624F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 9130E1F855 for ; Mon, 2 Oct 2023 12:50:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1696251047; 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=1VbS9sT6tV3dXtxB6EC7EtNisvC+xrvMKZU8TEYG+zY=; b=T3ZTxtFue4u2F0zhY79IqYUWoUDRAllD6yOFmcyzpcoNy9OnFGcjEzIjmdNLn7WOFrIr/P ikIu+ctSap6cfBhB6g3abj7YN534Nhpat2i1+Tk3iFAIQhfHg90UrHM2TLu1xypjHrk58D WSk+g76W6Vcq53YIzT4CRHWPYB2HRno= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1696251047; 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=1VbS9sT6tV3dXtxB6EC7EtNisvC+xrvMKZU8TEYG+zY=; b=v9cFFjCLG6zgwvPae1db5SCoc0VJxqkRWttlmtYQRwn6ZddwVvisKE1gkGtfYL727f9cUC EZNeqw3yDuLfoMBQ== 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 7FA6013434 for ; Mon, 2 Oct 2023 12:50:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2GYvHqe8GmVZMgAAMHmgww (envelope-from ) for ; Mon, 02 Oct 2023 12:50:47 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 13/13] [gdb/symtab] Add DW_TAG_inlined_subroutine entries in the cooked index for c++ Date: Mon, 2 Oct 2023 14:50:51 +0200 Message-Id: <20231002125051.29911-14-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231002125051.29911-1-tdevries@suse.de> References: <20231002125051.29911-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 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 List-Id: When running test-case gdb.cp/breakpoint-locs.exp with target board cc-with-dwz, we occasionally run into: ... FAIL: gdb.cp/breakpoint-locs.exp: break N1::C1::baz ... due to the breakpoint having one instead of two locations. By using "maint set worker-threads 0" we can make the test-case fail reliably. In the failing case the inlined_subroutine DIE at 0x1cf has an incorrect parent, and the one at 0x148 has the correct parent: ... [7] ((cooked_index_entry *) 0x7fdf800030b0) name: baz canonical: baz qualified: N1::C1::baz DWARF tag: DW_TAG_inlined_subroutine flags: 0x0 [] DIE offset: 0x148 parent: ((cooked_index_entry *) 0x7fdf80002ed0) [C1] ... [20] ((cooked_index_entry *) 0x7fdf84005340) name: baz canonical: baz qualified: baz DWARF tag: DW_TAG_inlined_subroutine flags: 0x0 [] DIE offset: 0x1cf parent: ((cooked_index_entry *) 0) ... and in the passing case it's the other way around. The corresponding dwarf for 0x148 is this: ... <0>: Abbrev Number: 34 (DW_TAG_partial_unit) <1><14>: Abbrev Number: 37 (DW_TAG_namespace) <15> DW_AT_name : N1 <2><19>: Abbrev Number: 36 (DW_TAG_class_type) <1a> DW_AT_name : C1 <3><20>: Abbrev Number: 32 (DW_TAG_subprogram) <21> DW_AT_external : 1 <21> DW_AT_name : baz <27> DW_AT_linkage_name: _ZN2N12C13bazEv <2b> DW_AT_accessibility: 1 (public) <2c> DW_AT_declaration : 1 <1><2e>: Abbrev Number: 35 (DW_TAG_subprogram) <2f> DW_AT_specification: <0x20> <30> DW_AT_inline : 3 (declared as inline and inlined) <0>: Abbrev Number: 16 (DW_TAG_compile_unit) DW_AT_language : 4 (C++) DW_AT_name : gdb.cp/breakpoint-locs.cc <1><13b>: Abbrev Number: 25 (DW_TAG_subprogram) <13c> DW_AT_specification: <0x115> <13d> DW_AT_low_pc : 0x4004d7 <145> DW_AT_high_pc : 16 <146> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <148> DW_AT_GNU_all_call_sites: 1 <2><148>: Abbrev Number: 24 (DW_TAG_inlined_subroutine) <149> DW_AT_abstract_origin: <0x2e> <14d> DW_AT_low_pc : 0x4004db <155> DW_AT_high_pc : 9 <156> DW_AT_call_file : 1 <157> DW_AT_call_line : 22 ... and for 0x1cf it's similar but in a CU with name gdb.cp/breakpoint-locs-2.cc. In the target board unix case, the test-case passes because both CUs are expanded, because each CU contains the equivalent of 0x2e. But in the dwz case, dwz factored out that DIE into the PU, so that mechanism no longer works. Note that when we used partial symtabs for dwarf we relied on the DW_TAG_inlined_subroutine DIEs, see commit f9b5d5ea18a ("[gdb/symtab] Fix missing breakpoint location for inlined function"). So lets fix this in the same way, by adding DW_TAG_inlined_subroutine entries in the cooked index. Currently the cooked index doesn't add an entry for it because in cooked_indexer::index_dies we don't recurse into the children of a DW_TAG_subprogram for c++: ... case DW_TAG_subprogram: if ((m_language == language_fortran || m_language == language_ada) && this_entry != nullptr) { info_ptr = recurse (reader, info_ptr, this_entry, true); ... Doing so yields entries with incorrect qualified names N1::foo::baz and N1::bar::baz, due to an incorrect parent field. Indeed in DIE terms the parent is foo/bar, but we use the parent field to track encapsulating scopes, so fix this by ignoring the actual DIE parent. That gives us the qualified name baz in both cases. Adding some debugging in handle_deferred_dies shows us why: ... 0x0000000000000015 0x7f9400002eb0 (0x14)^M 0x000000000000001a 0x7f9400002ee0 (0x19)^M 0x000000000000002d 0x7f9400002eb0 (0x14)^M 0x000000000000002e 0x0^M 0x000000000000002f 0x7f9400002f10 (0x2e)^M 0x0000000000000039 0x0^M 0x000000000000010f 0x7f9400002fd0 (0x10e)^M 0x0000000000000121 0x0^M 0x000000000000013c 0x7f9400003060 (0x13b)^M 0x0000000000000148 0x2934520 (deferred)^M 0x0000000000000149 0x7f9400003060 (0x13b)^M 0x000000000000016d 0x0^M 0x000000000000019a 0x7f94080052e0 (0x199)^M 0x00000000000001ac 0x0^M 0x00000000000001c3 0x7f9408005370 (0x1c2)^M 0x00000000000001cf 0x2934520 (deferred)^M 0x00000000000001d0 0x7f9408005370 (0x1c2)^M 0x00000000000001f4 0x0^M Resolve deferred: 0x148 -> 0x2e: no parent^M Resolve deferred: 0x1cf -> 0x2e: no parent^M ... We try to find the find the parent of 0x148, by looking up the parent of 0x2e in m_die_range_map, which is nullptr, in other words no parent. Fix this by recording more parent relations in m_die_range_map, such that we have: ... 0x0000000000000015 0x7fc980002eb0 (0x14)^M 0x000000000000001a 0x7fc980002ee0 (0x19)^M 0x000000000000002d 0x7fc980002eb0 (0x14)^M 0x000000000000002e 0x7fc980002ee0 (0x19)^M 0x000000000000002f 0x7fc980002f10 (0x2e)^M 0x0000000000000039 0x0^M 0x000000000000010f 0x7fc980002fd0 (0x10e)^M 0x0000000000000121 0x0^M 0x000000000000013b 0x7fc980002fd0 (0x10e)^M 0x000000000000013c 0x7fc980003060 (0x13b)^M 0x0000000000000148 0x2934520 (deferred)^M 0x0000000000000149 0x7fc980003060 (0x13b)^M 0x000000000000016d 0x0^M 0x000000000000019a 0x7fc978002eb0 (0x199)^M 0x00000000000001ac 0x0^M 0x00000000000001c2 0x7fc978002eb0 (0x199)^M 0x00000000000001c3 0x7fc978002f40 (0x1c2)^M 0x00000000000001cf 0x2934520 (deferred)^M 0x00000000000001d0 0x7fc978002f40 (0x1c2)^M 0x00000000000001f4 0x0^M Resolve deferred: 0x148 -> 0x2e: 0x19^M Resolve deferred: 0x1cf -> 0x2e: 0x19^M ... This gives us the desired outcome of N1::C1::baz for both DIEs, and makes the test-case pass. Tested on x86_64-linux. --- gdb/dwarf2/read.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 6f218f172a9..a770282c6ae 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16606,6 +16606,8 @@ cooked_indexer::index_dies (cutu_reader *reader, cooked_index_flag flags = IS_STATIC; sect_offset sibling {}; const cooked_index_entry *this_parent_entry = parent_entry; + if (abbrev->tag == DW_TAG_inlined_subroutine) + this_parent_entry = nullptr; info_ptr = scan_attributes (reader->cu->per_cu, reader, info_ptr, info_ptr, abbrev, &name, &linkage_name, &flags, &sibling, &this_parent_entry, @@ -16635,9 +16637,14 @@ cooked_indexer::index_dies (cutu_reader *reader, }); } else - this_entry = m_index_storage->add (this_die, abbrev->tag, flags, - name, this_parent_entry, - m_per_cu); + { + CORE_ADDR addr = form_addr (this_die, reader->cu->per_cu->is_dwz, + reader->cu->per_cu->is_debug_types); + set_parent (addr, addr, this_parent_entry); + this_entry = m_index_storage->add (this_die, abbrev->tag, flags, + name, this_parent_entry, + m_per_cu); + } } if (linkage_name != nullptr) @@ -16698,7 +16705,8 @@ cooked_indexer::index_dies (cutu_reader *reader, case DW_TAG_subprogram: if ((m_language == language_fortran - || m_language == language_ada) + || m_language == language_ada + || m_language == language_cplus) && this_entry != nullptr) { info_ptr = recurse (reader, info_ptr, this_entry, true); -- 2.35.3