/* Definitions for symbol file management in GDB.
- Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ Copyright (C) 1992-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "registry.h"
#include "gdb_bfd.h"
#include <vector>
+#include "common/next-iterator.h"
+#include "common/safe-iterator.h"
struct bcache;
struct htab;
/* In normal use, the section map will be rebuilt by find_pc_section
if objfiles have been added, removed or relocated since it was last
called. Calling inhibit_section_map_updates will inhibit this
- behavior until resume_section_map_updates is called. If you call
- inhibit_section_map_updates you must ensure that every call to
- find_pc_section in the inhibited region relates to a section that
- is already in the section map and has not since been removed or
- relocated. */
-extern void inhibit_section_map_updates (struct program_space *pspace);
-
-/* Resume automatically rebuilding the section map as required. */
-extern void resume_section_map_updates (struct program_space *pspace);
-
-/* Version of the above suitable for use as a cleanup. */
-extern void resume_section_map_updates_cleanup (void *arg);
+ behavior until the returned scoped_restore object is destroyed. If
+ you call inhibit_section_map_updates you must ensure that every
+ call to find_pc_section in the inhibited region relates to a
+ section that is already in the section map and has not since been
+ removed or relocated. */
+extern scoped_restore_tmpl<int> inhibit_section_map_updates
+ (struct program_space *pspace);
extern void default_iterate_over_objfiles_in_search_order
(struct gdbarch *gdbarch,
void *cb_data, struct objfile *current_objfile);
\f
-/* Traverse all object files in the current program space.
- ALL_OBJFILES_SAFE works even if you delete the objfile during the
- traversal. */
+/* 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:
-/* Traverse all object files in program space SS. */
+ for (objfile *objf : all_objfiles_safe (pspace)) { ... }
-#define ALL_PSPACE_OBJFILES(ss, obj) \
- for ((obj) = ss->objfiles; (obj) != NULL; (obj) = (obj)->next)
+ 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)
+ {
+ }
+};
+
+
+/* Traverse all object files in the current program space. */
#define ALL_OBJFILES(obj) \
for ((obj) = current_program_space->objfiles; \
(obj) != NULL; \
(obj) = (obj)->next)
-#define ALL_OBJFILES_SAFE(obj,nxt) \
- for ((obj) = current_program_space->objfiles; \
- (obj) != NULL? ((nxt)=(obj)->next,1) :0; \
- (obj) = (nxt))
-
/* Traverse all symtabs in one objfile. */
#define ALL_OBJFILE_FILETABS(objfile, cu, s) \
#define ALL_OBJFILE_COMPUNITS(objfile, cu) \
for ((cu) = (objfile) -> compunit_symtabs; (cu) != NULL; (cu) = (cu) -> next)
-/* Traverse all minimal symbols in one objfile. */
+/* A range adapter that makes it possible to iterate over all
+ minimal symbols of an objfile. */
-#define ALL_OBJFILE_MSYMBOLS(objfile, m) \
- for ((m) = (objfile)->per_bfd->msymbols; \
- MSYMBOL_LINKAGE_NAME (m) != NULL; \
- (m)++)
+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 objfile *objfile)
+ : m_msym (objfile->per_bfd->msymbols)
+ {
+ /* 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;
+ }
+
+ 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++ ()
+ {
+ if (m_msym != nullptr)
+ {
+ ++m_msym;
+ if (MSYMBOL_LINKAGE_NAME (m_msym) == nullptr)
+ m_msym = nullptr;
+ }
+ return *this;
+ }
+
+ private:
+ struct minimal_symbol *m_msym;
+ };
+
+ iterator begin () const
+ {
+ return iterator (m_objfile);
+ }
+
+ iterator end () const
+ {
+ return iterator ();
+ }
+
+private:
+
+ struct objfile *m_objfile;
+};
/* Traverse all symtabs in all objfiles in the current symbol
space. */
ALL_OBJFILES (objfile) \
ALL_OBJFILE_COMPUNITS (objfile, cu)
-/* Traverse all minimal symbols in all objfiles in the current symbol
- space. */
-
-#define ALL_MSYMBOLS(objfile, m) \
- ALL_OBJFILES (objfile) \
- ALL_OBJFILE_MSYMBOLS (objfile, m)
-
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
if (osect->the_bfd_section == NULL) \