[PATCH v4 05/10] gdb/solib: add remove_solib function

Simon Marchi <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
From: Simon Marchi <[email protected]>

Factor out the code to remove an solib into a new remove_solib function.
This function is used by patches later in this series.

This patch only moves code, so no behavior change expected.

Change-Id: I6bb901c954cdcf900a3f09a4c4d1ba44203f1ed0
Approved-By: Tom Tromey <[email protected]>
---
 gdb/solib.c | 53 +++++++++++++++++++++++++++++------------------------
 gdb/solib.h | 10 ++++++++++
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/gdb/solib.c b/gdb/solib.c
index 561a1448cfe6..6afa97e1aed5 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -703,6 +703,34 @@ notify_solib_unloaded (program_space *pspace, const solib &so,
 
 /* See solib.h.  */
 
+owning_intrusive_list<solib>::iterator
+remove_solib (program_space *pspace,
+	      owning_intrusive_list<solib>::iterator solib_it)
+{
+  bool still_in_use
+    = solib_it->objfile != nullptr && solib_used (pspace, *solib_it);
+
+  /* Notify any observer that the shared object has been unloaded before we
+     remove it from GDB's tables.  */
+  notify_solib_unloaded (pspace, *solib_it, still_in_use, false);
+
+  /* Unless the user loaded it explicitly, free SO's objfile.  */
+  if (solib_it->objfile != nullptr
+      && !(solib_it->objfile->flags & OBJF_USERLOADED)
+      && !still_in_use)
+    solib_it->objfile->unlink ();
+
+  pspace->deleted_solibs.push_back (solib_it->name);
+
+  /* Some targets' section tables might be referring to
+     sections from so.abfd; remove them.  */
+  pspace->remove_target_sections (&*solib_it);
+
+  return pspace->solibs ().erase (solib_it);
+}
+
+/* See solib.h.  */
+
 void
 update_solib_list (int from_tty)
 {
@@ -784,30 +812,7 @@ update_solib_list (int from_tty)
 
       /* If it's not on the inferior's list, remove it from GDB's tables.  */
       else
-	{
-	  bool still_in_use
-	    = (gdb_iter->objfile != nullptr
-	       && solib_used (current_program_space, *gdb_iter));
-
-	  /* Notify any observer that the shared object has been
-	     unloaded before we remove it from GDB's tables.  */
-	  notify_solib_unloaded (current_program_space, *gdb_iter,
-				 still_in_use, false);
-
-	  /* Unless the user loaded it explicitly, free SO's objfile.  */
-	  if (gdb_iter->objfile != nullptr
-	      && !(gdb_iter->objfile->flags & OBJF_USERLOADED)
-	      && !still_in_use)
-	    gdb_iter->objfile->unlink ();
-
-	  current_program_space->deleted_solibs.push_back (gdb_iter->name);
-
-	  /* Some targets' section tables might be referring to
-	     sections from so.abfd; remove them.  */
-	  current_program_space->remove_target_sections (&*gdb_iter);
-
-	  gdb_iter = current_program_space->solibs ().erase (gdb_iter);
-	}
+	gdb_iter = remove_solib (current_program_space, gdb_iter);
     }
 
   /* Now the inferior's list contains only shared objects that don't
diff --git a/gdb/solib.h b/gdb/solib.h
index b2523906596a..903b9d7b2a86 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -350,6 +350,16 @@ extern bool in_solib_dynsym_resolve_code (CORE_ADDR);
 
 extern void no_shared_libraries (program_space *pspace);
 
+/* Remove solib *SOLIB_IT from PSPACE.
+
+   Remove the corresponding objfiles and target sections.
+
+   Return an iterator to the next solib in PSPACE's solib list, helping to
+   continue iterating.  */
+
+extern owning_intrusive_list<solib>::iterator remove_solib
+  (program_space *pspace, owning_intrusive_list<solib>::iterator solib_it);
+
 /* Synchronize GDB's shared object list with inferior's.
 
    Extract the list of currently loaded shared objects from the
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.