Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH v2 7/9] gdb: make expanded_symbols_functions hold compunit symtabs
Date: Tue, 17 Feb 2026 14:50:56 -0500	[thread overview]
Message-ID: <20260217195329.3833518-8-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260217195329.3833518-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@polymtl.ca>

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_symtab *> 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<compunit_symtab *> 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_symtab *> 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<expanded_symbols_functions>
+			     (std::move (compunit_symtabs)));
 
   add_objfile_entry (objfile, priv_data->entry_addr,
 		     priv_data->entry.symfile_addr,
-- 
2.53.0


  parent reply	other threads:[~2026-02-17 20:03 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03  6:45 [RFC PATCH 0/8] Make CTF reader build full symtabs, get rid of psymtab simon.marchi
2026-02-03  6:45 ` [RFC PATCH 1/8] gdb/ctf: add debug logging in ctfread.c simon.marchi
2026-02-03 12:40   ` Eli Zaretskii
2026-02-03 16:21     ` Simon Marchi
2026-02-03 16:37       ` Eli Zaretskii
2026-02-03 20:39         ` Simon Marchi
2026-02-03  6:45 ` [RFC PATCH 2/8] gdb/ctf: add unique_ptr types simon.marchi
2026-02-03  6:45 ` [RFC PATCH 3/8] gdb/ctf: editorial renames simon.marchi
2026-02-03  6:45 ` [RFC PATCH 4/8] gdb/ctf: use ctf_per_objfile in ctf_archive_iter_psymtab_data and ctf_context simon.marchi
2026-02-12 17:44   ` Tom Tromey
2026-02-12 18:35     ` Simon Marchi
2026-02-03  6:45 ` [RFC PATCH 5/8] gdb/ctf: check return value of ctf_type_align simon.marchi
2026-02-12 17:49   ` Tom Tromey
2026-02-12 18:37     ` Simon Marchi
2026-02-03  6:45 ` [RFC PATCH 6/8] gdb/ctf: add scoped_time_it in elfctf_build_psymtabs simon.marchi
2026-02-03  6:45 ` [RFC PATCH 7/8] gdb/ctf: don't use psymtabs, create symtabs directly simon.marchi
2026-02-12 17:54   ` Tom Tromey
2026-02-03  6:45 ` [RFC PATCH 8/8] gdb: remove psymtab.{c,h} simon.marchi
2026-02-12 17:58 ` [RFC PATCH 0/8] Make CTF reader build full symtabs, get rid of psymtab Tom Tromey
2026-02-12 18:47   ` Simon Marchi
2026-02-17 19:50 ` [PATCH v2 0/9] " simon.marchi
2026-02-17 19:50   ` [PATCH v2 1/9] gdb/ctf: add debug logging in ctfread.c simon.marchi
2026-02-17 19:50   ` [PATCH v2 2/9] gdb/ctf: add unique_ptr types simon.marchi
2026-02-17 19:50   ` [PATCH v2 3/9] gdb/ctf: editorial renames simon.marchi
2026-02-17 19:50   ` [PATCH v2 4/9] gdb/ctf: use ctf_per_objfile in ctf_archive_iter_psymtab_data and ctf_context simon.marchi
2026-02-17 19:50   ` [PATCH v2 5/9] gdb/ctf: check return value of ctf_type_align simon.marchi
2026-02-17 19:50   ` [PATCH v2 6/9] gdb/ctf: add scoped_time_it in elfctf_build_psymtabs simon.marchi
2026-02-17 19:50   ` simon.marchi [this message]
2026-02-17 19:50   ` [PATCH v2 8/9] gdb/ctf: don't use psymtabs, create symtabs directly simon.marchi
2026-02-17 19:50   ` [PATCH v2 9/9] gdb: remove psymtab.{c,h} simon.marchi
2026-02-28  3:51   ` [PATCH v3 0/9] Make CTF reader build full symtabs, get rid of psymtab Simon Marchi
2026-02-28  3:51     ` [PATCH v3 1/9] gdb/ctf: add debug logging in ctfread.c Simon Marchi
2026-02-28 10:12       ` Eli Zaretskii
2026-02-28 16:23         ` Simon Marchi
2026-02-28  3:51     ` [PATCH v3 2/9] gdb/ctf: add unique_ptr types Simon Marchi
2026-02-28  3:51     ` [PATCH v3 3/9] gdb/ctf: editorial renames Simon Marchi
2026-02-28  3:51     ` [PATCH v3 4/9] gdb/ctf: use ctf_per_objfile in ctf_archive_iter_psymtab_data and ctf_context Simon Marchi
2026-02-28  3:51     ` [PATCH v3 5/9] gdb/ctf: check return value of ctf_type_align Simon Marchi
2026-02-28  3:51     ` [PATCH v3 6/9] gdb/ctf: add scoped_time_it in elfctf_build_psymtabs Simon Marchi
2026-02-28  3:51     ` [PATCH v3 7/9] gdb: make expanded_symbols_functions hold compunit symtabs Simon Marchi
2026-03-04 19:21       ` Tom Tromey
2026-03-04 19:32         ` Tom Tromey
2026-03-09 18:56           ` Simon Marchi
2026-03-09 18:48         ` Simon Marchi
2026-03-10 17:09           ` Tom Tromey
2026-02-28  3:51     ` [PATCH v3 8/9] gdb/ctf: don't use psymtabs, create symtabs directly Simon Marchi
2026-03-04 19:29       ` Tom Tromey
2026-03-09 18:51         ` Simon Marchi
2026-02-28  3:51     ` [PATCH v3 9/9] gdb: remove psymtab.{c,h} Simon Marchi
2026-02-28 10:18       ` Eli Zaretskii
2026-03-04 19:33     ` [PATCH v3 0/9] Make CTF reader build full symtabs, get rid of psymtab Tom Tromey
2026-03-09 18:57       ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260217195329.3833518-8-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox