-\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:
-
- 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)
- {
- }
-};
-
-
-/* Traverse all object files in the current program space. */
-
-#define ALL_OBJFILES(obj) \
- for ((obj) = current_program_space->objfiles; \
- (obj) != NULL; \
- (obj) = (obj)->next)
-
-/* 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. */
-
-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. */
-
-#define ALL_FILETABS(objfile, ps, s) \
- ALL_OBJFILES (objfile) \
- for (compunit_symtab *ps : objfile_compunits (objfile)) \
- for (symtab *s : compunit_filetabs (cu))
-
-#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
- for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
- if (osect->the_bfd_section == NULL) \
- { \
- /* Nothing. */ \
- } \
- else
-
-/* Traverse all obj_sections in all objfiles in the current program
- space.
-
- Note that this detects a "break" in the inner loop, and exits
- immediately from the outer loop as well, thus, client code doesn't
- need to know that this is implemented with a double for. The extra
- hair is to make sure that a "break;" stops the outer loop iterating
- as well, and both OBJFILE and OSECT are left unmodified:
-
- - The outer loop learns about the inner loop's end condition, and
- stops iterating if it detects the inner loop didn't reach its
- end. In other words, the outer loop keeps going only if the
- inner loop reached its end cleanly [(osect) ==
- (objfile)->sections_end].
-
- - OSECT is initialized in the outer loop initialization
- expressions, such as if the inner loop has reached its end, so
- the check mentioned above succeeds the first time.
-
- - The trick to not clearing OBJFILE on a "break;" is, in the outer
- loop's loop expression, advance OBJFILE, but iff the inner loop
- reached its end. If not, there was a "break;", so leave OBJFILE
- as is; the outer loop's conditional will break immediately as
- well (as OSECT will be different from OBJFILE->sections_end). */
-
-#define ALL_OBJSECTIONS(objfile, osect) \
- for ((objfile) = current_program_space->objfiles, \
- (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0; \
- (objfile) != NULL \
- && (osect) == (objfile)->sections_end; \
- ((osect) == (objfile)->sections_end \
- ? ((objfile) = (objfile)->next, \
- (objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \
- : 0)) \
- ALL_OBJFILE_OSECTIONS (objfile, osect)
-
-#define SECT_OFF_DATA(objfile) \
- ((objfile->sect_index_data == -1) \
- ? (internal_error (__FILE__, __LINE__, \
- _("sect_index_data not initialized")), -1) \
- : objfile->sect_index_data)
-
-#define SECT_OFF_RODATA(objfile) \
- ((objfile->sect_index_rodata == -1) \
- ? (internal_error (__FILE__, __LINE__, \
- _("sect_index_rodata not initialized")), -1) \
- : objfile->sect_index_rodata)
-
-#define SECT_OFF_TEXT(objfile) \
- ((objfile->sect_index_text == -1) \
- ? (internal_error (__FILE__, __LINE__, \
- _("sect_index_text not initialized")), -1) \
- : objfile->sect_index_text)
-
-/* Sometimes the .bss section is missing from the objfile, so we don't
- want to die here. Let the users of SECT_OFF_BSS deal with an
- uninitialized section index. */
-#define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
-
-/* Answer whether there is more than one object file loaded. */
-
-#define MULTI_OBJFILE_P() (object_files && object_files->next)