[pushed] gdb: make objfile::pspace private

Message ID 20240715135831.14391-1-simon.marchi@efficios.com
State New
Headers
Series [pushed] gdb: make objfile::pspace private |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Simon Marchi July 15, 2024, 1:58 p.m. UTC
  Rename to m_pspace, add getter.  An objfile's pspace never changes, so
no setter is necessary.

Pushed as obvious, since it's kind of straightforward and uninteresting.

Change-Id: If4dfb300cb90dc0fb9776ea704ff92baebb8f626
---
 gdb/ada-lang.c          |  4 ++--
 gdb/ada-tasks.c         |  2 +-
 gdb/annotate.c          |  2 +-
 gdb/auto-load.c         |  4 ++--
 gdb/breakpoint.c        |  2 +-
 gdb/guile/scm-objfile.c |  2 +-
 gdb/linespec.c          | 38 +++++++++++++++++++-------------------
 gdb/objfiles.c          |  6 +++---
 gdb/objfiles.h          |  7 ++++++-
 gdb/printcmd.c          |  4 ++--
 gdb/python/py-objfile.c |  2 +-
 gdb/remote.c            |  2 +-
 gdb/solib-svr4.c        |  6 +++---
 gdb/solib.c             |  2 +-
 gdb/symfile.c           |  6 +++---
 gdb/symtab.c            |  4 ++--
 16 files changed, 49 insertions(+), 44 deletions(-)


base-commit: d21176c014a4696e667b8567df90364939269170
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 46c20576cff8..e2be7f972241 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13884,7 +13884,7 @@  static struct cmd_list_element *show_ada_list;
 static void
 ada_new_objfile_observer (struct objfile *objfile)
 {
-  ada_clear_symbol_cache (objfile->pspace);
+  ada_clear_symbol_cache (objfile->pspace ());
 }
 
 /* This module's 'free_objfile' observer.  */
@@ -13892,7 +13892,7 @@  ada_new_objfile_observer (struct objfile *objfile)
 static void
 ada_free_objfile_observer (struct objfile *objfile)
 {
-  ada_clear_symbol_cache (objfile->pspace);
+  ada_clear_symbol_cache (objfile->pspace ());
 }
 
 /* Charsets known to GNAT.  */
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 83059d720709..119b223caa94 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -1495,7 +1495,7 @@  ada_tasks_clear_pspace_data (program_space *pspace)
 static void
 ada_tasks_new_objfile_observer (objfile *objfile)
 {
-  ada_tasks_clear_pspace_data (objfile->pspace);
+  ada_tasks_clear_pspace_data (objfile->pspace ());
 }
 
 /* The qcs command line flags for the "task apply" commands.  Keep
diff --git a/gdb/annotate.c b/gdb/annotate.c
index 88180295d1d6..c1d4229e28cb 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -457,7 +457,7 @@  annotate_source_line (struct symtab *s, int line, int mid_statement,
 
       /* Update the current symtab and line.  */
       symtab_and_line sal;
-      sal.pspace = s->compunit ()->objfile ()->pspace;
+      sal.pspace = s->compunit ()->objfile ()->pspace ();
       sal.symtab = s;
       sal.line = line;
       set_current_source_symtab_and_line (sal);
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index afc98eb1f588..839be081b3da 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -783,7 +783,7 @@  auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
       /* Add this script to the hash table too so
 	 "info auto-load ${lang}-scripts" can print it.  */
       pspace_info
-	= get_auto_load_pspace_data_for_loading (objfile->pspace);
+	= get_auto_load_pspace_data_for_loading (objfile->pspace ());
       maybe_add_script_file (pspace_info, is_safe, debugfile, debugfile,
 			     language);
 
@@ -1048,7 +1048,7 @@  source_section_scripts (struct objfile *objfile, const char *section_name,
 			const char *start, const char *end)
 {
   auto_load_pspace_info *pspace_info
-    = get_auto_load_pspace_data_for_loading (objfile->pspace);
+    = get_auto_load_pspace_data_for_loading (objfile->pspace ());
 
   for (const char *p = start; p < end; ++p)
     {
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a973518ac5f0..f32883eb3bc3 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8092,7 +8092,7 @@  disable_breakpoints_in_freed_objfile (struct objfile *objfile)
 	  if (loc.shlib_disabled != 0)
 	    continue;
 
-	  if (objfile->pspace != loc.pspace)
+	  if (objfile->pspace () != loc.pspace)
 	    continue;
 
 	  if (loc.loc_type != bp_loc_hardware_breakpoint
diff --git a/gdb/guile/scm-objfile.c b/gdb/guile/scm-objfile.c
index bccf6ba156d7..d6c0559afd3c 100644
--- a/gdb/guile/scm-objfile.c
+++ b/gdb/guile/scm-objfile.c
@@ -250,7 +250,7 @@  gdbscm_objfile_progspace (SCM self)
   objfile_smob *o_smob
     = ofscm_get_valid_objfile_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  return psscm_scm_from_pspace (o_smob->objfile->pspace);
+  return psscm_scm_from_pspace (o_smob->objfile->pspace ());
 }
 
 /* (objfile-pretty-printers <gdb:objfile>) -> list
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 7a1fbc2ebec5..d24d6912e347 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2172,7 +2172,7 @@  convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
       for (const auto &sym : ls->labels.label_symbols)
 	{
 	  struct program_space *pspace
-	    = sym.symbol->symtab ()->compunit ()->objfile ()->pspace;
+	    = sym.symbol->symtab ()->compunit ()->objfile ()->pspace ();
 
 	  if (symbol_to_sal (&sal, state->funfirstline, sym.symbol)
 	      && maybe_add_address (state->addr_set, pspace, sal.pc))
@@ -2194,7 +2194,7 @@  convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
 	  for (const auto &sym : ls->function_symbols)
 	    {
 	      program_space *pspace
-		= sym.symbol->symtab ()->compunit ()->objfile ()->pspace;
+		= sym.symbol->symtab ()->compunit ()->objfile ()->pspace ();
 	      set_current_program_space (pspace);
 
 	      /* Don't skip to the first line of the function if we
@@ -2256,7 +2256,7 @@  convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
 
 	  for (const auto &elem : ls->minimal_symbols)
 	    {
-	      program_space *pspace = elem.objfile->pspace;
+	      program_space *pspace = elem.objfile->pspace ();
 	      set_current_program_space (pspace);
 	      minsym_found (state, elem.objfile, elem.minsym, &sals);
 	    }
@@ -3437,7 +3437,7 @@  lookup_prefix_sym (struct linespec_state *state,
 	{
 	  /* Program spaces that are executing startup should have
 	     been filtered out earlier.  */
-	  program_space *pspace = elt->compunit ()->objfile ()->pspace;
+	  program_space *pspace = elt->compunit ()->objfile ()->pspace ();
 
 	  gdb_assert (!pspace->executing_startup);
 	  set_current_program_space (pspace);
@@ -3459,8 +3459,8 @@  compare_symbols (const block_symbol &a, const block_symbol &b)
 {
   uintptr_t uia, uib;
 
-  uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace;
-  uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace;
+  uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace ();
+  uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace ();
 
   if (uia < uib)
     return true;
@@ -3483,8 +3483,8 @@  compare_msymbols (const bound_minimal_symbol &a, const bound_minimal_symbol &b)
 {
   uintptr_t uia, uib;
 
-  uia = (uintptr_t) a.objfile->pspace;
-  uib = (uintptr_t) a.objfile->pspace;
+  uia = (uintptr_t) a.objfile->pspace ();
+  uib = (uintptr_t) a.objfile->pspace ();
 
   if (uia < uib)
     return true;
@@ -3584,7 +3584,7 @@  find_method (struct linespec_state *self,
 
       /* Program spaces that are executing startup should have
 	 been filtered out earlier.  */
-      pspace = sym->symtab ()->compunit ()->objfile ()->pspace;
+      pspace = sym->symtab ()->compunit ()->objfile ()->pspace ();
       gdb_assert (!pspace->executing_startup);
       set_current_program_space (pspace);
       t = check_typedef (sym->type ());
@@ -3596,7 +3596,7 @@  find_method (struct linespec_state *self,
       if (ix == sym_classes->size () - 1
 	  || (pspace
 	      != (sym_classes->at (ix + 1).symbol->symtab ()
-		  ->compunit ()->objfile ()->pspace)))
+		  ->compunit ()->objfile ()->pspace ())))
 	{
 	  /* If we did not find a direct implementation anywhere in
 	     this program space, consider superclasses.  */
@@ -3963,7 +3963,7 @@  find_label_symbols (struct linespec_state *self,
 	{
 	  fn_sym = elt.symbol;
 	  set_current_program_space
-	    (fn_sym->symtab ()->compunit ()->objfile ()->pspace);
+	    (fn_sym->symtab ()->compunit ()->objfile ()->pspace ());
 	  block = fn_sym->value_block ();
 
 	  find_label_symbols_in_block (block, name, fn_sym, completion_mode,
@@ -3992,7 +3992,7 @@  decode_digits_list_mode (struct linespec_state *self,
       /* The logic above should ensure this.  */
       gdb_assert (elt != NULL);
 
-      program_space *pspace = elt->compunit ()->objfile ()->pspace;
+      program_space *pspace = elt->compunit ()->objfile ()->pspace ();
       set_current_program_space (pspace);
 
       /* Simplistic search just for the list command.  */
@@ -4027,7 +4027,7 @@  decode_digits_ordinary (struct linespec_state *self,
       /* The logic above should ensure this.  */
       gdb_assert (elt != NULL);
 
-      program_space *pspace = elt->compunit ()->objfile ()->pspace;
+      program_space *pspace = elt->compunit ()->objfile ()->pspace ();
       set_current_program_space (pspace);
 
       pcs = find_pcs_for_symtab_line (elt, line, best_entry);
@@ -4153,7 +4153,7 @@  minsym_found (struct linespec_state *self, struct objfile *objfile,
 
   sal.section = msymbol->obj_section (objfile);
 
-  if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
+  if (maybe_add_address (self->addr_set, objfile->pspace (), sal.pc))
     add_sal_to_sals (self, result, &sal, msymbol->natural_name (), 0);
 }
 
@@ -4228,7 +4228,7 @@  search_minsyms_for_name (struct collect_info *info,
     }
   else
     {
-      program_space *pspace = symtab->compunit ()->objfile ()->pspace;
+      program_space *pspace = symtab->compunit ()->objfile ()->pspace ();
 
       if (search_pspace == NULL || pspace == search_pspace)
 	{
@@ -4322,13 +4322,13 @@  add_matching_symbols_to_info (const char *name,
 	    { return info->add_symbol (bsym); });
 	  search_minsyms_for_name (info, lookup_name, pspace, NULL);
 	}
-      else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace)
+      else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace ())
 	{
 	  int prev_len = info->result.symbols->size ();
 
 	  /* Program spaces that are executing startup should have
 	     been filtered out earlier.  */
-	  program_space *elt_pspace = elt->compunit ()->objfile ()->pspace;
+	  program_space *elt_pspace = elt->compunit ()->objfile ()->pspace ();
 	  gdb_assert (!elt_pspace->executing_startup);
 	  set_current_program_space (elt_pspace);
 	  iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT,
@@ -4369,7 +4369,7 @@  symbol_to_sal (struct symtab_and_line *result,
 	  result->symbol = sym;
 	  result->line = sym->line ();
 	  result->pc = sym->value_address ();
-	  result->pspace = result->symtab->compunit ()->objfile ()->pspace;
+	  result->pspace = result->symtab->compunit ()->objfile ()->pspace ();
 	  result->explicit_pc = 1;
 	  return 1;
 	}
@@ -4385,7 +4385,7 @@  symbol_to_sal (struct symtab_and_line *result,
 	  result->symbol = sym;
 	  result->line = sym->line ();
 	  result->pc = sym->value_address ();
-	  result->pspace = result->symtab->compunit ()->objfile ()->pspace;
+	  result->pspace = result->symtab->compunit ()->objfile ()->pspace ();
 	  return 1;
 	}
     }
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 368e129b49d3..3d50db402412 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -308,7 +308,7 @@  build_objfile_section_table (struct objfile *objfile)
 
 objfile::objfile (gdb_bfd_ref_ptr bfd_, const char *name, objfile_flags flags_)
   : flags (flags_),
-    pspace (current_program_space),
+    m_pspace (current_program_space),
     obfd (std::move (bfd_))
 {
   const char *expanded_name;
@@ -568,7 +568,7 @@  objfile::~objfile ()
   }
 
   /* Rebuild section map next time we need it.  */
-  get_objfile_pspace_data (pspace)->section_map_dirty = 1;
+  get_objfile_pspace_data (m_pspace)->section_map_dirty = 1;
 }
 
 
@@ -646,7 +646,7 @@  objfile_relocate1 (struct objfile *objfile,
     objfile->section_offsets[i] = new_offsets[i];
 
   /* Rebuild section map next time we need it.  */
-  get_objfile_pspace_data (objfile->pspace)->section_map_dirty = 1;
+  get_objfile_pspace_data (objfile->pspace ())->section_map_dirty = 1;
 
   /* Update the table in exec_ops, used to read memory.  */
   for (obj_section *s : objfile->sections ())
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 88dfb33e45c9..320e8099c91a 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -445,6 +445,9 @@  struct objfile
 
   DISABLE_COPY_AND_ASSIGN (objfile);
 
+  /* Return the program space associated with this objfile.  */
+  program_space *pspace () { return m_pspace; }
+
   /* A range adapter that makes it possible to iterate over all
      compunits in one objfile.  */
 
@@ -716,10 +719,12 @@  struct objfile
 
   objfile_flags flags;
 
+private:
   /* The program space associated with this objfile.  */
 
-  struct program_space *pspace;
+  program_space *m_pspace;
 
+public:
   /* List of compunits.
      These are used to do symbol lookups and file/line-number lookups.  */
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 1d6a4922b8e7..e37e30edb87b 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2294,11 +2294,11 @@  disable_display_command (const char *args, int from_tty)
 static void
 clear_dangling_display_expressions (struct objfile *objfile)
 {
-  program_space *pspace = objfile->pspace;
+  program_space *pspace = objfile->pspace ();
   if (objfile->separate_debug_objfile_backlink)
     {
       objfile = objfile->separate_debug_objfile_backlink;
-      gdb_assert (objfile->pspace == pspace);
+      gdb_assert (objfile->pspace () == pspace);
     }
 
   for (auto &d : all_displays)
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 60a14833b957..6e8d5b57692a 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -183,7 +183,7 @@  objfpy_get_progspace (PyObject *self, void *closure)
   objfile_object *obj = (objfile_object *) self;
 
   if (obj->objfile)
-    return pspace_to_pspace_object (obj->objfile->pspace).release ();
+    return pspace_to_pspace_object (obj->objfile->pspace ()).release ();
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/remote.c b/gdb/remote.c
index 90a4bd57a828..15c3eea6f79b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -15444,7 +15444,7 @@  remote_objfile_changed_check_symbols (program_space *pspace)
 static void
 remote_new_objfile (struct objfile *objfile)
 {
-  remote_objfile_changed_check_symbols (objfile->pspace);
+  remote_objfile_changed_check_symbols (objfile->pspace ());
 }
 
 /* Pull all the tracepoints defined on the target and create local
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 5c8557e9377a..9f377f427c87 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1496,7 +1496,7 @@  svr4_current_sos ()
 CORE_ADDR
 svr4_fetch_objfile_link_map (struct objfile *objfile)
 {
-  struct svr4_info *info = get_svr4_info (objfile->pspace);
+  struct svr4_info *info = get_svr4_info (objfile->pspace ());
 
   /* Cause svr4_current_sos() to be run if it hasn't been already.  */
   if (info->main_lm_addr == 0)
@@ -1625,7 +1625,7 @@  probes_table_htab_remove_objfile_probes (void **slot, void *info)
   struct objfile *objfile = (struct objfile *) info;
 
   if (pa->objfile == objfile)
-    htab_clear_slot (get_svr4_info (objfile->pspace)->probes_table.get (),
+    htab_clear_slot (get_svr4_info (objfile->pspace ())->probes_table.get (),
 		     slot);
 
   return 1;
@@ -1636,7 +1636,7 @@  probes_table_htab_remove_objfile_probes (void **slot, void *info)
 static void
 probes_table_remove_objfile_probes (struct objfile *objfile)
 {
-  svr4_info *info = get_svr4_info (objfile->pspace);
+  svr4_info *info = get_svr4_info (objfile->pspace ());
   if (info->probes_table != nullptr)
     htab_traverse_noresize (info->probes_table.get (),
 			    probes_table_htab_remove_objfile_probes, objfile);
diff --git a/gdb/solib.c b/gdb/solib.c
index 881f0d965027..55f1c53b99be 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1700,7 +1700,7 @@  remove_user_added_objfile (struct objfile *objfile)
 {
   if (objfile->flags & OBJF_USERLOADED)
     {
-      for (solib &so : objfile->pspace->solibs ())
+      for (solib &so : objfile->pspace ()->solibs ())
 	if (so.objfile == objfile)
 	  so.objfile = nullptr;
     }
diff --git a/gdb/symfile.c b/gdb/symfile.c
index b0510b4b4090..fc86841b52d5 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2387,7 +2387,7 @@  remove_symbol_file_command (const char *args, int from_tty)
 	{
 	  if ((objfile->flags & OBJF_USERLOADED) != 0
 	      && (objfile->flags & OBJF_SHARED) != 0
-	      && objfile->pspace == pspace
+	      && objfile->pspace () == pspace
 	      && is_addr_in_objfile (addr, objfile))
 	    {
 	      objf = objfile;
@@ -2408,7 +2408,7 @@  remove_symbol_file_command (const char *args, int from_tty)
 	{
 	  if ((objfile->flags & OBJF_USERLOADED) != 0
 	      && (objfile->flags & OBJF_SHARED) != 0
-	      && objfile->pspace == pspace
+	      && objfile->pspace () == pspace
 	      && filename_cmp (filename.get (), objfile_name (objfile)) == 0)
 	    {
 	      objf = objfile;
@@ -3722,7 +3722,7 @@  static void
 symfile_free_objfile (struct objfile *objfile)
 {
   /* Remove the target sections owned by this objfile.  */
-  objfile->pspace->remove_target_sections (objfile);
+  objfile->pspace ()->remove_target_sections (objfile);
 }
 
 /* Wrapper around the quick_symbol_functions expand_symtabs_matching "method".
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 41d71beec2ac..9ffc1e0b26b0 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1755,7 +1755,7 @@  maintenance_print_symbol_cache_statistics (const char *args, int from_tty)
 static void
 symtab_new_objfile_observer (struct objfile *objfile)
 {
-  symbol_cache_flush (objfile->pspace);
+  symbol_cache_flush (objfile->pspace ());
 }
 
 /* This module's 'all_objfiles_removed' observer.  */
@@ -1774,7 +1774,7 @@  symtab_all_objfiles_removed (program_space *pspace)
 static void
 symtab_free_objfile_observer (struct objfile *objfile)
 {
-  symbol_cache_flush (objfile->pspace);
+  symbol_cache_flush (objfile->pspace ());
 }
 
 /* See symtab.h.  */