diff options
Diffstat (limited to 'gdb/progspace.c')
-rw-r--r-- | gdb/progspace.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/gdb/progspace.c b/gdb/progspace.c index 28198c1..1c27165 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -1,6 +1,6 @@ /* Program and address space management, for GDB, the GNU debugger. - Copyright (C) 2009-2024 Free Software Foundation, Inc. + Copyright (C) 2009-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -21,7 +21,6 @@ #include "objfiles.h" #include "gdbcore.h" #include "solib.h" -#include "solist.h" #include "gdbthread.h" #include "inferior.h" #include <algorithm> @@ -124,6 +123,15 @@ program_space::~program_space () /* See progspace.h. */ +bool +program_space::multi_objfile_p () const +{ + return (!m_objfiles_list.empty () + && std::next (m_objfiles_list.begin ()) != m_objfiles_list.end ()); +} + +/* See progspace.h. */ + void program_space::free_all_objfiles () { @@ -131,8 +139,8 @@ program_space::free_all_objfiles () for (const solib &so : this->solibs ()) gdb_assert (so.objfile == NULL); - while (!objfiles_list.empty ()) - objfiles_list.front ()->unlink (); + while (!m_objfiles_list.empty ()) + this->remove_objfile (&m_objfiles_list.front ()); } /* See progspace.h. */ @@ -142,16 +150,12 @@ program_space::add_objfile (std::unique_ptr<objfile> &&objfile, struct objfile *before) { if (before == nullptr) - objfiles_list.push_back (std::move (objfile)); + m_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 ()); + m_objfiles_list.insert (m_objfiles_list.iterator_to (*before), + std::move (objfile)); } } @@ -166,16 +170,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 ()); + m_objfiles_list.erase (m_objfiles_list.iterator_to (*objfile)); } /* See progspace.h. */ @@ -202,12 +201,14 @@ program_space::exec_close () if (ebfd != nullptr) { /* Removing target sections may close the exec_ops target. - Clear ebfd before doing so to prevent recursion. */ - bfd *saved_ebfd = ebfd.get (); + Clear ebfd before doing so to prevent recursion. We + move it to another ref_ptr instead of saving it to a raw + pointer to avoid it looking like possible use-after-free. */ + gdb_bfd_ref_ptr saved_ebfd = std::move (ebfd); ebfd.reset (nullptr); ebfd_mtime = 0; - remove_target_sections (saved_ebfd); + remove_target_sections (saved_ebfd.get ()); m_exec_filename.reset (); } |