public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] change range adapters to be member functions
@ 2019-01-17  2:50 Tom Tromey
  2019-01-17  2:50 ` [PATCH 6/6] Make minimal symbol range adapter a method on objfile Tom Tromey
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches

In the ALL_* removal series, Pedro pointed out that the range adapter
classes would be nicer as member functions of the relevant class.

This series implements this idea.  Most of these patches were written
using a script.

While looking at changing the minimal symbol iterator, I noticed that
the implementation could be simplified, so I've included this as patch
#5.

Regression tested by the buildbot.

Tom


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/6] Make minimal symbol range adapter a method on objfile
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
@ 2019-01-17  2:50 ` Tom Tromey
  2019-01-17  2:50 ` [PATCH 3/6] Add compunits range adapter to objfile Tom Tromey
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes class objfile_msymbols in favor of a method on the
objfile.

2019-01-16  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct minimal_symbol_iterator): Rename.  Move
	earlier.
	(struct objfile) <msymbols_range>: Move from top level.
	<msymbols>: New method.
	(class objfile_msymbols): Remove.
	* symtab.c (default_collect_symbol_completion_matches_break_on):
	Update.
	* symmisc.c (dump_msymbols): Update.
	* stabsread.c (scan_file_globals): Update.
	* objc-lang.c (info_selectors_command, info_classes_command)
	(find_methods): Update.
	* minsyms.c (find_solib_trampoline_target): Update.
	* hppa-tdep.c (hppa_lookup_stub_minimal_symbol): Update.
	* coffread.c (coff_symfile_read): Update.
	* ada-lang.c (ada_lookup_simple_minsym)
	(ada_collect_symbol_completion_matches): Update.
---
 gdb/ChangeLog   |  19 +++++++
 gdb/ada-lang.c  |   4 +-
 gdb/coffread.c  |   2 +-
 gdb/hppa-tdep.c |   2 +-
 gdb/minsyms.c   |   2 +-
 gdb/objc-lang.c |  10 ++--
 gdb/objfiles.h  | 146 ++++++++++++++++++++++++++----------------------
 gdb/stabsread.c |   2 +-
 gdb/symmisc.c   |   2 +-
 gdb/symtab.c    |   6 +-
 10 files changed, 113 insertions(+), 82 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 978bfcf352..abadf3d134 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4924,7 +4924,7 @@ ada_lookup_simple_minsym (const char *name)
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+      for (minimal_symbol *msymbol : objfile->msymbols ())
 	{
 	  if (match_name (MSYMBOL_LINKAGE_NAME (msymbol), lookup_name, NULL)
 	      && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
@@ -6411,7 +6411,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+      for (minimal_symbol *msymbol : objfile->msymbols ())
 	{
 	  QUIT;
 
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 2b75d8189f..6381cd3f37 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -661,7 +661,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
   if (pe_file)
     {
-      for (minimal_symbol *msym : objfile_msymbols (objfile))
+      for (minimal_symbol *msym : objfile->msymbols ())
 	{
 	  const char *name = MSYMBOL_LINKAGE_NAME (msym);
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 1d5730e0a2..f9ebfb32ba 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -2544,7 +2544,7 @@ hppa_lookup_stub_minimal_symbol (const char *name,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (minimal_symbol *msym : objfile_msymbols (objfile))
+      for (minimal_symbol *msym : objfile->msymbols ())
 	{
 	  if (strcmp (MSYMBOL_LINKAGE_NAME (msym), name) == 0)
 	    {
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 2433ff6c1e..d62e785668 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1494,7 +1494,7 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
     {
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+	  for (minimal_symbol *msymbol : objfile->msymbols ())
 	    {
 	      /* Also handle minimal symbols pointing to function
 		 descriptors.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 435a6a513a..bf4ea0ad2e 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -607,7 +607,7 @@ info_selectors_command (const char *regexp, int from_tty)
   /* First time thru is JUST to get max length and count.  */
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+      for (minimal_symbol *msymbol : objfile->msymbols ())
 	{
 	  QUIT;
 	  name = MSYMBOL_NATURAL_NAME (msymbol);
@@ -647,7 +647,7 @@ info_selectors_command (const char *regexp, int from_tty)
       matches = 0;
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+	  for (minimal_symbol *msymbol : objfile->msymbols ())
 	    {
 	      QUIT;
 	      name = MSYMBOL_NATURAL_NAME (msymbol);
@@ -761,7 +761,7 @@ info_classes_command (const char *regexp, int from_tty)
   /* First time thru is JUST to get max length and count.  */
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+      for (minimal_symbol *msymbol : objfile->msymbols ())
 	{
 	  QUIT;
 	  name = MSYMBOL_NATURAL_NAME (msymbol);
@@ -788,7 +788,7 @@ info_classes_command (const char *regexp, int from_tty)
       matches = 0;
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+	  for (minimal_symbol *msymbol : objfile->msymbols ())
 	    {
 	      QUIT;
 	      name = MSYMBOL_NATURAL_NAME (msymbol);
@@ -1008,7 +1008,7 @@ find_methods (char type, const char *theclass, const char *category,
 	/* There are no ObjC symbols in this objfile.  Skip it entirely.  */
 	continue;
 
-      for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+      for (minimal_symbol *msymbol : objfile->msymbols ())
 	{
 	  QUIT;
 
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index f666d558c2..7181ccf93c 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -182,6 +182,47 @@ extern void print_symbol_bcache_statistics (void);
 /* Number of entries in the minimal symbol hash table.  */
 #define MINIMAL_SYMBOL_HASH_SIZE 2039
 
+/* An iterator for minimal symbols.  */
+
+struct minimal_symbol_iterator
+{
+  typedef minimal_symbol_iterator self_type;
+  typedef struct minimal_symbol *value_type;
+  typedef struct minimal_symbol *&reference;
+  typedef struct minimal_symbol **pointer;
+  typedef std::forward_iterator_tag iterator_category;
+  typedef int difference_type;
+
+  explicit minimal_symbol_iterator (struct minimal_symbol *msym)
+    : m_msym (msym)
+  {
+  }
+
+  value_type operator* () const
+  {
+    return m_msym;
+  }
+
+  bool operator== (const self_type &other) const
+  {
+    return m_msym == other.m_msym;
+  }
+
+  bool operator!= (const self_type &other) const
+  {
+    return m_msym != other.m_msym;
+  }
+
+  self_type &operator++ ()
+  {
+    ++m_msym;
+    return *this;
+  }
+
+private:
+  struct minimal_symbol *m_msym;
+};
+
 /* Some objfile data is hung off the BFD.  This enables sharing of the
    data across all objfiles using the BFD.  The data is stored in an
    instance of this structure, and associated with the BFD using the
@@ -319,6 +360,44 @@ struct objfile
     return compunits_range (compunit_symtabs);
   }
 
+  /* A range adapter that makes it possible to iterate over all
+     minimal symbols of an objfile.  */
+
+  class msymbols_range
+  {
+  public:
+
+    explicit msymbols_range (struct objfile *objfile)
+      : m_objfile (objfile)
+    {
+    }
+
+    minimal_symbol_iterator begin () const
+    {
+      return minimal_symbol_iterator (m_objfile->per_bfd->msymbols);
+    }
+
+    minimal_symbol_iterator end () const
+    {
+      return minimal_symbol_iterator
+	(m_objfile->per_bfd->msymbols
+	 + m_objfile->per_bfd->minimal_symbol_count);
+    }
+
+  private:
+
+    struct objfile *m_objfile;
+  };
+
+  /* Return a range adapter for iterating over all minimal
+     symbols.  */
+
+  msymbols_range msymbols ()
+  {
+    return msymbols_range (this);
+  }
+
+
   /* All struct objfile's are chained together by their next pointers.
      The program space field "objfiles"  (frequently referenced via
      the macro "object_files") points to the first link in this chain.  */
@@ -570,73 +649,6 @@ extern void default_iterate_over_objfiles_in_search_order
    void *cb_data, struct objfile *current_objfile);
 \f
 
-/* A range adapter that makes it possible to iterate over all
-   minimal symbols of an objfile.  */
-
-class objfile_msymbols
-{
-public:
-
-  explicit objfile_msymbols (struct objfile *objfile)
-    : m_objfile (objfile)
-  {
-  }
-
-  struct iterator
-  {
-    typedef iterator self_type;
-    typedef struct minimal_symbol *value_type;
-    typedef struct minimal_symbol *&reference;
-    typedef struct minimal_symbol **pointer;
-    typedef std::forward_iterator_tag iterator_category;
-    typedef int difference_type;
-
-    explicit iterator (struct minimal_symbol *msym)
-      : m_msym (msym)
-    {
-    }
-
-    value_type operator* () const
-    {
-      return m_msym;
-    }
-
-    bool operator== (const self_type &other) const
-    {
-      return m_msym == other.m_msym;
-    }
-
-    bool operator!= (const self_type &other) const
-    {
-      return m_msym != other.m_msym;
-    }
-
-    self_type &operator++ ()
-    {
-      ++m_msym;
-      return *this;
-    }
-
-  private:
-    struct minimal_symbol *m_msym;
-  };
-
-  iterator begin () const
-  {
-    return iterator (m_objfile->per_bfd->msymbols);
-  }
-
-  iterator end () const
-  {
-    return iterator (m_objfile->per_bfd->msymbols
-		     + m_objfile->per_bfd->minimal_symbol_count);
-  }
-
-private:
-
-  struct objfile *m_objfile;
-};
-
 #define ALL_OBJFILE_OSECTIONS(objfile, osect)	\
   for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
     if (osect->the_bfd_section == NULL)					\
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index daba7cb98b..fc41c8fc86 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -4598,7 +4598,7 @@ scan_file_globals (struct objfile *objfile)
       if (hash >= HASHSIZE)
 	return;
 
-      for (minimal_symbol *msymbol : objfile_msymbols (resolve_objfile))
+      for (minimal_symbol *msymbol : resolve_objfile->msymbols ())
 	{
 	  QUIT;
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 11a3b7f4f0..2d424b8f7a 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -197,7 +197,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
       return;
     }
   index = 0;
-  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+  for (minimal_symbol *msymbol : objfile->msymbols ())
     {
       struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 867fb6c927..0b811fb8ea 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4455,7 +4455,7 @@ search_symbols (const char *regexp, enum search_domain kind,
     {
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+	  for (minimal_symbol *msymbol : objfile->msymbols ())
 	    {
 	      QUIT;
 
@@ -4558,7 +4558,7 @@ search_symbols (const char *regexp, enum search_domain kind,
     {
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+	  for (minimal_symbol *msymbol : objfile->msymbols ())
 	    {
 	      QUIT;
 
@@ -5274,7 +5274,7 @@ default_collect_symbol_completion_matches_break_on
     {
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+	  for (minimal_symbol *msymbol : objfile->msymbols ())
 	    {
 	      QUIT;
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] Change all_objfiles adapter to be a method on program_space
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
                   ` (4 preceding siblings ...)
  2019-01-17  2:50 ` [PATCH 4/6] Make psymtab range adapter a method on objfile Tom Tromey
@ 2019-01-17  2:50 ` Tom Tromey
  2019-01-17 13:58 ` [PATCH 0/6] change range adapters to be member functions Pedro Alves
  6 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the all_objfiles range adapter to be a method on the
program space, and fixes up all the users.

gdb/ChangeLog
2019-01-15  Tom Tromey  <tom@tromey.com>

	* progspace.h (program_space) <all_objfiles_range>: New typedef.
	<all_objfiles>: New method.
	* guile/scm-progspace.c (gdbscm_progspace_objfiles): Update.
	* guile/scm-pretty-print.c
	(ppscm_find_pretty_printer_from_objfiles): Update.
	* guile/scm-objfile.c (gdbscm_objfiles): Update.
	* python/py-xmethods.c (gdbpy_get_matching_xmethod_workers):
	Update.
	* python/py-progspace.c (pspy_get_objfiles): Update.
	* python/py-prettyprint.c (find_pretty_printer_from_objfiles):
	Update.
	* python/py-objfile.c (objfpy_lookup_objfile_by_name)
	(objfpy_lookup_objfile_by_build_id): Update.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Update.
	* windows-tdep.c (windows_iterate_over_objfiles_in_search_order):
	Update.
	* symtab.c (iterate_over_symtabs, matching_obj_sections)
	(expand_symtab_containing_pc, lookup_objfile_from_block)
	(lookup_static_symbol, basic_lookup_transparent_type)
	(find_pc_sect_compunit_symtab, find_symbol_at_address)
	(find_line_symtab, info_sources_command)
	(default_collect_symbol_completion_matches_break_on)
	(make_source_files_completion_list, find_main_name): Update.
	* symmisc.c (print_symbol_bcache_statistics)
	(print_objfile_statistics, maintenance_print_symbols)
	(maintenance_print_msymbols, maintenance_print_objfiles)
	(maintenance_info_symtabs, maintenance_check_symtabs)
	(maintenance_expand_symtabs, maintenance_info_line_tables):
	Update.
	* symfile.c (remove_symbol_file_command, overlay_invalidate_all)
	(find_pc_overlay, find_pc_mapped_section, list_overlays_command)
	(map_overlay_command, unmap_overlay_command)
	(simple_overlay_update, expand_symtabs_matching)
	(map_symbol_filenames): Update.
	* symfile-debug.c (set_debug_symfile): Update.
	* spu-tdep.c (spu_overlay_update, spu_objfile_from_frame):
	Update.
	* source.c (select_source_symtab, forget_cached_source_info):
	Update.
	* solib.c (solib_read_symbols): Update.
	* solib-spu.c (append_ocl_sos): Update.
	* psymtab.c (maintenance_print_psymbols)
	(maintenance_info_psymtabs, maintenance_check_psymtabs): Update.
	* probe.c (parse_probes_in_pspace, find_probe_by_pc): Update.
	* printcmd.c (info_symbol_command): Update.
	* ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created):
	Update.
	* objfiles.h (class all_objfiles): Remove.
	* objfiles.c (have_partial_symbols, have_full_symbols)
	(have_minimal_symbols, qsort_cmp, update_section_map)
	(shared_objfile_contains_address_p)
	(default_iterate_over_objfiles_in_search_order): Update.
	* objc-lang.c (info_selectors_command, info_classes_command)
	(find_methods): Update.
	* minsyms.c (find_solib_trampoline_target): Update.
	* maint.c (maintenance_info_sections)
	(maintenance_translate_address, count_symtabs_and_blocks):
	Update.
	* main.c (captured_main_1): Update.
	* linux-thread-db.c (try_thread_db_load_from_pdir)
	(has_libpthread): Update.
	* linespec.c (iterate_over_all_matching_symtabs)
	(search_minsyms_for_name): Update.
	* jit.c (jit_find_objf_with_entry_addr): Update.
	* hppa-tdep.c (find_unwind_entry)
	(hppa_lookup_stub_minimal_symbol): Update.
	* gcore.c (gcore_create_callback, objfile_find_memory_regions):
	Update.
	* elfread.c (elf_gnu_ifunc_resolve_by_cache)
	(elf_gnu_ifunc_resolve_by_got): Update.
	* dwarf2-frame.c (dwarf2_frame_find_fde): Update.
	* dwarf-index-write.c (save_gdb_index_command): Update.
	* cp-support.c (add_symbol_overload_list_qualified): Update.
	* breakpoint.c (create_overlay_event_breakpoint)
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint): Update.
	* blockframe.c (find_pc_partial_function): Update.
	* ada-lang.c (ada_lookup_simple_minsym, add_nonlocal_symbols)
	(ada_collect_symbol_completion_matches)
	(ada_add_global_exceptions): Update.
---
 gdb/ChangeLog                    | 84 ++++++++++++++++++++++++++++++++
 gdb/ada-lang.c                   | 14 +++---
 gdb/blockframe.c                 |  2 +-
 gdb/breakpoint.c                 |  8 +--
 gdb/compile/compile-object-run.c |  2 +-
 gdb/cp-support.c                 |  6 +--
 gdb/dwarf-index-write.c          |  2 +-
 gdb/dwarf2-frame.c               |  2 +-
 gdb/elfread.c                    |  4 +-
 gdb/gcore.c                      |  4 +-
 gdb/guile/scm-objfile.c          |  2 +-
 gdb/guile/scm-pretty-print.c     |  2 +-
 gdb/guile/scm-progspace.c        |  2 +-
 gdb/hppa-tdep.c                  |  4 +-
 gdb/jit.c                        |  2 +-
 gdb/linespec.c                   |  4 +-
 gdb/linux-thread-db.c            |  4 +-
 gdb/main.c                       |  2 +-
 gdb/maint.c                      |  6 +--
 gdb/mi/mi-cmd-file.c             |  2 +-
 gdb/minsyms.c                    |  2 +-
 gdb/objc-lang.c                  | 10 ++--
 gdb/objfiles.c                   | 16 +++---
 gdb/objfiles.h                   | 15 ------
 gdb/ppc-linux-tdep.c             |  2 +-
 gdb/printcmd.c                   |  2 +-
 gdb/probe.c                      |  6 +--
 gdb/progspace.h                  | 11 +++++
 gdb/psymtab.c                    |  6 +--
 gdb/python/py-objfile.c          |  4 +-
 gdb/python/py-prettyprint.c      |  2 +-
 gdb/python/py-progspace.c        |  2 +-
 gdb/python/py-xmethods.c         |  2 +-
 gdb/solib-spu.c                  |  2 +-
 gdb/solib.c                      |  2 +-
 gdb/source.c                     |  6 +--
 gdb/spu-tdep.c                   |  4 +-
 gdb/symfile-debug.c              |  2 +-
 gdb/symfile.c                    | 24 ++++-----
 gdb/symmisc.c                    | 18 +++----
 gdb/symtab.c                     | 46 ++++++++---------
 gdb/windows-tdep.c               |  2 +-
 42 files changed, 212 insertions(+), 132 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dbd258a608..54ac0fc668 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4922,7 +4922,7 @@ ada_lookup_simple_minsym (const char *name)
   symbol_name_matcher_ftype *match_name
     = ada_get_symbol_name_matcher (lookup_name);
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	{
@@ -5612,7 +5612,7 @@ add_nonlocal_symbols (struct obstack *obstackp,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       data.objfile = objfile;
 
@@ -5645,7 +5645,7 @@ add_nonlocal_symbols (struct obstack *obstackp,
       const char *name = ada_lookup_name (lookup_name);
       std::string name1 = std::string ("<_ada_") + name + '>';
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
         {
 	  data.objfile = objfile;
 	  objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (),
@@ -6409,7 +6409,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
      anything that isn't a text symbol (everything else will be
      handled by the psymtab code above).  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	{
@@ -6465,7 +6465,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *s : objfile_compunits (objfile))
 	{
@@ -6484,7 +6484,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
 	}
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *s : objfile_compunits (objfile))
 	{
@@ -13566,7 +13566,7 @@ ada_add_global_exceptions (compiled_regex *preg,
 			   NULL,
 			   VARIABLES_DOMAIN);
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *s : objfile_compunits (objfile))
 	{
diff --git a/gdb/blockframe.c b/gdb/blockframe.c
index 106f8a49c2..2ee288d3a4 100644
--- a/gdb/blockframe.c
+++ b/gdb/blockframe.c
@@ -236,7 +236,7 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address,
     goto return_cached_value;
 
   msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->sf)
 	{
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 2ab8a76326..1abbe11386 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3205,7 +3205,7 @@ create_overlay_event_breakpoint (void)
 {
   const char *const func_name = "_ovly_debug_event";
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       struct breakpoint *b;
       struct breakpoint_objfile_data *bp_objfile_data;
@@ -3263,7 +3263,7 @@ create_longjmp_master_breakpoint (void)
   {
     set_current_program_space (pspace);
 
-    for (objfile *objfile : all_objfiles (current_program_space))
+    for (objfile *objfile : current_program_space->all_objfiles ())
       {
 	int i;
 	struct gdbarch *gdbarch;
@@ -3366,7 +3366,7 @@ create_std_terminate_master_breakpoint (void)
 
     set_current_program_space (pspace);
 
-    for (objfile *objfile : all_objfiles (current_program_space))
+    for (objfile *objfile : current_program_space->all_objfiles ())
       {
 	struct breakpoint *b;
 	struct breakpoint_objfile_data *bp_objfile_data;
@@ -3411,7 +3411,7 @@ create_exception_master_breakpoint (void)
 {
   const char *const func_name = "_Unwind_DebugHook";
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       struct breakpoint *b;
       struct gdbarch *gdbarch;
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 8abe494218..9b1c255048 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -82,7 +82,7 @@ do_module_cleanup (void *arg, int registers_valid)
 	}
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     if ((objfile->flags & OBJF_USERLOADED) == 0
         && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0))
       {
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 16d8176341..d147486e00 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1378,7 +1378,7 @@ add_symbol_overload_list_qualified (const char *func_name,
   /* Look through the partial symtabs for all symbols which begin by
      matching FUNC_NAME.  Make sure we read that symbol table in.  */
 
-  for (objfile *objf : all_objfiles (current_program_space))
+  for (objfile *objf : current_program_space->all_objfiles ())
     {
       if (objf->sf)
 	objf->sf->qf->expand_symtabs_for_function (objf, func_name);
@@ -1395,7 +1395,7 @@ add_symbol_overload_list_qualified (const char *func_name,
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cust : objfile_compunits (objfile))
 	{
@@ -1405,7 +1405,7 @@ add_symbol_overload_list_qualified (const char *func_name,
 	}
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cust : objfile_compunits (objfile))
 	{
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index b11927d360..9e44658579 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -1662,7 +1662,7 @@ save_gdb_index_command (const char *arg, int from_tty)
   if (!*arg)
     error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       struct stat st;
 
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index deb8a80029..7cc88e3a06 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -1702,7 +1702,7 @@ bsearch_fde_cmp (const void *key, const void *element)
 static struct dwarf2_fde *
 dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       struct dwarf2_fde_table *fde_table;
       struct dwarf2_fde **p_fde;
diff --git a/gdb/elfread.c b/gdb/elfread.c
index bc6b5ff69b..7e654754f2 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -759,7 +759,7 @@ elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
 static int
 elf_gnu_ifunc_resolve_by_cache (const char *name, CORE_ADDR *addr_p)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       htab_t htab;
       struct elf_gnu_ifunc_cache *entry_p;
@@ -804,7 +804,7 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
   name_got_plt = (char *) alloca (strlen (name) + got_suffix_len + 1);
   sprintf (name_got_plt, "%s" SYMBOL_GOT_PLT_SUFFIX, name);
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       bfd *obfd = objfile->obfd;
       struct gdbarch *gdbarch = get_objfile_arch (objfile);
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 1a2ed0cd7e..0476a4e4b4 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -426,7 +426,7 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read,
 	 If so, we can avoid copying its contents by clearing SEC_LOAD.  */
       struct obj_section *objsec;
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	ALL_OBJFILE_OSECTIONS (objfile, objsec)
 	  {
 	    bfd *abfd = objfile->obfd;
@@ -493,7 +493,7 @@ objfile_find_memory_regions (struct target_ops *self,
   bfd_vma temp_bottom, temp_top;
 
   /* Call callback function for each objfile section.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, objsec)
       {
 	bfd *ibfd = objfile->obfd;
diff --git a/gdb/guile/scm-objfile.c b/gdb/guile/scm-objfile.c
index 79b784aad6..1880690efe 100644
--- a/gdb/guile/scm-objfile.c
+++ b/gdb/guile/scm-objfile.c
@@ -370,7 +370,7 @@ gdbscm_objfiles (void)
 
   result = SCM_EOL;
 
-  for (objfile *objf : all_objfiles (current_program_space))
+  for (objfile *objf : current_program_space->all_objfiles ())
     {
       SCM item = ofscm_scm_from_objfile (objf);
 
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index d621ed5e91..17cc0ff6cd 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -427,7 +427,7 @@ ppscm_search_pp_list (SCM list, SCM value)
 static SCM
 ppscm_find_pretty_printer_from_objfiles (SCM value)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       objfile_smob *o_smob = ofscm_objfile_smob_from_objfile (objfile);
       SCM pp
diff --git a/gdb/guile/scm-progspace.c b/gdb/guile/scm-progspace.c
index 9fc650c67c..6cf63ca095 100644
--- a/gdb/guile/scm-progspace.c
+++ b/gdb/guile/scm-progspace.c
@@ -289,7 +289,7 @@ gdbscm_progspace_objfiles (SCM self)
 
   result = SCM_EOL;
 
-  for (objfile *objfile : all_objfiles (p_smob->pspace))
+  for (objfile *objfile : p_smob->pspace->all_objfiles ())
     {
       if (objfile->separate_debug_objfile_backlink == NULL)
 	{
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 16e44252f5..1d5730e0a2 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -497,7 +497,7 @@ find_unwind_entry (CORE_ADDR pc)
       return NULL;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       struct hppa_unwind_info *ui;
       ui = NULL;
@@ -2542,7 +2542,7 @@ hppa_lookup_stub_minimal_symbol (const char *name,
 {
   struct bound_minimal_symbol result = { NULL, NULL };
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (minimal_symbol *msym : objfile_msymbols (objfile))
 	{
diff --git a/gdb/jit.c b/gdb/jit.c
index 35e44e3426..543eb60995 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -984,7 +984,7 @@ jit_unregister_code (struct objfile *objfile)
 static struct objfile *
 jit_find_objf_with_entry_addr (CORE_ADDR entry_addr)
 {
-  for (objfile *objf : all_objfiles (current_program_space))
+  for (objfile *objf : current_program_space->all_objfiles ())
     {
       struct jit_objfile_data *objf_data;
 
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 964697b7bc..1cd3e251e0 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1141,7 +1141,7 @@ iterate_over_all_matching_symtabs
 
     set_current_program_space (pspace);
 
-    for (objfile *objfile : all_objfiles (current_program_space))
+    for (objfile *objfile : current_program_space->all_objfiles ())
       {
 	if (objfile->sf)
 	  objfile->sf->qf->expand_symtabs_matching (objfile,
@@ -4357,7 +4357,7 @@ search_minsyms_for_name (struct collect_info *info,
 
 	set_current_program_space (pspace);
 
-	for (objfile *objfile : all_objfiles (current_program_space))
+	for (objfile *objfile : current_program_space->all_objfiles ())
 	  {
 	    iterate_over_minimal_symbols (objfile, name,
 					  [&] (struct minimal_symbol *msym)
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index d6cbc34f33..996d018444 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1056,7 +1056,7 @@ try_thread_db_load_from_pdir (const char *subdir)
   if (!auto_load_thread_db)
     return 0;
 
-  for (objfile *obj : all_objfiles (current_program_space))
+  for (objfile *obj : current_program_space->all_objfiles ())
     if (libpthread_name_p (objfile_name (obj)))
       {
 	if (try_thread_db_load_from_pdir_1 (obj, subdir))
@@ -1165,7 +1165,7 @@ thread_db_load_search (void)
 static int
 has_libpthread (void)
 {
-  for (objfile *obj : all_objfiles (current_program_space))
+  for (objfile *obj : current_program_space->all_objfiles ())
     if (libpthread_name_p (objfile_name (obj)))
       return 1;
 
diff --git a/gdb/main.c b/gdb/main.c
index 7d9492b876..305727f23d 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1123,7 +1123,7 @@ captured_main_1 (struct captured_main_args *context)
      We wait until now because it is common to add to the source search
      path in local_gdbinit.  */
   global_auto_load = save_auto_load;
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     load_auto_scripts_for_objfile (objfile);
 
   /* Process '-x' and '-ex' options.  */
diff --git a/gdb/maint.c b/gdb/maint.c
index f286c63430..0037f5e0f4 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -357,7 +357,7 @@ maintenance_info_sections (const char *arg, int from_tty)
 	  if (strcmp (arg, "ALLOBJ") == 0)
 	    arg = NULL;
 
-	  for (objfile *ofile : all_objfiles (current_program_space))
+	  for (objfile *ofile : current_program_space->all_objfiles ())
 	    {
 	      printf_filtered (_("  Object file: %s\n"), 
 			       bfd_get_filename (ofile->obfd));
@@ -447,7 +447,7 @@ maintenance_translate_address (const char *arg, int from_tty)
       int arg_len = p - arg;
       p = skip_spaces (p + 1);
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	ALL_OBJFILE_OSECTIONS (objfile, sect)
 	  {
 	    if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
@@ -771,7 +771,7 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
      current_program_space may be NULL.  */
   if (current_program_space != NULL)
     {
-      for (objfile *o : all_objfiles (current_program_space))
+      for (objfile *o : current_program_space->all_objfiles ())
 	{
 	  for (compunit_symtab *cu : objfile_compunits (o))
 	    {
diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
index 2071b9fcb4..a3c10955da 100644
--- a/gdb/mi/mi-cmd-file.c
+++ b/gdb/mi/mi-cmd-file.c
@@ -92,7 +92,7 @@ mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc)
   uiout->begin (ui_out_type_list, "files");
 
   /* Look at all of the file symtabs.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cu : objfile_compunits (objfile))
 	{
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index d09022623d..2433ff6c1e 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1492,7 +1492,7 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
 
   if (tsymbol != NULL)
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	    {
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 22c12fff3b..435a6a513a 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -605,7 +605,7 @@ info_selectors_command (const char *regexp, int from_tty)
     }
 
   /* First time thru is JUST to get max length and count.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	{
@@ -645,7 +645,7 @@ info_selectors_command (const char *regexp, int from_tty)
 
       sym_arr = XALLOCAVEC (struct symbol *, matches);
       matches = 0;
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	    {
@@ -759,7 +759,7 @@ info_classes_command (const char *regexp, int from_tty)
     }
 
   /* First time thru is JUST to get max length and count.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	{
@@ -786,7 +786,7 @@ info_classes_command (const char *regexp, int from_tty)
 		       regexp ? regexp : "*");
       sym_arr = XALLOCAVEC (struct symbol *, matches);
       matches = 0;
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	    {
@@ -992,7 +992,7 @@ find_methods (char type, const char *theclass, const char *category,
 
   gdb_assert (symbol_names != NULL);
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       unsigned int *objc_csym;
 
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 854e87db21..569e308b6b 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1013,7 +1013,7 @@ objfile_has_symbols (struct objfile *objfile)
 int
 have_partial_symbols (void)
 {
-  for (objfile *ofp : all_objfiles (current_program_space))
+  for (objfile *ofp : current_program_space->all_objfiles ())
     {
       if (objfile_has_partial_symbols (ofp))
 	return 1;
@@ -1028,7 +1028,7 @@ have_partial_symbols (void)
 int
 have_full_symbols (void)
 {
-  for (objfile *ofp : all_objfiles (current_program_space))
+  for (objfile *ofp : current_program_space->all_objfiles ())
     {
       if (objfile_has_full_symbols (ofp))
 	return 1;
@@ -1062,7 +1062,7 @@ objfile_purge_solibs (void)
 int
 have_minimal_symbols (void)
 {
-  for (objfile *ofp : all_objfiles (current_program_space))
+  for (objfile *ofp : current_program_space->all_objfiles ())
     {
       if (ofp->per_bfd->minimal_symbol_count > 0)
 	{
@@ -1133,7 +1133,7 @@ qsort_cmp (const void *a, const void *b)
 	{
 	  /* Sort on sequence number of the objfile in the chain.  */
 
-	  for (objfile *objfile : all_objfiles (current_program_space))
+	  for (objfile *objfile : current_program_space->all_objfiles ())
 	    if (objfile == objfile1)
 	      return -1;
 	    else if (objfile == objfile2)
@@ -1317,7 +1317,7 @@ update_section_map (struct program_space *pspace,
   xfree (map);
 
   alloc_size = 0;
-  for (objfile *objfile : all_objfiles (pspace))
+  for (objfile *objfile : pspace->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, s)
       if (insert_section_p (objfile->obfd, s->the_bfd_section))
 	alloc_size += 1;
@@ -1333,7 +1333,7 @@ update_section_map (struct program_space *pspace,
   map = XNEWVEC (struct obj_section *, alloc_size);
 
   i = 0;
-  for (objfile *objfile : all_objfiles (pspace))
+  for (objfile *objfile : pspace->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, s)
       if (insert_section_p (objfile->obfd, s->the_bfd_section))
 	map[i++] = s;
@@ -1477,7 +1477,7 @@ int
 shared_objfile_contains_address_p (struct program_space *pspace,
 				   CORE_ADDR address)
 {
-  for (objfile *objfile : all_objfiles (pspace))
+  for (objfile *objfile : pspace->all_objfiles ())
     {
       if ((objfile->flags & OBJF_SHARED) != 0
 	  && is_addr_in_objfile (address, objfile))
@@ -1503,7 +1503,7 @@ default_iterate_over_objfiles_in_search_order
 {
   int stop = 0;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
        stop = cb (objfile, cb_data);
        if (stop)
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index f7d08c43b3..9ab0f38280 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -553,21 +553,6 @@ extern void default_iterate_over_objfiles_in_search_order
    void *cb_data, struct objfile *current_objfile);
 \f
 
-/* An iterarable object that can be used to iterate over all
-   objfiles.  The basic use is in a foreach, like:
-
-   for (objfile *objf : all_objfiles (pspace)) { ... }  */
-
-class all_objfiles : public next_adapter<struct objfile>
-{
-public:
-
-  explicit all_objfiles (struct program_space *pspace)
-    : next_adapter<struct objfile> (pspace->objfiles)
-  {
-  }
-};
-
 /* An iterarable object that can be used to iterate over all
    objfiles.  The basic use is in a foreach, like:
 
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 48bf56dd2f..45414fc1ec 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1789,7 +1789,7 @@ static void
 ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty)
 {
   ppc_linux_spe_context_lookup (NULL);
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     ppc_linux_spe_context_lookup (objfile);
 }
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 9c476e743d..eb05c61757 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1282,7 +1282,7 @@ info_symbol_command (const char *arg, int from_tty)
     error_no_arg (_("address"));
 
   addr = parse_and_eval_address (arg);
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, osect)
       {
 	/* Only process each object file once, even if there's a separate
diff --git a/gdb/probe.c b/gdb/probe.c
index 7450e4cede..bbb5095041 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -73,7 +73,7 @@ parse_probes_in_pspace (const static_probe_ops *spops,
 			const char *name,
 			std::vector<symtab_and_line> *result)
 {
-  for (objfile *objfile : all_objfiles (search_pspace))
+  for (objfile *objfile : search_pspace->all_objfiles ())
     {
       if (!objfile->sf || !objfile->sf->sym_probe_fns)
 	continue;
@@ -249,7 +249,7 @@ find_probe_by_pc (CORE_ADDR pc)
   result.objfile = NULL;
   result.prob = NULL;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (!objfile->sf || !objfile->sf->sym_probe_fns
 	  || objfile->sect_index_text == -1)
@@ -294,7 +294,7 @@ collect_probes (const std::string &objname, const std::string &provider,
     obj_pat.emplace (objname.c_str (), REG_NOSUB,
 		     _("Invalid object file regexp"));
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (! objfile->sf || ! objfile->sf->sym_probe_fns)
 	continue;
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 825daff202..5006840d85 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -137,6 +137,17 @@ struct program_space
   program_space (address_space *aspace_);
   ~program_space ();
 
+  typedef next_adapter<struct objfile> all_objfiles_range;
+
+  /* Return an iterarable object that can be used to iterate over all
+     objfiles.  The basic use is in a foreach, like:
+
+     for (objfile *objf : pspace->all_objfiles ()) { ... }  */
+  all_objfiles_range all_objfiles ()
+  {
+    return all_objfiles_range (objfiles);
+  }
+
   /* Pointer to next in linked list.  */
   struct program_space *next = NULL;
 
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index e034fda340..1ee63dc20c 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1942,7 +1942,7 @@ maintenance_print_psymbols (const char *args, int from_tty)
     }
 
   found = 0;
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       int printed_objfile_header = 0;
       int print_for_objfile = 1;
@@ -2035,7 +2035,7 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
     re_comp (regexp);
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
@@ -2148,7 +2148,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
   struct block *b;
   int length;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     for (partial_symtab *ps : require_partial_symbols (objfile, 1))
       {
 	struct gdbarch *gdbarch = get_objfile_arch (objfile);
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index d9cf548adb..d31d65ceaa 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -501,7 +501,7 @@ objfpy_build_id_matches (const struct bfd_build_id *build_id,
 static struct objfile *
 objfpy_lookup_objfile_by_name (const char *name)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       const char *filename;
 
@@ -527,7 +527,7 @@ objfpy_lookup_objfile_by_name (const char *name)
 static struct objfile *
 objfpy_lookup_objfile_by_build_id (const char *build_id)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       const struct bfd_build_id *obfd_build_id;
 
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 4092fdb79f..e39a277e63 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -93,7 +93,7 @@ search_pp_list (PyObject *list, PyObject *value)
 static PyObject *
 find_pretty_printer_from_objfiles (PyObject *value)
 {
-  for (objfile *obj : all_objfiles (current_program_space))
+  for (objfile *obj : current_program_space->all_objfiles ())
     {
       gdbpy_ref<> objf = objfile_to_objfile_object (obj);
       if (objf == NULL)
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index a17ef69df7..cf116d4e0e 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -333,7 +333,7 @@ pspy_get_objfiles (PyObject *self_, PyObject *args)
 
   if (self->pspace != NULL)
     {
-      for (objfile *objf : all_objfiles (self->pspace))
+      for (objfile *objf : self->pspace->all_objfiles ())
 	{
 	  gdbpy_ref<> item = objfile_to_objfile_object (objf);
 
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index acf521dfe3..6b7a46e7a4 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -143,7 +143,7 @@ gdbpy_get_matching_xmethod_workers
   /* Gather debug method matchers registered with the object files.
      This could be done differently by iterating over each objfile's matcher
      list individually, but there's no data yet to show it's needed.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile);
 
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index d68150eb3c..d6e62337af 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -102,7 +102,7 @@ append_ocl_sos (struct so_list **link_ptr)
 {
   CORE_ADDR *ocl_program_addr_base;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       ocl_program_addr_base
 	= (CORE_ADDR *) objfile_data (objfile, ocl_program_data_key);
diff --git a/gdb/solib.c b/gdb/solib.c
index 24f40d1124..cef661909e 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -678,7 +678,7 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
 	{
 	  /* Have we already loaded this shared object?  */
 	  so->objfile = nullptr;
-	  for (objfile *objfile : all_objfiles (current_program_space))
+	  for (objfile *objfile : current_program_space->all_objfiles ())
 	    {
 	      if (filename_cmp (objfile_name (objfile), so->so_name) == 0
 		  && objfile->addr_low == so->addr_low)
diff --git a/gdb/source.c b/gdb/source.c
index abe4c6cf1e..120bceb44b 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -269,7 +269,7 @@ select_source_symtab (struct symtab *s)
 
   current_source_line = 1;
 
-  for (objfile *ofp : all_objfiles (current_program_space))
+  for (objfile *ofp : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cu : objfile_compunits (ofp))
 	{
@@ -291,7 +291,7 @@ select_source_symtab (struct symtab *s)
   if (current_source_symtab)
     return;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->sf)
 	s = objfile->sf->qf->find_last_source_symtab (objfile);
@@ -382,7 +382,7 @@ forget_cached_source_info (void)
   struct program_space *pspace;
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	forget_cached_source_info_for_objfile (objfile);
       }
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index 33081fb828..2e15d8ef7b 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -1883,7 +1883,7 @@ spu_overlay_update (struct obj_section *osect)
   /* All sections.  */
   else
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	ALL_OBJFILE_OSECTIONS (objfile, osect)
 	  if (section_is_overlay (osect))
 	    spu_overlay_update_osect (osect);
@@ -2003,7 +2003,7 @@ spu_objfile_from_frame (struct frame_info *frame)
   if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
     return NULL;
 
-  for (objfile *obj : all_objfiles (current_program_space))
+  for (objfile *obj : current_program_space->all_objfiles ())
     {
       if (obj->sections != obj->sections_end
 	  && SPUADDR_SPU (obj_section_addr (obj->sections)) == tdep->id)
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index b71fa8b001..0fe2d4f5aa 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -662,7 +662,7 @@ set_debug_symfile (const char *args, int from_tty, struct cmd_list_element *c)
   struct program_space *pspace;
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	if (debug_symfile)
 	  {
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 04197120db..142aed713a 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2351,7 +2351,7 @@ remove_symbol_file_command (const char *args, int from_tty)
 
       addr = parse_and_eval_address (argv[1]);
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  if ((objfile->flags & OBJF_USERLOADED) != 0
 	      && (objfile->flags & OBJF_SHARED) != 0
@@ -2372,7 +2372,7 @@ remove_symbol_file_command (const char *args, int from_tty)
 
       gdb::unique_xmalloc_ptr<char> filename (tilde_expand (argv[0]));
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  if ((objfile->flags & OBJF_USERLOADED) != 0
 	      && (objfile->flags & OBJF_SHARED) != 0
@@ -2980,7 +2980,7 @@ overlay_invalidate_all (void)
 {
   struct obj_section *sect;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, sect)
       if (section_is_overlay (sect))
 	sect->ovly_mapped = -1;
@@ -3158,7 +3158,7 @@ find_pc_overlay (CORE_ADDR pc)
 
   if (overlay_debugging)
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	ALL_OBJFILE_OSECTIONS (objfile, osect)
 	  if (section_is_overlay (osect))
 	    {
@@ -3187,7 +3187,7 @@ find_pc_mapped_section (CORE_ADDR pc)
 
   if (overlay_debugging)
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	ALL_OBJFILE_OSECTIONS (objfile, osect)
 	  if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
 	    return osect;
@@ -3207,7 +3207,7 @@ list_overlays_command (const char *args, int from_tty)
 
   if (overlay_debugging)
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	ALL_OBJFILE_OSECTIONS (objfile, osect)
 	  if (section_is_mapped (osect))
 	    {
@@ -3255,7 +3255,7 @@ map_overlay_command (const char *args, int from_tty)
     error (_("Argument required: name of an overlay section"));
 
   /* First, find a section matching the user supplied argument.  */
-  for (objfile *obj_file : all_objfiles (current_program_space))
+  for (objfile *obj_file : current_program_space->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (obj_file, sec)
       if (!strcmp (bfd_section_name (obj_file->obfd, sec->the_bfd_section),
 		   args))
@@ -3269,7 +3269,7 @@ map_overlay_command (const char *args, int from_tty)
 
 	  /* Next, make a pass and unmap any sections that are
 	     overlapped by this new section: */
-	  for (objfile *objfile2 : all_objfiles (current_program_space))
+	  for (objfile *objfile2 : current_program_space->all_objfiles ())
 	    ALL_OBJFILE_OSECTIONS (objfile2, sec2)
 	      if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec,
 									sec2))
@@ -3303,7 +3303,7 @@ unmap_overlay_command (const char *args, int from_tty)
     error (_("Argument required: name of an overlay section"));
 
   /* First, find a section matching the user supplied argument.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, sec)
       if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
 	{
@@ -3574,7 +3574,7 @@ simple_overlay_update (struct obj_section *osect)
     return;
 
   /* Now may as well update all sections, even if only one was requested.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     ALL_OBJFILE_OSECTIONS (objfile, osect)
       if (section_is_overlay (osect))
 	{
@@ -3790,7 +3790,7 @@ expand_symtabs_matching
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    enum search_domain kind)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->sf)
 	objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher,
@@ -3808,7 +3808,7 @@ void
 map_symbol_filenames (symbol_filename_ftype *fun, void *data,
 		      int need_fullname)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->sf)
 	objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 92c054cba3..772dd3adb4 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -64,7 +64,7 @@ print_symbol_bcache_statistics (void)
   struct program_space *pspace;
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	QUIT;
 	printf_filtered (_("Byte cache statistics for '%s':\n"),
@@ -86,7 +86,7 @@ print_objfile_statistics (void)
   int i, linetables, blockvectors;
 
   ALL_PSPACES (pspace)
-  for (objfile *objfile : all_objfiles (pspace))
+  for (objfile *objfile : pspace->all_objfiles ())
     {
       QUIT;
       printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile));
@@ -475,7 +475,7 @@ maintenance_print_symbols (const char *args, int from_tty)
     {
       int found = 0;
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  int print_for_objfile = 1;
 
@@ -736,7 +736,7 @@ maintenance_print_msymbols (const char *args, int from_tty)
       outfile = &arg_outfile;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       QUIT;
       if (objfile_arg == NULL
@@ -756,7 +756,7 @@ maintenance_print_objfiles (const char *regexp, int from_tty)
     re_comp (regexp);
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	QUIT;
 	if (! regexp
@@ -778,7 +778,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
     re_comp (regexp);
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	/* We don't want to print anything for this objfile until we
 	   actually find a symtab whose name matches.  */
@@ -863,7 +863,7 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
   struct program_space *pspace;
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	/* We don't want to print anything for this objfile until we
 	   actually find something worth printing.  */
@@ -929,7 +929,7 @@ maintenance_expand_symtabs (const char *args, int from_tty)
     re_comp (regexp);
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	if (objfile->sf)
 	  {
@@ -1030,7 +1030,7 @@ maintenance_info_line_tables (const char *regexp, int from_tty)
     re_comp (regexp);
 
   ALL_PSPACES (pspace)
-    for (objfile *objfile : all_objfiles (pspace))
+    for (objfile *objfile : pspace->all_objfiles ())
       {
 	for (compunit_symtab *cust : objfile_compunits (objfile))
 	  {
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 29b24328fb..713b845c3a 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -473,7 +473,7 @@ iterate_over_symtabs (const char *name,
       gdb_assert (IS_ABSOLUTE_PATH (real_path.get ()));
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (iterate_over_some_symtabs (name, real_path.get (),
 				     objfile->compunit_symtabs, NULL,
@@ -484,7 +484,7 @@ iterate_over_symtabs (const char *name,
   /* Same search rules as above apply here, but now we look thru the
      psymtabs.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->sf
 	  && objfile->sf->qf->map_symtabs_matching_filename (objfile,
@@ -1010,7 +1010,7 @@ matching_obj_sections (struct obj_section *obj_first,
   /* Otherwise check that they are in corresponding objfiles.  */
 
   struct objfile *obj = NULL;
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     if (objfile->obfd == first->owner)
       {
 	obj = objfile;
@@ -1047,7 +1047,7 @@ expand_symtab_containing_pc (CORE_ADDR pc, struct obj_section *section)
 	  || MSYMBOL_TYPE (msymbol.minsym) == mst_file_bss))
     return;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       struct compunit_symtab *cust = NULL;
 
@@ -2169,7 +2169,7 @@ lookup_objfile_from_block (const struct block *block)
 
   block = block_global_block (block);
   /* Look through all blockvectors.  */
-  for (objfile *obj : all_objfiles (current_program_space))
+  for (objfile *obj : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cust : objfile_compunits (obj))
 	if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
@@ -2588,7 +2588,7 @@ lookup_static_symbol (const char *name, const domain_enum domain)
       return result;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       result = lookup_symbol_in_objfile (objfile, STATIC_BLOCK, name, domain);
       if (result.symbol != NULL)
@@ -2795,14 +2795,14 @@ basic_lookup_transparent_type (const char *name)
      of the desired name as a global, then do psymtab-to-symtab
      conversion on the fly and return the found symbol.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name);
       if (t)
 	return t;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, name);
       if (t)
@@ -2816,14 +2816,14 @@ basic_lookup_transparent_type (const char *name)
      of the desired name as a file-level static, then do psymtab-to-symtab
      conversion on the fly and return the found symbol.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name);
       if (t)
 	return t;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, name);
       if (t)
@@ -2902,7 +2902,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
      It also happens for objfiles that have their functions reordered.
      For these, the symtab we are looking for is not necessarily read in.  */
 
-  for (objfile *obj_file : all_objfiles (current_program_space))
+  for (objfile *obj_file : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cust : objfile_compunits (obj_file))
 	{
@@ -2964,7 +2964,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 
   /* Not found in symtabs, search the "quick" symtabs (e.g. psymtabs).  */
 
-  for (objfile *objf : all_objfiles (current_program_space))
+  for (objfile *objf : current_program_space->all_objfiles ())
     {
       struct compunit_symtab *result;
 
@@ -2996,7 +2996,7 @@ find_pc_compunit_symtab (CORE_ADDR pc)
 struct symbol *
 find_symbol_at_address (CORE_ADDR address)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->sf == NULL
 	  || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
@@ -3351,14 +3351,14 @@ find_line_symtab (struct symtab *sym_tab, int line,
       else
 	best = 0;
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  if (objfile->sf)
 	    objfile->sf->qf->expand_symtabs_with_fullname
 	      (objfile, symtab_to_fullname (sym_tab));
 	}
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (compunit_symtab *cu : objfile_compunits (objfile))
 	    {
@@ -4198,7 +4198,7 @@ info_sources_command (const char *ignore, int from_tty)
   printf_filtered ("Source files for which symbols have been read in:\n\n");
 
   data.first = 1;
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cu : objfile_compunits (objfile))
 	{
@@ -4453,7 +4453,7 @@ search_symbols (const char *regexp, enum search_domain kind,
 
   if (nfiles == 0 && (kind == VARIABLES_DOMAIN || kind == FUNCTIONS_DOMAIN))
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	    {
@@ -4490,7 +4490,7 @@ search_symbols (const char *regexp, enum search_domain kind,
 	}
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cust : objfile_compunits (objfile))
 	{
@@ -4556,7 +4556,7 @@ search_symbols (const char *regexp, enum search_domain kind,
   if ((found_misc || (nfiles == 0 && kind != FUNCTIONS_DOMAIN))
       && !treg.has_value ())
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	    {
@@ -5272,7 +5272,7 @@ default_collect_symbol_completion_matches_break_on
 
   if (code == TYPE_CODE_UNDEF)
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->all_objfiles ())
 	{
 	  for (minimal_symbol *msymbol : objfile_msymbols (objfile))
 	    {
@@ -5291,7 +5291,7 @@ default_collect_symbol_completion_matches_break_on
     }
 
   /* Add completions for all currently loaded symbol tables.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cust : objfile_compunits (objfile))
 	add_symtab_completions (cust, tracker, mode, lookup_name,
@@ -5600,7 +5600,7 @@ make_source_files_completion_list (const char *text, const char *word)
 
   filename_seen_cache filenames_seen;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       for (compunit_symtab *cu : objfile_compunits (objfile))
 	{
@@ -5717,7 +5717,7 @@ find_main_name (void)
      relies on the order of objfile creation -- which still isn't
      guaranteed to get the correct answer, but is just probably more
      accurate.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile->per_bfd->name_of_main != NULL)
 	{
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 9258f39eca..973871fb9a 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -423,7 +423,7 @@ windows_iterate_over_objfiles_in_search_order
 	return;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles ())
     {
       if (objfile != current_objfile)
 	{
-- 
2.17.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/6] Simplify minsym iteration
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
  2019-01-17  2:50 ` [PATCH 6/6] Make minimal symbol range adapter a method on objfile Tom Tromey
  2019-01-17  2:50 ` [PATCH 3/6] Add compunits range adapter to objfile Tom Tromey
@ 2019-01-17  2:50 ` Tom Tromey
  2019-01-17  2:50 ` [PATCH 2/6] Change all_objfiles_safe adapter to be a method on program_space Tom Tromey
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This simplifies the minimal symbol iterator, by using
minimal_symbol_count and just doing a somewhat ordinary array-like
iteration.  array_view is nearly usable, except that this iterator
must return pointers rather than references.

2019-01-16  Tom Tromey  <tom@tromey.com>

	* objfiles.h (class objfile_msymbols) <iterator>: Change argument
	type.  Remove no-argument constructor.
	<iterator::operator++>: Simplify.
	<begin>: Update.
	<end>: Use minimal_symbol_count.
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/objfiles.h | 25 ++++++-------------------
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 4c68430975..f666d558c2 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -591,20 +591,11 @@ public:
     typedef std::forward_iterator_tag iterator_category;
     typedef int difference_type;
 
-    explicit iterator (struct objfile *objfile)
-      : m_msym (objfile->per_bfd->msymbols)
+    explicit iterator (struct minimal_symbol *msym)
+      : m_msym (msym)
     {
-      /* Make sure to properly handle the case where there are no
-	 minsyms.  */
-      if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
-	m_msym = nullptr;
     }
 
-    iterator ()
-      : m_msym (nullptr)
-    {
-    }
-    
     value_type operator* () const
     {
       return m_msym;
@@ -622,12 +613,7 @@ public:
 
     self_type &operator++ ()
     {
-      if (m_msym != nullptr)
-	{
-	  ++m_msym;
-	  if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
-	    m_msym = nullptr;
-	}
+      ++m_msym;
       return *this;
     }
 
@@ -637,12 +623,13 @@ public:
 
   iterator begin () const
   {
-    return iterator (m_objfile);
+    return iterator (m_objfile->per_bfd->msymbols);
   }
 
   iterator end () const
   {
-    return iterator ();
+    return iterator (m_objfile->per_bfd->msymbols
+		     + m_objfile->per_bfd->minimal_symbol_count);
   }
 
 private:
-- 
2.17.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/6] Add compunits range adapter to objfile
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
  2019-01-17  2:50 ` [PATCH 6/6] Make minimal symbol range adapter a method on objfile Tom Tromey
@ 2019-01-17  2:50 ` Tom Tromey
  2019-01-17  2:50 ` [PATCH 5/6] Simplify minsym iteration Tom Tromey
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the objfile_compunits range adapter in favor of using a
method on objfile.

gdb/ChangeLog
2019-01-15  Tom Tromey  <tom@tromey.com>

	* symtab.c (lookup_objfile_from_block)
	(lookup_symbol_in_objfile_symtabs)
	(basic_lookup_transparent_type_1, find_pc_sect_compunit_symtab)
	(find_line_symtab, info_sources_command)
	(default_collect_symbol_completion_matches_break_on)
	(make_source_files_completion_list): Update.
	* symmisc.c (print_objfile_statistics, dump_objfile)
	(maintenance_print_symbols, maintenance_info_symtabs)
	(maintenance_check_symtabs, maintenance_info_line_tables):
	Update.
	* source.c (select_source_symtab)
	(forget_cached_source_info_for_objfile): Update.
	* objfiles.h (class objfile_compunits): Remove.
	(struct objfile) <compunits_range>: New typedef.
	(compunits): New method.
	* objfiles.c (objfile_relocate1): Update.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Update.
	* maint.c (count_symtabs_and_blocks): Update.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* cp-support.c (add_symbol_overload_list_qualified): Update.
	* coffread.c (coff_symtab_read): Update.
	* ada-lang.c (add_nonlocal_symbols)
	(ada_collect_symbol_completion_matches)
	(ada_add_global_exceptions): Update.
---
 gdb/ChangeLog        | 27 +++++++++++++++++++++++++++
 gdb/ada-lang.c       |  8 ++++----
 gdb/coffread.c       |  2 +-
 gdb/cp-support.c     |  4 ++--
 gdb/linespec.c       |  2 +-
 gdb/maint.c          |  2 +-
 gdb/mi/mi-cmd-file.c |  2 +-
 gdb/objfiles.c       |  4 ++--
 gdb/objfiles.h       | 22 +++++++++-------------
 gdb/source.c         |  4 ++--
 gdb/symmisc.c        | 16 ++++++++--------
 gdb/symtab.c         | 18 +++++++++---------
 12 files changed, 67 insertions(+), 44 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 54ac0fc668..978bfcf352 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5629,7 +5629,7 @@ add_nonlocal_symbols (struct obstack *obstackp,
 					       symbol_name_match_type::FULL,
 					       compare_names);
 
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  const struct block *global_block
 	    = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu), GLOBAL_BLOCK);
@@ -6467,7 +6467,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *s : objfile_compunits (objfile))
+      for (compunit_symtab *s : objfile->compunits ())
 	{
 	  QUIT;
 	  b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
@@ -6486,7 +6486,7 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *s : objfile_compunits (objfile))
+      for (compunit_symtab *s : objfile->compunits ())
 	{
 	  QUIT;
 	  b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
@@ -13568,7 +13568,7 @@ ada_add_global_exceptions (compiled_regex *preg,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *s : objfile_compunits (objfile))
+      for (compunit_symtab *s : objfile->compunits ())
 	{
 	  const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
 	  int i;
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 4f05295712..2b75d8189f 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1203,7 +1203,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
   /* Patch up any opaque types (references to types that are not defined
      in the file where they are referenced, e.g. "struct foo *bar").  */
   {
-    for (compunit_symtab *cu : objfile_compunits (objfile))
+    for (compunit_symtab *cu : objfile->compunits ())
       {
 	for (symtab *s : compunit_filetabs (cu))
 	  patch_opaque_types (s);
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index d147486e00..2ea5206193 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1397,7 +1397,7 @@ add_symbol_overload_list_qualified (const char *func_name,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (objfile))
+      for (compunit_symtab *cust : objfile->compunits ())
 	{
 	  QUIT;
 	  b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
@@ -1407,7 +1407,7 @@ add_symbol_overload_list_qualified (const char *func_name,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (objfile))
+      for (compunit_symtab *cust : objfile->compunits ())
 	{
 	  QUIT;
 	  b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 1cd3e251e0..769d76d3b2 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1150,7 +1150,7 @@ iterate_over_all_matching_symtabs
 						    NULL, NULL,
 						    search_domain);
 
-	for (compunit_symtab *cu : objfile_compunits (objfile))
+	for (compunit_symtab *cu : objfile->compunits ())
 	  {
 	    struct symtab *symtab = COMPUNIT_FILETABS (cu);
 
diff --git a/gdb/maint.c b/gdb/maint.c
index 0037f5e0f4..b50757039e 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -773,7 +773,7 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
     {
       for (objfile *o : current_program_space->all_objfiles ())
 	{
-	  for (compunit_symtab *cu : objfile_compunits (o))
+	  for (compunit_symtab *cu : o->compunits ())
 	    {
 	      ++nr_compunit_symtabs;
 	      nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
index a3c10955da..f24f9cf6c5 100644
--- a/gdb/mi/mi-cmd-file.c
+++ b/gdb/mi/mi-cmd-file.c
@@ -94,7 +94,7 @@ mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc)
   /* Look at all of the file symtabs.  */
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  for (symtab *s : compunit_filetabs (cu))
 	    {
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index e9432ca145..e592dfb7bd 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -787,7 +787,7 @@ objfile_relocate1 (struct objfile *objfile,
 
   /* OK, get all the symtabs.  */
   {
-    for (compunit_symtab *cust : objfile_compunits (objfile))
+    for (compunit_symtab *cust : objfile->compunits ())
       {
 	for (symtab *s : compunit_filetabs (cust))
 	  {
@@ -805,7 +805,7 @@ objfile_relocate1 (struct objfile *objfile,
 	  }
       }
 
-    for (compunit_symtab *cust : objfile_compunits (objfile))
+    for (compunit_symtab *cust : objfile->compunits ())
       {
 	const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (cust);
 	int block_line_section = COMPUNIT_BLOCK_LINE_SECTION (cust);
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 244c1280be..86c88fc512 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -301,6 +301,15 @@ struct objfile
     partial_symtabs.reset (new psymtab_storage ());
   }
 
+  typedef next_adapter<struct compunit_symtab> compunits_range;
+
+  /* A range adapter that makes it possible to iterate over all
+     compunits in one objfile.  */
+
+  compunits_range compunits ()
+  {
+    return compunits_range (compunit_symtabs);
+  }
 
   /* All struct objfile's are chained together by their next pointers.
      The program space field "objfiles"  (frequently referenced via
@@ -553,19 +562,6 @@ extern void default_iterate_over_objfiles_in_search_order
    void *cb_data, struct objfile *current_objfile);
 \f
 
-/* A range adapter that makes it possible to iterate over all
-   compunits in one objfile.  */
-
-class objfile_compunits : public next_adapter<struct compunit_symtab>
-{
-public:
-
-  explicit objfile_compunits (struct objfile *objfile)
-    : next_adapter<struct compunit_symtab> (objfile->compunit_symtabs)
-  {
-  }
-};
-
 /* A range adapter that makes it possible to iterate over all
    minimal symbols of an objfile.  */
 
diff --git a/gdb/source.c b/gdb/source.c
index 120bceb44b..202843d41c 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -271,7 +271,7 @@ select_source_symtab (struct symtab *s)
 
   for (objfile *ofp : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cu : objfile_compunits (ofp))
+      for (compunit_symtab *cu : ofp->compunits ())
 	{
 	  for (symtab *symtab : compunit_filetabs (cu))
 	    {
@@ -353,7 +353,7 @@ show_directories_command (struct ui_file *file, int from_tty,
 void
 forget_cached_source_info_for_objfile (struct objfile *objfile)
 {
-  for (compunit_symtab *cu : objfile_compunits (objfile))
+  for (compunit_symtab *cu : objfile->compunits ())
     {
       for (symtab *s : compunit_filetabs (cu))
 	{
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 772dd3adb4..11a3b7f4f0 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -108,7 +108,7 @@ print_objfile_statistics (void)
       if (objfile->sf)
 	objfile->sf->qf->print_stats (objfile);
       i = linetables = 0;
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  for (symtab *s : compunit_filetabs (cu))
 	    {
@@ -117,8 +117,8 @@ print_objfile_statistics (void)
 		linetables++;
 	    }
 	}
-      blockvectors = std::distance (objfile_compunits (objfile).begin (),
-				    objfile_compunits (objfile).end ());
+      blockvectors = std::distance (objfile->compunits ().begin (),
+				    objfile->compunits ().end ());
       printf_filtered (_("  Number of symbol tables: %d\n"), i);
       printf_filtered (_("  Number of symbol tables with line tables: %d\n"),
 		       linetables);
@@ -162,7 +162,7 @@ dump_objfile (struct objfile *objfile)
   if (objfile->compunit_symtabs != NULL)
     {
       printf_filtered ("Symtabs:\n");
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  for (symtab *symtab : compunit_filetabs (cu))
 	    {
@@ -486,7 +486,7 @@ maintenance_print_symbols (const char *args, int from_tty)
 	  if (!print_for_objfile)
 	    continue;
 
-	  for (compunit_symtab *cu : objfile_compunits (objfile))
+	  for (compunit_symtab *cu : objfile->compunits ())
 	    {
 	      for (symtab *s : compunit_filetabs (cu))
 		{
@@ -784,7 +784,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 	   actually find a symtab whose name matches.  */
 	int printed_objfile_start = 0;
 
-	for (compunit_symtab *cust : objfile_compunits (objfile))
+	for (compunit_symtab *cust : objfile->compunits ())
 	  {
 	    int printed_compunit_symtab_start = 0;
 
@@ -869,7 +869,7 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
 	   actually find something worth printing.  */
 	int printed_objfile_start = 0;
 
-	for (compunit_symtab *cust : objfile_compunits (objfile))
+	for (compunit_symtab *cust : objfile->compunits ())
 	  {
 	    int found_something = 0;
 	    struct symtab *symtab = compunit_primary_filetab (cust);
@@ -1032,7 +1032,7 @@ maintenance_info_line_tables (const char *regexp, int from_tty)
   ALL_PSPACES (pspace)
     for (objfile *objfile : pspace->all_objfiles ())
       {
-	for (compunit_symtab *cust : objfile_compunits (objfile))
+	for (compunit_symtab *cust : objfile->compunits ())
 	  {
 	    for (symtab *symtab : compunit_filetabs (cust))
 	      {
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 713b845c3a..867fb6c927 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2171,7 +2171,7 @@ lookup_objfile_from_block (const struct block *block)
   /* Look through all blockvectors.  */
   for (objfile *obj : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (obj))
+      for (compunit_symtab *cust : obj->compunits ())
 	if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
 					GLOBAL_BLOCK))
 	  {
@@ -2265,7 +2265,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
 			  name, domain_name (domain));
     }
 
-  for (compunit_symtab *cust : objfile_compunits (objfile))
+  for (compunit_symtab *cust : objfile->compunits ())
     {
       const struct blockvector *bv;
       const struct block *block;
@@ -2763,7 +2763,7 @@ basic_lookup_transparent_type_1 (struct objfile *objfile, int block_index,
   const struct block *block;
   const struct symbol *sym;
 
-  for (compunit_symtab *cust : objfile_compunits (objfile))
+  for (compunit_symtab *cust : objfile->compunits ())
     {
       bv = COMPUNIT_BLOCKVECTOR (cust);
       block = BLOCKVECTOR_BLOCK (bv, block_index);
@@ -2904,7 +2904,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 
   for (objfile *obj_file : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (obj_file))
+      for (compunit_symtab *cust : obj_file->compunits ())
 	{
 	  struct block *b;
 	  const struct blockvector *bv;
@@ -3360,7 +3360,7 @@ find_line_symtab (struct symtab *sym_tab, int line,
 
       for (objfile *objfile : current_program_space->all_objfiles ())
 	{
-	  for (compunit_symtab *cu : objfile_compunits (objfile))
+	  for (compunit_symtab *cu : objfile->compunits ())
 	    {
 	      for (symtab *s : compunit_filetabs (cu))
 		{
@@ -4200,7 +4200,7 @@ info_sources_command (const char *ignore, int from_tty)
   data.first = 1;
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  for (symtab *s : compunit_filetabs (cu))
 	    {
@@ -4492,7 +4492,7 @@ search_symbols (const char *regexp, enum search_domain kind,
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (objfile))
+      for (compunit_symtab *cust : objfile->compunits ())
 	{
 	  bv = COMPUNIT_BLOCKVECTOR (cust);
 	  for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
@@ -5293,7 +5293,7 @@ default_collect_symbol_completion_matches_break_on
   /* Add completions for all currently loaded symbol tables.  */
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (objfile))
+      for (compunit_symtab *cust : objfile->compunits ())
 	add_symtab_completions (cust, tracker, mode, lookup_name,
 				sym_text, word, code);
     }
@@ -5602,7 +5602,7 @@ make_source_files_completion_list (const char *text, const char *word)
 
   for (objfile *objfile : current_program_space->all_objfiles ())
     {
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  for (symtab *s : compunit_filetabs (cu))
 	    {
-- 
2.17.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/6] Change all_objfiles_safe adapter to be a method on program_space
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
                   ` (2 preceding siblings ...)
  2019-01-17  2:50 ` [PATCH 5/6] Simplify minsym iteration Tom Tromey
@ 2019-01-17  2:50 ` Tom Tromey
  2019-01-17  2:50 ` [PATCH 4/6] Make psymtab range adapter a method on objfile Tom Tromey
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the all_objfiles_safe range adapter to be a method on the
program space, and fixes up all the users.

gdb/ChangeLog
2019-01-15  Tom Tromey  <tom@tromey.com>

	* progspace.h (program_space) <all_objfiles_safe_range>: New
	typedef.
	<all_objfiles_safe>: New method.
	* objfiles.h (class all_objfiles_safe): Remove.
	* objfiles.c (free_all_objfiles, objfile_purge_solibs): Update.
	* jit.c (jit_inferior_exit_hook): Update.
---
 gdb/ChangeLog   | 11 ++++++++++-
 gdb/jit.c       |  2 +-
 gdb/objfiles.c  |  4 ++--
 gdb/objfiles.h  | 22 ----------------------
 gdb/progspace.h | 18 ++++++++++++++++++
 5 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/gdb/jit.c b/gdb/jit.c
index 543eb60995..645b3ff97e 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1391,7 +1391,7 @@ jit_breakpoint_re_set (void)
 static void
 jit_inferior_exit_hook (struct inferior *inf)
 {
-  for (objfile *objf : all_objfiles_safe (current_program_space))
+  for (objfile *objf : current_program_space->all_objfiles_safe ())
     {
       struct jit_objfile_data *objf_data
 	= (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data);
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 569e308b6b..e9432ca145 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -735,7 +735,7 @@ free_all_objfiles (void)
   for (so = master_so_list (); so; so = so->next)
     gdb_assert (so->objfile == NULL);
 
-  for (objfile *objfile : all_objfiles_safe (current_program_space))
+  for (objfile *objfile : current_program_space->all_objfiles_safe ())
     delete objfile;
   clear_symtab_users (0);
 }
@@ -1044,7 +1044,7 @@ have_full_symbols (void)
 void
 objfile_purge_solibs (void)
 {
-  for (objfile *objf : all_objfiles_safe (current_program_space))
+  for (objfile *objf : current_program_space->all_objfiles_safe ())
     {
       /* We assume that the solib package has been purged already, or will
 	 be soon.  */
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 9ab0f38280..244c1280be 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -553,28 +553,6 @@ extern void default_iterate_over_objfiles_in_search_order
    void *cb_data, struct objfile *current_objfile);
 \f
 
-/* An iterarable object that can be used to iterate over all
-   objfiles.  The basic use is in a foreach, like:
-
-   for (objfile *objf : all_objfiles_safe (pspace)) { ... }
-
-   This variant uses a basic_safe_iterator so that objfiles can be
-   deleted during iteration.  */
-
-class all_objfiles_safe
-  : public next_adapter<struct objfile,
-			basic_safe_iterator<next_iterator<objfile>>>
-{
-public:
-
-  explicit all_objfiles_safe (struct program_space *pspace)
-    : next_adapter<struct objfile,
-		   basic_safe_iterator<next_iterator<objfile>>>
-        (pspace->objfiles)
-  {
-  }
-};
-
 /* A range adapter that makes it possible to iterate over all
    compunits in one objfile.  */
 
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 5006840d85..dd97a4e2be 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -26,6 +26,8 @@
 #include "gdb_bfd.h"
 #include "gdb_vecs.h"
 #include "registry.h"
+#include "common/next-iterator.h"
+#include "common/safe-iterator.h"
 
 struct target_ops;
 struct bfd;
@@ -148,6 +150,22 @@ struct program_space
     return all_objfiles_range (objfiles);
   }
 
+  typedef next_adapter<struct objfile,
+		       basic_safe_iterator<next_iterator<objfile>>>
+    all_objfiles_safe_range;
+
+  /* An iterable object that can be used to iterate over all objfiles.
+     The basic use is in a foreach, like:
+
+     for (objfile *objf : pspace->all_objfiles_safe ()) { ... }
+
+     This variant uses a basic_safe_iterator so that objfiles can be
+     deleted during iteration.  */
+  all_objfiles_safe_range all_objfiles_safe ()
+  {
+    return all_objfiles_safe_range (objfiles);
+  }
+
   /* Pointer to next in linked list.  */
   struct program_space *next = NULL;
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/6] Make psymtab range adapter a method on objfile
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
                   ` (3 preceding siblings ...)
  2019-01-17  2:50 ` [PATCH 2/6] Change all_objfiles_safe adapter to be a method on program_space Tom Tromey
@ 2019-01-17  2:50 ` Tom Tromey
  2019-01-17  2:50 ` [PATCH 1/6] Change all_objfiles adapter to be a method on program_space Tom Tromey
  2019-01-17 13:58 ` [PATCH 0/6] change range adapters to be member functions Pedro Alves
  6 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the objfile_psymtabs class in favor of a method on
objfile and on psymtab_storage.

2019-01-16  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile) <psymtabs>: New method.
	(class objfile_psymtabs): Remove.
	* psymtab.h (class psymtab_storage) <partial_symtab_range>: New
	typedef.
	<range>: New method.
	(require_partial_symbols): Change return type.
	* psymtab.c (require_partial_symbols)
	(psym_expand_symtabs_matching): Update.
	* mdebugread.c (parse_partial_symbols): Update.
	* dbxread.c (dbx_end_psymtab): Update.
---
 gdb/ChangeLog    | 13 +++++++++++++
 gdb/dbxread.c    |  2 +-
 gdb/mdebugread.c |  2 +-
 gdb/objfiles.h   | 21 ++++++++-------------
 gdb/psymtab.c    |  6 +++---
 gdb/psymtab.h    | 15 ++++++++++++---
 6 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 25bcc2778c..60d384b27f 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2011,7 +2011,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
          address, set it to our starting address.  Take care to not set our
          own ending address to our starting address.  */
 
-      for (partial_symtab *p1 : objfile_psymtabs (objfile))
+      for (partial_symtab *p1 : objfile->psymtabs ())
 	if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
 	  p1->set_text_high (pst->raw_text_low ());
     }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 4bdf9731cf..accf07c278 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3684,7 +3684,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	  && save_pst->text_low_valid
 	  && !(objfile->flags & OBJF_REORDERED))
 	{
-	  for (partial_symtab *iter : objfile_psymtabs (objfile))
+	  for (partial_symtab *iter : objfile->psymtabs ())
 	    {
 	      if (save_pst != iter
 		  && save_pst->raw_text_low () >= iter->raw_text_low ()
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 86c88fc512..4c68430975 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -293,6 +293,14 @@ struct objfile
 
   DISABLE_COPY_AND_ASSIGN (objfile);
 
+  /* A range adapter that makes it possible to iterate over all
+     psymtabs in one objfile.  */
+
+  psymtab_storage::partial_symtab_range psymtabs ()
+  {
+    return partial_symtabs->range ();
+  }
+
   /* Reset the storage for the partial symbol tables.  */
 
   void reset_psymtabs ()
@@ -642,19 +650,6 @@ private:
   struct objfile *m_objfile;
 };
 
-/* A range adapter that makes it possible to iterate over all
-   psymtabs in one objfile.  */
-
-class objfile_psymtabs : public next_adapter<struct partial_symtab>
-{
-public:
-
-  explicit objfile_psymtabs (struct objfile *objfile)
-    : next_adapter<struct partial_symtab> (objfile->partial_symtabs->psymtabs)
-  {
-  }
-};
-
 #define ALL_OBJFILE_OSECTIONS(objfile, osect)	\
   for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
     if (osect->the_bfd_section == NULL)					\
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1ee63dc20c..e209c6b2bd 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -104,7 +104,7 @@ psymtab_storage::allocate_psymtab ()
 
 /* See psymtab.h.  */
 
-objfile_psymtabs
+psymtab_storage::partial_symtab_range
 require_partial_symbols (struct objfile *objfile, int verbose)
 {
   if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
@@ -129,7 +129,7 @@ require_partial_symbols (struct objfile *objfile, int verbose)
 	}
     }
 
-  return objfile_psymtabs (objfile);
+  return objfile->psymtabs ();
 }
 
 /* Helper function for psym_map_symtabs_matching_filename that
@@ -1341,7 +1341,7 @@ psym_expand_symtabs_matching
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     ps->searched_flag = PST_NOT_SEARCHED;
 
-  for (partial_symtab *ps : objfile_psymtabs (objfile))
+  for (partial_symtab *ps : objfile->psymtabs ())
     {
       QUIT;
 
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index 26aeb29646..3ee5eee0b6 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -92,6 +92,16 @@ public:
 
   struct partial_symtab *allocate_psymtab ();
 
+  typedef next_adapter<struct partial_symtab> partial_symtab_range;
+
+  /* A range adapter that makes it possible to iterate over all
+     psymtabs in one objfile.  */
+
+  partial_symtab_range range ()
+  {
+    return partial_symtab_range (psymtabs);
+  }
+
 
   /* Each objfile points to a linked list of partial symtabs derived from
      this file, one partial symtab structure for each compilation unit
@@ -144,8 +154,7 @@ extern const struct quick_symbol_functions dwarf2_debug_names_functions;
    are loaded.  This function returns a range adapter suitable for
    iterating over the psymtabs of OBJFILE.  */
 
-class objfile_psymtabs;
-extern objfile_psymtabs require_partial_symbols (struct objfile *objfile,
-						 int verbose);
+extern psymtab_storage::partial_symtab_range require_partial_symbols
+    (struct objfile *objfile, int verbose);
 
 #endif /* PSYMTAB_H */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/6] change range adapters to be member functions
  2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
                   ` (5 preceding siblings ...)
  2019-01-17  2:50 ` [PATCH 1/6] Change all_objfiles adapter to be a method on program_space Tom Tromey
@ 2019-01-17 13:58 ` Pedro Alves
  2019-01-17 23:11   ` Tom Tromey
  6 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2019-01-17 13:58 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 01/17/2019 02:50 AM, Tom Tromey wrote:
> In the ALL_* removal series, Pedro pointed out that the range adapter
> classes would be nicer as member functions of the relevant class.
> 
> This series implements this idea.  Most of these patches were written
> using a script.
> 
> While looking at changing the minimal symbol iterator, I noticed that
> the implementation could be simplified, so I've included this as patch
> #5.
> 
> Regression tested by the buildbot.

Thanks.

On patches #1 and #2, I'd rather drop the "all_" from the method
names, to follow the pattern in the inferiors/threads ranges, where
we have:

 all_threads ()
 all_inferiors ()
vs
 inf->threads()

When I was doing that initially, I went back and forth picking
those names.  At some point I had the global functions
called just threads() and inferiors(), and that turned out
confusing.  I also tried naming the inferior method all_threads(),
and found that confusing as well.  In the end I settled on "all_" for
the top level functions because those really iterate over all
objects.  I.e., all_threads iterates over all threads of all
inferiors.  While inf->threads() iterates over threads of only
that inferior, of course.

I tried doing that change locally, and it didn't turn up anything
tricky to fix.  All we need to do is rename the current
program_space::objfiles field, and the only fallback is the
object_files macro.  See below.  I'm not including the rest of the
patch since that's just a global search&replace, and you have that
spread between two commits, so probably wouldn't help.

On patch #5 the commit log says:

 "array_view is nearly usable, except that this iterator
  must return pointers rather than references."

I found that "must" intriguing.  It's not that it
must -- with array_view, we could still write code like this:

 -	  for (minimal_symbol *msymbol : objfile->msymbols ())
 +	  for (minimal_symbol &msymbol : objfile->msymbols ())
            {
	      /* Also handle minimal symbols pointing to function
		 descriptors.  */
 -	      if ((MSYMBOL_TYPE (msymbol) == mst_text
 +	      if ((MSYMBOL_TYPE (&msymbol) == mst_text

            }

Or this:

	  for (minimal_symbol &msym_ref : objfile->msymbols ())
	    {
               minimal_symbol *msymbol = &msym_ref;


But that's just not convenient, when most code expects minimal_symbol
pointers.

So I think it'd be fitting to update the commit log to replace
the "must" with "more convenient" or something like it.  Maybe
even add a comment to the code.

Otherwise LGTM.  Thanks for doing this.

diff --git c/gdb/progspace.h w/gdb/progspace.h
index dd97a4e2be..9a061a6e5e 100644
--- c/gdb/progspace.h
+++ w/gdb/progspace.h
@@ -139,31 +139,32 @@ struct program_space
   program_space (address_space *aspace_);
   ~program_space ();
 
-  typedef next_adapter<struct objfile> all_objfiles_range;
+  typedef next_adapter<struct objfile> objfiles_range;
 
   /* Return an iterarable object that can be used to iterate over all
-     objfiles.  The basic use is in a foreach, like:
+     objfiles in the program space.  The basic use is in a foreach,
+     like:
 
-     for (objfile *objf : pspace->all_objfiles ()) { ... }  */
-  all_objfiles_range all_objfiles ()
+     for (objfile *objf : pspace->objfiles ()) { ... }  */
+  objfiles_range objfiles ()
   {
-    return all_objfiles_range (objfiles);
+    return objfiles_range (objfiles_head);
   }
 
   typedef next_adapter<struct objfile,
 		       basic_safe_iterator<next_iterator<objfile>>>
-    all_objfiles_safe_range;
+    objfiles_safe_range;
 
   /* An iterable object that can be used to iterate over all objfiles.
      The basic use is in a foreach, like:
 
-     for (objfile *objf : pspace->all_objfiles_safe ()) { ... }
+     for (objfile *objf : pspace->objfiles_safe ()) { ... }
 
      This variant uses a basic_safe_iterator so that objfiles can be
      deleted during iteration.  */
-  all_objfiles_safe_range all_objfiles_safe ()
+  objfiles_safe_range objfiles_safe ()
   {
-    return all_objfiles_safe_range (objfiles);
+    return objfiles_safe_range (objfiles_head);
   }
 
   /* Pointer to next in linked list.  */
@@ -218,7 +219,7 @@ struct program_space
 
   /* All known objfiles are kept in a linked list.  This points to
      the head of this list.  */
-  struct objfile *objfiles = NULL;
+  struct objfile *objfiles_head = NULL;
 
   /* The set of target sections matching the sections mapped into
      this program space.  Managed by both exec_ops and solib.c.  */
@@ -261,7 +262,7 @@ struct address_space
 
 /* All known objfiles are kept in a linked list.  This points to the
    root of this list.  */
-#define object_files current_program_space->objfiles
+#define object_files current_program_space->objfiles_head
 
 /* The set of target sections matching the sections mapped into the
    current program space.  */

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/6] change range adapters to be member functions
  2019-01-17 13:58 ` [PATCH 0/6] change range adapters to be member functions Pedro Alves
@ 2019-01-17 23:11   ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2019-01-17 23:11 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> On patches #1 and #2, I'd rather drop the "all_" from the method
Pedro> names, to follow the pattern in the inferiors/threads ranges, where
Pedro> we have:
[...]

I made this change.

Pedro> On patch #5 the commit log says:
Pedro>  "array_view is nearly usable, except that this iterator
Pedro>   must return pointers rather than references."
Pedro> I found that "must" intriguing.  It's not that it
Pedro> must -- with array_view, we could still write code like this:
[...]
Pedro> So I think it'd be fitting to update the commit log to replace
Pedro> the "must" with "more convenient" or something like it.  Maybe
Pedro> even add a comment to the code.

I reworded the commit message.

I've re-run this through the buildbot, and I'm going to push it soon.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-01-17 23:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17  2:50 [PATCH 0/6] change range adapters to be member functions Tom Tromey
2019-01-17  2:50 ` [PATCH 6/6] Make minimal symbol range adapter a method on objfile Tom Tromey
2019-01-17  2:50 ` [PATCH 3/6] Add compunits range adapter to objfile Tom Tromey
2019-01-17  2:50 ` [PATCH 5/6] Simplify minsym iteration Tom Tromey
2019-01-17  2:50 ` [PATCH 2/6] Change all_objfiles_safe adapter to be a method on program_space Tom Tromey
2019-01-17  2:50 ` [PATCH 4/6] Make psymtab range adapter a method on objfile Tom Tromey
2019-01-17  2:50 ` [PATCH 1/6] Change all_objfiles adapter to be a method on program_space Tom Tromey
2019-01-17 13:58 ` [PATCH 0/6] change range adapters to be member functions Pedro Alves
2019-01-17 23:11   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).