From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gcRCFBVnommgWQ0AWB0awg (envelope-from ) for ; Fri, 27 Feb 2026 22:55:01 -0500 Received: by simark.ca (Postfix, from userid 112) id 4C2341E0DD; Fri, 27 Feb 2026 22:55:01 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 580FC1E09A for ; Fri, 27 Feb 2026 22:54:58 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id DDB744BA23E4 for ; Sat, 28 Feb 2026 03:54:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDB744BA23E4 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 142064BA23F6 for ; Sat, 28 Feb 2026 03:54:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 142064BA23F6 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 142064BA23F6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772250871; cv=none; b=LAPhvtZ39rh9axlK0nluOOdEuYyWPQwSwodR3Ec0rKDYYVTZCUryMtfOCGWrsUfSnV04yzoD7XA5+R93lBD6qWHa54Q6ssArgXmcq98zXwrM57GB8GPC/w8r7eN52SmyvBmHZd5B+DtuR4GXg0uiljEmrYC7k6BQ6MzZAZugP+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772250871; c=relaxed/simple; bh=+29IEvNckt/NvoND/SKWVkq0fAxrnIHmRKlFm+YIlM8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Dp2bneHPsoFJFZNZcf9OY180/nYJY2BHLAgaWF5lfTlqoacDFn1dCgF/Duj7tscFmo8ZjqkAL44PQRqt74l4mfDRDFNHrDDQG1xz4U9sU5gKSGO+MFucy37QXvNbHU6C8+KSnw/Ac0vP4OPH4GcC007GDoy7MpMCm8kAAp/+m1U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 142064BA23F6 Received: by simark.ca (Postfix) id B6F391E0F4; Fri, 27 Feb 2026 22:54:28 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v3 7/9] gdb: make expanded_symbols_functions hold compunit symtabs Date: Fri, 27 Feb 2026 22:51:54 -0500 Message-ID: <20260228035425.422765-8-simon.marchi@efficios.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260228035425.422765-1-simon.marchi@efficios.com> References: <20260217195329.3833518-1-simon.marchi@polymtl.ca> <20260228035425.422765-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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~public-inbox=simark.ca@sourceware.org From: Simon Marchi Change the expanded_symbols_functions quick functions type to hold and use a list of compunit symtab to search. Currently, an expanded_symbols_functions instance will search all the compunits in the objfile. This is not efficient if an expanded_symbols_functions instance exists alongside another quick functions object in an objfile, as the compunits belonging to that other object will be unnecessarily searched. And at worst, I think it could be a source of subtle bugs. For instance, if the order of quick functions determine the order in which we want the search to happen (the comment in elf_symfile_read suggests this is the case), then having expanded_symbols_functions search the compunits from other quick functions objects would not respect that ordering. Update the expanded_symbols_functions constructor to accept a vector of compunits and store this vector in a field. Update expanded_symbols_functions methods to use that vector instead of the objfile's compunits. Right now the sole user of expanded_symbols_functions is JIT. Update it to keep a vector of compunits as they are finalized, and pass this vector to the expanded_symbols_functions object. Change-Id: Idf8de18b25fd3f71766166d6f420184af3c26b7e --- gdb/expanded-symbol.c | 16 ++++++++-------- gdb/expanded-symbol.h | 8 ++++++++ gdb/jit.c | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/gdb/expanded-symbol.c b/gdb/expanded-symbol.c index 050608795f93..d885fe33fa84 100644 --- a/gdb/expanded-symbol.c +++ b/gdb/expanded-symbol.c @@ -28,10 +28,10 @@ symtab * expanded_symbols_functions::find_last_source_symtab (objfile *objfile) { - if (objfile->compunit_symtabs.empty ()) + if (m_compunit_symtabs.empty ()) return nullptr; else - return objfile->compunit_symtabs.back ().primary_filetab (); + return m_compunit_symtabs.back ()->primary_filetab (); } /* See expanded-symbol.h. */ @@ -61,15 +61,15 @@ expanded_symbols_functions::search /* This invariant is documented in quick-functions.h. */ gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); - for (compunit_symtab &cu : objfile->compunits ()) + for (compunit_symtab *cu : m_compunit_symtabs) { - if (lang_matcher != nullptr && !lang_matcher (cu.language ())) + if (lang_matcher != nullptr && !lang_matcher (cu->language ())) continue; if (file_matcher != nullptr) { bool matched = false; - for (auto st : cu.filetabs ()) + for (auto st : cu->filetabs ()) { if (file_matcher (st->filename (), false)) { @@ -92,7 +92,7 @@ expanded_symbols_functions::search consult lookup_name and symbol_matcher (if any). This should be okay since i) all symtabs are already expanded and ii) listeners iterate over matching symbols themselves. */ - if (listener != nullptr && !listener (&cu)) + if (listener != nullptr && !listener (cu)) return false; } return true; @@ -104,9 +104,9 @@ symbol * expanded_symbols_functions::find_symbol_by_address (objfile *objfile, CORE_ADDR address) { - for (compunit_symtab &symtab : objfile->compunits ()) + for (compunit_symtab *symtab : m_compunit_symtabs) { - symbol *sym = symtab.symbol_at_address (address); + symbol *sym = symtab->symbol_at_address (address); if (sym != nullptr) return sym; } diff --git a/gdb/expanded-symbol.h b/gdb/expanded-symbol.h index c088d74f7e59..885390ccb124 100644 --- a/gdb/expanded-symbol.h +++ b/gdb/expanded-symbol.h @@ -29,6 +29,11 @@ struct expanded_symbols_functions : public quick_symbol_functions { + explicit expanded_symbols_functions + (std::vector compunit_symtabs) + : m_compunit_symtabs (std::move (compunit_symtabs)) + {} + bool has_symbols (objfile *objfile) override { return true; @@ -86,6 +91,9 @@ struct expanded_symbols_functions : public quick_symbol_functions bool need_fullname) override { } + +private: + std::vector m_compunit_symtabs; }; diff --git a/gdb/jit.c b/gdb/jit.c index 21e8667a7af6..5fa3869316c3 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -513,9 +513,11 @@ jit_symtab_close_impl (struct gdb_symbol_callbacks *cb, ABI). */ } -/* Transform STAB to a proper symtab, and add it it OBJFILE. */ +/* Transform STAB to a proper symtab, and add it it OBJFILE. -static void + Return the created symtab. */ + +static compunit_symtab * finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) { CORE_ADDR begin, end; @@ -653,6 +655,8 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) /* Move just built blockvector over to CUST. */ cust->set_blockvector (std::move (bv)); + + return cust; } /* Called when closing a gdb_objfile. Converts OBJ to a proper @@ -673,10 +677,14 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, objfile->section_offsets.push_back (0); objfile->sect_index_text = 0; objfile->per_bfd->gdbarch = priv_data->gdbarch; - objfile->qf.emplace_front (new expanded_symbols_functions); + + std::vector compunit_symtabs; for (gdb_symtab &symtab : obj->symtabs) - finalize_symtab (&symtab, objfile); + compunit_symtabs.emplace_back (finalize_symtab (&symtab, objfile)); + + objfile->qf.emplace_front (std::make_unique + (std::move (compunit_symtabs))); add_objfile_entry (objfile, priv_data->entry_addr, priv_data->entry.symfile_addr, -- 2.53.0