From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id B8EE338582B2 for ; Tue, 9 Jan 2024 17:03:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8EE338582B2 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 B8EE338582B2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704819831; cv=none; b=Wtom6/Xo/EfpsqK11hW9DFxEkMyilcYP6eInMu2bP0dwt8AcucIqT5jQhwN4EwjyyJV8tn4KSm9mlaCPL5T44O3TPExWZpYsDAxagoRR1tu46J7oGydOLoxENHSytnvtcsu306eAdecl7cTWXFAKcBFzL2WumUe2a9tx1Dycx3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704819831; c=relaxed/simple; bh=bIgjLg/a6ot12ydDbdikmGkQhzxo9NgOobtQ7JEuhAg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=w6vDyEv5FCsvqX4gHGMDfvvTB1rS0MZsO8iQRCyB+qcy6GhXIcyH5MsgC4mP4601xkm9ifVoTAjWTDzggMRGiSZoX0WbJN+iyeVSnp1NMlHGNGg1QWS8yj6EelEY7U3abRRuBQILwGcKKKsW9BFSVYcXQ1Y7PmrCP0aP1jPTYak= ARC-Authentication-Results: i=1; server2.sourceware.org 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 6BC992219F for ; Tue, 9 Jan 2024 17:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1704819827; 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=kZIe0ZGDlM0EM1Yt3m3cCI7es+ZECdgHMht1VzPBhM0=; b=ARo3W4PCSWSXaXvVdG0eIbL4OYAbCdY+WoH5R7X6DJYhO9uVmhVdaHIAVYlXlcIcsARwJo yx5qNNiN4BVyGUgsQ2sYE9ngu7ydNUmU88crtDgmKpb7IGxcXGXQpYx1hFZeMWekQ6QFai Ov+9oPiHIcxIsxLZMYPf1yGV/SOROFs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1704819827; 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=kZIe0ZGDlM0EM1Yt3m3cCI7es+ZECdgHMht1VzPBhM0=; b=zSeRxCQMBW6aroBXEH+QDON8MbmvCbwfvalYalLO45h6xPserVQov8syR3gA6Khdb3V6F6 pJO6mtSw39kSJ9Cw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1704819827; 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=kZIe0ZGDlM0EM1Yt3m3cCI7es+ZECdgHMht1VzPBhM0=; b=ARo3W4PCSWSXaXvVdG0eIbL4OYAbCdY+WoH5R7X6DJYhO9uVmhVdaHIAVYlXlcIcsARwJo yx5qNNiN4BVyGUgsQ2sYE9ngu7ydNUmU88crtDgmKpb7IGxcXGXQpYx1hFZeMWekQ6QFai Ov+9oPiHIcxIsxLZMYPf1yGV/SOROFs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1704819827; 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=kZIe0ZGDlM0EM1Yt3m3cCI7es+ZECdgHMht1VzPBhM0=; b=zSeRxCQMBW6aroBXEH+QDON8MbmvCbwfvalYalLO45h6xPserVQov8syR3gA6Khdb3V6F6 pJO6mtSw39kSJ9Cw== 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 5593113CB4 for ; Tue, 9 Jan 2024 17:03:47 +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 YOiyE3N8nWUUFwAAD6G6ig (envelope-from ) for ; Tue, 09 Jan 2024 17:03:47 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 3/3] gdb/symtab: Eliminate deferred_entry Date: Tue, 9 Jan 2024 18:04:21 +0100 Message-Id: <20240109170421.4688-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240109170421.4688-1-tdevries@suse.de> References: <20240109170421.4688-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 6BC992219F Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ARo3W4PC; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zSeRxCQM X-Spam-Score: -1.51 X-Spam-Level: X-Spamd-Result: default: False [-1.51 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-12.4 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,T_SCC_BODY_TEXT_LINE 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: Currently cooked_index entry creation is either: - done immediately if the parent_entry is known, or - deferred if the parent_entry is not yet known, and done later while resolving the deferred entries. Instead, create all cooked_index entries immediately, and keep track of which entries have a parent_entry that needs resolving later using the new IS_PARENT_DEFERRED flag. Tested on x86_64-linux. --- gdb/dwarf2/cooked-index.c | 10 +++++--- gdb/dwarf2/cooked-index.h | 53 +++++++++++++++++++++++++++++++++------ gdb/dwarf2/read.c | 35 +++++++++++--------------- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index a4a400e8eae..790df66d948 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -248,7 +248,7 @@ cooked_index_entry::write_scope (struct obstack *storage, cooked_index_entry * cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag, cooked_index_flag flags, const char *name, - const cooked_index_entry *parent_entry, + cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu) { cooked_index_entry *result = create (die_offset, tag, flags, name, @@ -259,7 +259,8 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag, implicit "main" discovery. */ if ((flags & IS_MAIN) != 0) m_main = result; - else if (parent_entry == nullptr + else if ((flags & IS_PARENT_DEFERRED) == 0 + && parent_entry.resolved == nullptr && m_main == nullptr && language_may_use_plain_main (per_cu->lang ()) && strcmp (name, "main") == 0) @@ -638,7 +639,10 @@ cooked_index::dump (gdbarch *arch) gdb_printf (" flags: %s\n", to_string (entry->flags).c_str ()); gdb_printf (" DIE offset: %s\n", sect_offset_str (entry->die_offset)); - if (entry->get_parent () != nullptr) + if ((entry->flags & IS_PARENT_DEFERRED) != 0) + gdb_printf (" parent: deferred (%" PRIx64 ")\n", + entry->get_deferred_parent ()); + else if (entry->get_parent () != nullptr) gdb_printf (" parent: ((cooked_index_entry *) %p) [%s]\n", entry->get_parent (), entry->get_parent ()->name); else diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 0b6e59333da..2f579210da8 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -48,6 +48,7 @@ struct dwarf2_per_cu_data; struct dwarf2_per_bfd; struct index_cache_store_context; +struct cooked_index_entry; /* Flags that describe an entry in the index. */ enum cooked_index_flag_enum : unsigned char @@ -63,9 +64,30 @@ enum cooked_index_flag_enum : unsigned char /* True if this entry is just for the declaration of a type, not the definition. */ IS_TYPE_DECLARATION = 16, + /* True is parent_entry.deferred has a value rather than parent_entry + .resolved. */ + IS_PARENT_DEFERRED = 32, }; DEF_ENUM_FLAGS_TYPE (enum cooked_index_flag_enum, cooked_index_flag); +/* Type representing either a resolved or deferred cooked_index_entry. */ + +union cooked_index_entry_ref +{ + cooked_index_entry_ref (CORE_ADDR deferred_) + { + deferred = deferred_; + } + + cooked_index_entry_ref (const cooked_index_entry *resolved_) + { + resolved = resolved_; + } + + const cooked_index_entry *resolved; + CORE_ADDR deferred; +}; + /* Return a string representation of FLAGS. */ std::string to_string (cooked_index_flag flags); @@ -88,7 +110,7 @@ struct cooked_index_entry : public allocate_on_obstack { cooked_index_entry (sect_offset die_offset_, enum dwarf_tag tag_, cooked_index_flag flags_, const char *name_, - const cooked_index_entry *parent_entry_, + cooked_index_entry_ref parent_entry_, dwarf2_per_cu_data *per_cu_) : name (name_), tag (tag_), @@ -223,13 +245,30 @@ struct cooked_index_entry : public allocate_on_obstack /* Set parent entry to PARENT. */ void set_parent (const cooked_index_entry *parent) { - m_parent_entry = parent; + gdb_assert ((flags & IS_PARENT_DEFERRED) == 0); + m_parent_entry.resolved = parent; + } + + /* Resolve deferred parent entry to PARENT. */ + void resolve_parent (const cooked_index_entry *parent) + { + gdb_assert ((flags & IS_PARENT_DEFERRED) != 0); + flags = flags & ~IS_PARENT_DEFERRED; + m_parent_entry.resolved = parent; } /* Return parent entry. */ const cooked_index_entry *get_parent () const { - return m_parent_entry; + gdb_assert ((flags & IS_PARENT_DEFERRED) == 0); + return m_parent_entry.resolved; + } + + /* Return deferred parent entry. */ + CORE_ADDR get_deferred_parent () const + { + gdb_assert ((flags & IS_PARENT_DEFERRED) != 0); + return m_parent_entry.deferred; } /* The name as it appears in DWARF. This always points into one of @@ -260,7 +299,7 @@ struct cooked_index_entry : public allocate_on_obstack /* The parent entry. This is NULL for top-level entries. Otherwise, it points to the parent entry, such as a namespace or class. */ - const cooked_index_entry *m_parent_entry; + cooked_index_entry_ref m_parent_entry; }; class cooked_index; @@ -283,7 +322,7 @@ class cooked_index_shard cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag, cooked_index_flag flags, const char *name, - const cooked_index_entry *parent_entry, + cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu); /* Install a new fixed addrmap from the given mutable addrmap. */ @@ -334,7 +373,7 @@ class cooked_index_shard enum dwarf_tag tag, cooked_index_flag flags, const char *name, - const cooked_index_entry *parent_entry, + cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu) { return new (&m_storage) cooked_index_entry (die_offset, tag, flags, @@ -399,7 +438,7 @@ class cooked_index_storage cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag, cooked_index_flag flags, const char *name, - const cooked_index_entry *parent_entry, + cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu) { return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 818e0f6e58f..25b53d622a0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4552,16 +4552,6 @@ class cooked_indexer understand this. */ addrmap_mutable m_die_range_map; - /* A single deferred entry. */ - struct deferred_entry - { - sect_offset die_offset; - const char *name; - CORE_ADDR spec_offset; - dwarf_tag tag; - cooked_index_flag flags; - }; - /* The generated DWARF can sometimes have the declaration for a method in a class (or perhaps namespace) scope, with the definition appearing outside this scope... just one of the many @@ -4569,7 +4559,7 @@ class cooked_indexer defer certain entries until the end of scanning, at which point we'll know the containing context of all the DIEs that we might have scanned. This vector stores these deferred entries. */ - std::vector m_deferred_entries; + std::vector m_deferred_entries; }; /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. @@ -16525,17 +16515,21 @@ cooked_indexer::index_dies (cutu_reader *reader, name = nullptr; } - const cooked_index_entry *this_entry = nullptr; + cooked_index_entry *this_entry = nullptr; if (name != nullptr) { if (defer != 0) - m_deferred_entries.push_back ({ - this_die, name, defer, abbrev->tag, flags - }); + { + this_entry + = m_index_storage->add (this_die, abbrev->tag, + flags | IS_PARENT_DEFERRED, name, + defer, m_per_cu); + m_deferred_entries.push_back (this_entry); + } else - this_entry = m_index_storage->add (this_die, abbrev->tag, flags, - name, this_parent_entry, - m_per_cu); + this_entry + = m_index_storage->add (this_die, abbrev->tag, flags, name, + this_parent_entry, m_per_cu); } if (linkage_name != nullptr) @@ -16636,10 +16630,9 @@ cooked_indexer::make_index (cutu_reader *reader) for (const auto &entry : m_deferred_entries) { - void *obj = m_die_range_map.find (entry.spec_offset); + void *obj = m_die_range_map.find (entry->get_deferred_parent ()); cooked_index_entry *parent = static_cast (obj); - m_index_storage->add (entry.die_offset, entry.tag, entry.flags, - entry.name, parent, m_per_cu); + entry->resolve_parent (parent); } } -- 2.35.3