diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2024-07-11 12:07:00 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2024-11-11 11:28:24 -0500 |
commit | fa15972b68a6745eea5f7c1dfe8b6b0c3bd3bc45 (patch) | |
tree | 41a846effbe604a60fe3f5ab261f2b6fb3266d81 | |
parent | 427cc3b541e65b24b78bddb5c0672e871947132c (diff) | |
download | binutils-fa15972b68a6745eea5f7c1dfe8b6b0c3bd3bc45.zip binutils-fa15972b68a6745eea5f7c1dfe8b6b0c3bd3bc45.tar.gz binutils-fa15972b68a6745eea5f7c1dfe8b6b0c3bd3bc45.tar.bz2 |
gdb/progspace: link objfiles using owning_intrusive_list
This simplifies things a little bit, removing some `find_if` when
inserting or removing objfiles, and the whole
unwrapping_objfile_iterator thing.
Change-Id: Idd1851d36c7834820c9c1639a6a252de643eafba
-rw-r--r-- | gdb/objfiles.h | 2 | ||||
-rw-r--r-- | gdb/progspace.c | 32 | ||||
-rw-r--r-- | gdb/progspace.h | 71 | ||||
-rw-r--r-- | gdb/source.c | 1 |
4 files changed, 25 insertions, 81 deletions
diff --git a/gdb/objfiles.h b/gdb/objfiles.h index d92570a..bd65e2b 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<objfile> { private: diff --git a/gdb/progspace.c b/gdb/progspace.c index 28198c1..94175d3 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> &&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 999e7a3..4f98b45 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 <list> #include <vector> struct target_ops; @@ -41,8 +40,6 @@ struct address_space; struct program_space; struct solib; -typedef std::list<std::unique_ptr<objfile>> 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<objfile>, - 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<unwrapping_objfile_iterator>; - /* 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<intrusive_list<objfile>::iterator>; + using objfiles_range = iterator_range<objfiles_iterator>; /* 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<objfiles_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<std::unique_ptr<objfile>> objfiles_list; + owning_intrusive_list<objfile> 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 32099b9..3410e86 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -27,6 +27,7 @@ #include "value.h" #include "gdbsupport/filestuff.h" +#include <list> #include <sys/types.h> #include <fcntl.h> #include "gdbcore.h" |