diff --git a/gdb/objfiles.h b/gdb/objfiles.h index d92570a00bd..bd65e2bd030 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -418,7 +418,7 @@ struct obj_section symbols, lookup_symbol is used to check if we only have a partial symbol and if so, read and expand the full compunit. */ -struct objfile +struct objfile : intrusive_list_node { private: diff --git a/gdb/progspace.c b/gdb/progspace.c index 28198c1e8a4..94175d36c18 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -124,6 +124,15 @@ program_space::~program_space () /* See progspace.h. */ +bool +program_space::multi_objfile_p () const +{ + return (!objfiles_list.empty () + && std::next (objfiles_list.begin ()) != objfiles_list.end ()); +} + +/* See progspace.h. */ + void program_space::free_all_objfiles () { @@ -132,7 +141,7 @@ program_space::free_all_objfiles () gdb_assert (so.objfile == NULL); while (!objfiles_list.empty ()) - objfiles_list.front ()->unlink (); + this->remove_objfile (&objfiles_list.front ()); } /* See progspace.h. */ @@ -145,13 +154,9 @@ program_space::add_objfile (std::unique_ptr &&objfile, objfiles_list.push_back (std::move (objfile)); else { - auto iter = std::find_if (objfiles_list.begin (), objfiles_list.end (), - [=] (const std::unique_ptr<::objfile> &objf) - { - return objf.get () == before; - }); - gdb_assert (iter != objfiles_list.end ()); - objfiles_list.insert (iter, std::move (objfile)); + gdb_assert (before->is_linked ()); + objfiles_list.insert (objfiles_list.iterator_to (*before), + std::move (objfile)); } } @@ -166,16 +171,11 @@ program_space::remove_objfile (struct objfile *objfile) reference stale info. */ reinit_frame_cache (); - auto iter = std::find_if (objfiles_list.begin (), objfiles_list.end (), - [=] (const std::unique_ptr<::objfile> &objf) - { - return objf.get () == objfile; - }); - gdb_assert (iter != objfiles_list.end ()); - objfiles_list.erase (iter); - if (objfile == symfile_object_file) symfile_object_file = NULL; + + gdb_assert (objfile->is_linked ()); + objfiles_list.erase (objfiles_list.iterator_to (*objfile)); } /* See progspace.h. */ diff --git a/gdb/progspace.h b/gdb/progspace.h index 999e7a39182..4f98b4576a5 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -29,7 +29,6 @@ #include "gdbsupport/intrusive_list.h" #include "gdbsupport/refcounted-object.h" #include "gdbsupport/gdb_ref_ptr.h" -#include #include struct target_ops; @@ -41,8 +40,6 @@ struct address_space; struct program_space; struct solib; -typedef std::list> objfile_list; - /* An address space. It is used for comparing if pspaces/inferior/threads see the same address space and for associating caches to each address space. */ @@ -77,55 +74,6 @@ new_address_space () return address_space_ref_ptr::new_reference (new address_space); } -/* An iterator that wraps an iterator over std::unique_ptr, - and dereferences the returned object. This is useful for iterating - over a list of shared pointers and returning raw pointers -- which - helped avoid touching a lot of code when changing how objfiles are - managed. */ - -class unwrapping_objfile_iterator -{ -public: - - typedef unwrapping_objfile_iterator self_type; - typedef typename ::objfile *value_type; - typedef typename ::objfile &reference; - typedef typename ::objfile **pointer; - typedef typename objfile_list::iterator::iterator_category iterator_category; - typedef typename objfile_list::iterator::difference_type difference_type; - - unwrapping_objfile_iterator (objfile_list::iterator iter) - : m_iter (std::move (iter)) - { - } - - objfile *operator* () const - { - return m_iter->get (); - } - - unwrapping_objfile_iterator operator++ () - { - ++m_iter; - return *this; - } - - bool operator!= (const unwrapping_objfile_iterator &other) const - { - return m_iter != other.m_iter; - } - -private: - - /* The underlying iterator. */ - objfile_list::iterator m_iter; -}; - - -/* A range that returns unwrapping_objfile_iterators. */ - -using unwrapping_objfile_range = iterator_range; - /* A program space represents a symbolic view of an address space. Roughly speaking, it holds all the data associated with a non-running-yet program (main executable, main symbols), and when @@ -235,7 +183,9 @@ struct program_space a program space. */ ~program_space (); - using objfiles_range = unwrapping_objfile_range; + using objfiles_iterator + = reference_to_pointer_iterator::iterator>; + using objfiles_range = iterator_range; /* Return an iterable object that can be used to iterate over all objfiles. The basic use is in a foreach, like: @@ -243,9 +193,7 @@ struct program_space for (objfile *objf : pspace->objfiles ()) { ... } */ objfiles_range objfiles () { - return objfiles_range - (unwrapping_objfile_iterator (objfiles_list.begin ()), - unwrapping_objfile_iterator (objfiles_list.end ())); + return objfiles_range (objfiles_iterator (objfiles_list.begin ())); } using objfiles_safe_range = basic_safe_range; @@ -260,9 +208,7 @@ struct program_space objfiles_safe_range objfiles_safe () { return objfiles_safe_range - (objfiles_range - (unwrapping_objfile_iterator (objfiles_list.begin ()), - unwrapping_objfile_iterator (objfiles_list.end ()))); + (objfiles_range (objfiles_iterator (objfiles_list.begin ()))); } /* Add OBJFILE to the list of objfiles, putting it just before @@ -276,10 +222,7 @@ struct program_space /* Return true if there is more than one object file loaded; false otherwise. */ - bool multi_objfile_p () const - { - return objfiles_list.size () > 1; - } + bool multi_objfile_p () const; /* Free all the objfiles associated with this program space. */ void free_all_objfiles (); @@ -395,7 +338,7 @@ struct program_space struct objfile *symfile_object_file = NULL; /* All known objfiles are kept in a linked list. */ - std::list> objfiles_list; + owning_intrusive_list objfiles_list; /* List of shared objects mapped into this space. Managed by solib.c. */ diff --git a/gdb/source.c b/gdb/source.c index 32099b9ea7d..3410e865cdf 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -27,6 +27,7 @@ #include "value.h" #include "gdbsupport/filestuff.h" +#include #include #include #include "gdbcore.h"