Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 10/28] Have expand_symtabs_matching work for already-expanded CUs
Date: Wed, 02 Apr 2025 17:45:09 -0600	[thread overview]
Message-ID: <20250402-search-in-psyms-v2-10-ea91704487cb@tromey.com> (raw)
In-Reply-To: <20250402-search-in-psyms-v2-0-ea91704487cb@tromey.com>

Currently, gdb will search the already-expanded symtabs in one loop,
and then also expand matching symtabs in another loop.  However, this
is somewhat inefficient -- when searching the already-expanded
symtabs, all such symtabs are examined.  However, the various "quick"
implementations already know which subset of symtabs might have a
match.

This changes the contract of expand_symtabs_matching to also call the
callback for an already-expanded symtab.  With this change, the number
of searched symtabs should sometimes be reduced.  This also cuts down
on the amount of redundant code.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998
---
 gdb/dwarf2/read.c | 42 ++++++++++++++++++++++++++++--------------
 gdb/psymtab.c     |  3 ---
 2 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4b971173815f439ad26da4f78c6aadd0cd18446b..f1084530221e82f33efb35f542d6d842fe3df2ab 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1544,6 +1544,23 @@ struct readnow_functions : public dwarf2_base_index_functions
      domain_search_flags domain,
      expand_symtabs_lang_matcher lang_matcher) override
   {
+    dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+    auto_bool_vector marked;
+    dw_expand_symtabs_matching_file_matcher (per_objfile, marked,
+					     file_matcher);
+
+    for (const auto &per_cu : per_objfile->per_bfd->all_units)
+      {
+	QUIT;
+
+	if (per_cu->is_debug_types)
+	  continue;
+	if (!dw2_expand_symtabs_matching_one (per_cu.get (), per_objfile,
+					      marked, file_matcher,
+					      expansion_notify,
+					      lang_matcher))
+	  return false;
+      }
     return true;
   }
 };
@@ -1931,13 +1948,15 @@ dw2_expand_symtabs_matching_one
 	return true;
     }
 
-  bool symtab_was_null = !per_objfile->symtab_set_p (per_cu);
   compunit_symtab *symtab
     = dw2_instantiate_symtab (per_cu, per_objfile, false);
   gdb_assert (symtab != nullptr);
 
-  if (expansion_notify != NULL && symtab_was_null)
-    return expansion_notify (symtab);
+  if (expansion_notify != nullptr)
+    {
+      marked.set (per_cu->index, true);
+      return expansion_notify (symtab);
+    }
 
   return true;
 }
@@ -1969,13 +1988,6 @@ dw_expand_symtabs_matching_file_matcher
 	  continue;
 	}
 
-      /* We only need to look at symtabs not already expanded.  */
-      if (per_objfile->symtab_set_p (per_cu.get ()))
-	{
-	  marked.set (per_cu->index, true);
-	  continue;
-	}
-
       if (per_cu->fnd != nullptr)
 	{
 	  file_and_directory *fnd = per_cu->fnd.get ();
@@ -4211,6 +4223,12 @@ load_full_comp_unit (dwarf2_per_cu *this_cu, dwarf2_per_objfile *per_objfile,
   if (reader.is_dummy ())
     return;
 
+  /* We always need the file names filled in so that
+     expand_symtabs_matching can match filenames.  It's convenient to
+     do this here.  */
+  if (!this_cu->files_read)
+    dw2_get_file_names_reader (reader.cu (), reader.top_level_die ());
+
   reader.read_all_dies ();
 
   /* Save this dwarf2_cu in the per_objfile.  The per_objfile owns it
@@ -14534,10 +14552,6 @@ cooked_index_functions::expand_symtabs_matching
 	{
 	  QUIT;
 
-	  /* No need to consider symbols from expanded CUs.  */
-	  if (per_objfile->symtab_set_p (entry->per_cu))
-	    continue;
-
 	  /* We don't need to consider symbols from some CUs.  */
 	  if (marked.is_set (entry->per_cu->index))
 	    continue;
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 28455ba0bc58990a515f0899a873c9995fb4cca8..d12f8f1c5c18018fe96b0d647f3957dfd0f4d594 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -914,9 +914,6 @@ psymbol_functions::expand_symtabs_matching
     {
       QUIT;
 
-      if (ps->readin_p (objfile))
-	continue;
-
       if (file_matcher)
 	{
 	  bool match;

-- 
2.46.1


  parent reply	other threads:[~2025-04-03  0:01 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-02 23:44 [PATCH v2 00/28] Search symbols via quick API Tom Tromey
2025-04-02 23:45 ` [PATCH v2 01/28] Add another minor hack to cooked_index_entry::full_name Tom Tromey
2025-04-02 23:45 ` [PATCH v2 02/28] Change ada_decode to preserve upper-case in some situations Tom Tromey
2025-04-02 23:45 ` [PATCH v2 03/28] Emit some type declarations in .gdb_index Tom Tromey
2025-04-21  2:50   ` Simon Marchi
2025-04-21 14:50     ` Tom Tromey
2025-04-23  4:11       ` Simon Marchi
2025-04-23 20:54         ` Tom Tromey
2025-04-02 23:45 ` [PATCH v2 04/28] Ada import functions not in index Tom Tromey
2025-04-02 23:45 ` [PATCH v2 05/28] Fix index's handling of DW_TAG_imported_declaration Tom Tromey
2025-04-02 23:45 ` [PATCH v2 06/28] Put all CTF symbols in global scope Tom Tromey
2025-04-02 23:45 ` [PATCH v2 07/28] Restore "ingestion" of .debug_str when writing .debug_names Tom Tromey
2025-04-02 23:45 ` [PATCH v2 08/28] Entries from anon-struct.exp not in cooked index Tom Tromey
2025-04-02 23:45 ` [PATCH v2 09/28] Remove dwarf2_per_cu_data::mark Tom Tromey
2025-04-21  3:09   ` Simon Marchi
2025-04-21 15:38     ` Tom Tromey
2025-04-23  4:12       ` Simon Marchi
2025-04-02 23:45 ` Tom Tromey [this message]
2025-04-23 15:53   ` [PATCH v2 10/28] Have expand_symtabs_matching work for already-expanded CUs Simon Marchi
2025-04-23 20:39     ` Tom Tromey
2025-04-23 20:57       ` Tom Tromey
2025-04-02 23:45 ` [PATCH v2 11/28] Rewrite the .gdb_index reader Tom Tromey
2025-04-23 17:22   ` Simon Marchi
2025-04-23 20:50     ` Tom Tromey
2025-04-24 14:37   ` Pedro Alves
2025-04-02 23:45 ` [PATCH v2 12/28] Convert default_collect_symbol_completion_matches_break_on Tom Tromey
2025-04-02 23:45 ` [PATCH v2 13/28] Convert gdbpy_lookup_static_symbols Tom Tromey
2025-04-02 23:45 ` [PATCH v2 14/28] Convert ada_add_global_exceptions Tom Tromey
2025-04-02 23:45 ` [PATCH v2 15/28] Convert ada_language_defn::collect_symbol_completion_matches Tom Tromey
2025-04-02 23:45 ` [PATCH v2 16/28] Convert ada-lang.c:map_matching_symbols Tom Tromey
2025-04-02 23:45 ` [PATCH v2 17/28] Remove expand_symtabs_matching Tom Tromey
2025-04-02 23:45 ` [PATCH v2 18/28] Simplify basic_lookup_transparent_type Tom Tromey
2025-04-02 23:45 ` [PATCH v2 19/28] Remove objfile::expand_symtabs_for_function Tom Tromey
2025-04-02 23:45 ` [PATCH v2 20/28] Convert linespec.c:iterate_over_all_matching_symtabs Tom Tromey
2025-04-02 23:45 ` [PATCH v2 21/28] Simplify block_lookup_symbol_primary Tom Tromey
2025-04-02 23:45 ` [PATCH v2 22/28] Pass lookup_name_info to block_lookup_symbol_primary Tom Tromey
2025-04-02 23:45 ` [PATCH v2 23/28] Simplify block_lookup_symbol Tom Tromey
2025-04-02 23:45 ` [PATCH v2 24/28] Add best_symbol_tracker Tom Tromey
2025-04-02 23:45 ` [PATCH v2 25/28] Convert lookup_symbol_via_quick_fns Tom Tromey
2025-04-02 23:45 ` [PATCH v2 26/28] Convert lookup_symbol_in_objfile Tom Tromey
2025-04-02 23:45 ` [PATCH v2 27/28] Make dw_expand_symtabs_matching_file_matcher static Tom Tromey
2025-04-23 20:00   ` Simon Marchi
2025-04-23 20:09     ` Tom Tromey
2025-04-23 20:44       ` Tom Tromey
2025-04-02 23:45 ` [PATCH v2 28/28] Remove enter_symbol_lookup Tom Tromey
2025-04-23 20:09 ` [PATCH v2 00/28] Search symbols via quick API Simon Marchi
2025-04-24 21:09   ` Tom Tromey
2025-04-28 14:07 ` Guinevere Larsen
2025-04-28 22:06   ` Tom Tromey
2025-04-29 19:31     ` Guinevere Larsen

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=20250402-search-in-psyms-v2-10-ea91704487cb@tromey.com \
    --to=tom@tromey.com \
    --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