]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/symtab: pass program space to lookup_symtab and iterate_over_symtabs
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 12 Aug 2024 17:46:06 +0000 (13:46 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 27 Sep 2024 18:58:57 +0000 (14:58 -0400)
Make the current program space references bubble up.

In collect_symtabs_from_filename, remove the calls to
set_current_program_space and just pass the relevant pspaces.
This appears safe to do, because nothing in the `collector` callback
cares about the current pspace.

Change-Id: I00a7ed484bfbe5264f01a6abf0d33b51de373cbb
Reviewed-by: Keith Seitz <keiths@redhat.com>
gdb/ada-exp.y
gdb/c-exp.y
gdb/linespec.c
gdb/m2-exp.y
gdb/mi/mi-cmd-disas.c
gdb/mi/mi-symbol-cmds.c
gdb/p-exp.y
gdb/symtab.c
gdb/symtab.h

index b9f84ee0222049e77425de708caf8dd0013676e4..ed8ed443f8299dc330c319c3f6c4b4656d7d4dd7 100644 (file)
@@ -1477,7 +1477,7 @@ block_lookup (const struct block *context, const char *raw_name)
 
   if (context == NULL
       && (syms.empty () || syms[0].symbol->aclass () != LOC_BLOCK))
-    symtab = lookup_symtab (name);
+    symtab = lookup_symtab (current_program_space, name);
   else
     symtab = NULL;
 
index ca411dc0f5b0bacb6830bed66a09d5c2a2816313..645cb59b878142efb06174733bdfe276c897b2ed 100644 (file)
@@ -3087,10 +3087,8 @@ classify_name (struct parser_state *par_state, const struct block *block,
          || is_quoted_name)
        {
          /* See if it's a file name. */
-         struct symtab *symtab;
-
-         symtab = lookup_symtab (copy.c_str ());
-         if (symtab)
+         if (auto symtab = lookup_symtab (current_program_space, copy.c_str ());
+             symtab != nullptr)
            {
              yylval.bval
                = symtab->compunit ()->blockvector ()->static_block ();
index be85074b01d310fe0846c8783f506e9d6dc38364..d5256261eff5c71f82652be02e7a0e0774a80512 100644 (file)
@@ -3733,15 +3733,11 @@ collect_symtabs_from_filename (const char *file,
          if (pspace->executing_startup)
            continue;
 
-         set_current_program_space (pspace);
-         iterate_over_symtabs (file, collector);
+         iterate_over_symtabs (pspace, file, collector);
        }
     }
   else
-    {
-      set_current_program_space (search_pspace);
-      iterate_over_symtabs (file, collector);
-    }
+    iterate_over_symtabs (search_pspace, file, collector);
 
   return collector.release_symtabs ();
 }
index 28005e1a70008bc6331405f3af4ac7082a099f22..c12767533a83aba15a54ff2ded3aa7d8b5d709ab 100644 (file)
@@ -918,8 +918,9 @@ yylex (void)
     std::string tmp = copy_name (yylval.sval);
     struct symbol *sym;
 
-    if (lookup_symtab (tmp.c_str ()))
+    if (lookup_symtab (current_program_space, tmp.c_str ()) != nullptr)
       return BLOCKNAME;
+
     sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
                         SEARCH_VFT, 0).symbol;
     if (sym && sym->aclass () == LOC_BLOCK)
index 99b2ae418172a182631c24bbfce40f793eda5189..a311e25050cbe110d8d905579fca26d20ef24aea 100644 (file)
@@ -18,6 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "arch-utils.h"
+#include "progspace.h"
 #include "target.h"
 #include "value.h"
 #include "mi-cmds.h"
@@ -245,7 +246,7 @@ mi_cmd_disassemble (const char *command, const char *const *argv, int argc)
 
   if (line_seen && file_seen)
     {
-      s = lookup_symtab (file_string);
+      s = lookup_symtab (current_program_space, file_string);
       if (s == NULL)
        error (_("-data-disassemble: Invalid filename."));
       if (!find_line_pc (s, line_num, &start))
index e90055f6011cab59ecf13f9715b1200acb6b1b76..e4d890f3f36f02c65ff351ce794bb58398b4c34e 100644 (file)
@@ -41,7 +41,7 @@ mi_cmd_symbol_list_lines (const char *command, const char *const *argv,
     error (_("-symbol-list-lines: Usage: SOURCE_FILENAME"));
 
   filename = argv[0];
-  s = lookup_symtab (filename);
+  s = lookup_symtab (current_program_space, filename);
 
   if (s == NULL)
     error (_("-symbol-list-lines: Unknown source file name."));
index ad7cd58196f79405d59a778ffc55db01b7403bf2..938d3cf20240cb46e493c954e3558dbf5f170312 100644 (file)
@@ -614,7 +614,7 @@ block       :       BLOCKNAME
                            {
                              std::string copy = copy_name ($1.stoken);
                              struct symtab *tem =
-                                 lookup_symtab (copy.c_str ());
+                                 lookup_symtab (current_program_space, copy.c_str ());
                              if (tem)
                                $$ = (tem->compunit ()->blockvector ()
                                      ->static_block ());
@@ -1520,7 +1520,7 @@ yylex (void)
        no psymtabs (coff, xcoff, or some future change to blow away the
        psymtabs once once symbols are read).  */
     if ((sym && sym->aclass () == LOC_BLOCK)
-       || lookup_symtab (tmp.c_str ()))
+       || lookup_symtab (current_program_space, tmp.c_str ()))
       {
        yylval.ssym.sym.symbol = sym;
        yylval.ssym.sym.block = NULL;
index 3d8dcac63bb0ee891d12a20227031bf756d3be4b..b9ae418d8cda1215465acbff524f27ced325a548 100644 (file)
@@ -700,15 +700,10 @@ iterate_over_some_symtabs (const char *name,
   return false;
 }
 
-/* Check for a symtab of a specific name; first in symtabs, then in
-   psymtabs.  *If* there is no '/' in the name, a match after a '/'
-   in the symtab filename will also work.
-
-   Calls CALLBACK with each symtab that is found.  If CALLBACK returns
-   true, the search stops.  */
+/* See symtab.h.  */
 
 void
-iterate_over_symtabs (const char *name,
+iterate_over_symtabs (program_space *pspace, const char *name,
                      gdb::function_view<bool (symtab *)> callback)
 {
   gdb::unique_xmalloc_ptr<char> real_path;
@@ -721,34 +716,28 @@ iterate_over_symtabs (const char *name,
       gdb_assert (IS_ABSOLUTE_PATH (real_path.get ()));
     }
 
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (iterate_over_some_symtabs (name, real_path.get (),
-                                    objfile->compunit_symtabs, NULL,
-                                    callback))
+  for (objfile *objfile : pspace->objfiles ())
+    if (iterate_over_some_symtabs (name, real_path.get (),
+                                  objfile->compunit_symtabs, nullptr,
+                                  callback))
        return;
-    }
 
   /* Same search rules as above apply here, but now we look thru the
      psymtabs.  */
-
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      if (objfile->map_symtabs_matching_filename (name, real_path.get (),
-                                                 callback))
-       return;
-    }
+  for (objfile *objfile : pspace->objfiles ())
+    if (objfile->map_symtabs_matching_filename (name, real_path.get (),
+                                               callback))
+      return;
 }
 
-/* A wrapper for iterate_over_symtabs that returns the first matching
-   symtab, or NULL.  */
+/* See symtab.h.  */
 
-struct symtab *
-lookup_symtab (const char *name)
+symtab *
+lookup_symtab (program_space *pspace, const char *name)
 {
   struct symtab *result = NULL;
 
-  iterate_over_symtabs (name, [&] (symtab *symtab)
+  iterate_over_symtabs (pspace, name, [&] (symtab *symtab)
     {
       result = symtab;
       return true;
@@ -6317,7 +6306,7 @@ collect_file_symbol_completion_matches (completion_tracker &tracker,
 
   /* Go through symtabs for SRCFILE and check the externs and statics
      for symbols which match.  */
-  iterate_over_symtabs (srcfile, [&] (symtab *s)
+  iterate_over_symtabs (current_program_space, srcfile, [&] (symtab *s)
     {
       add_symtab_completions (s->compunit (),
                              tracker, mode, lookup_name,
index a2cc1ebbe295996b0be48cf1b5b2c2f4047ef240..aa86a80412113d3f2668e8e52db03fbf2499365e 100644 (file)
@@ -2089,9 +2089,9 @@ extern const char multiple_symbols_cancel[];
 
 const char *multiple_symbols_select_mode (void);
 
-/* lookup a symbol table by source file name.  */
+/* Lookup a symbol table in PSPACE by source file name.  */
 
-extern struct symtab *lookup_symtab (const char *);
+extern symtab *lookup_symtab (program_space *pspace, const char *name);
 
 /* An object of this type is passed as the 'is_a_field_of_this'
    argument to lookup_symbol and lookup_symbol_in_language.  */
@@ -2808,9 +2808,15 @@ bool iterate_over_some_symtabs (const char *name,
                                struct compunit_symtab *after_last,
                                gdb::function_view<bool (symtab *)> callback);
 
-void iterate_over_symtabs (const char *name,
-                          gdb::function_view<bool (symtab *)> callback);
+/* Check in PSPACE for a symtab of a specific name; first in symtabs, then in
+   psymtabs.  *If* there is no '/' in the name, a match after a '/' in the
+   symtab filename will also work.
+
+   Call CALLBACK with each symtab that is found.  If CALLBACK returns
+   true, the search stops.  */
 
+void iterate_over_symtabs (program_space *pspace, const char *name,
+                          gdb::function_view<bool (symtab *)> callback);
 
 std::vector<CORE_ADDR> find_pcs_for_symtab_line
     (struct symtab *symtab, int line, const linetable_entry **best_entry);