Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>, Lancelot SIX <Lancelot.Six@amd.com>,
	Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH v3 05/10] gdb/solib: add remove_solib function
Date: Wed,  8 Jul 2026 17:51:37 -0400	[thread overview]
Message-ID: <20260708215145.93134-6-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260708215145.93134-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@polymtl.ca>

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 <tom@tromey.com>
---
 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


  parent reply	other threads:[~2026-07-08 22:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 21:51 [PATCH v3 00/10] Multiple solib_ops in a program_space simon.marchi
2026-07-08 21:51 ` [PATCH v3 01/10] gdb/solib-rocm: assert that host ops isn't rocm_solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 02/10] gdb/solib-rocm: pass reference to cache to rocm_code_object_stream_file simon.marchi
2026-07-08 21:51 ` [PATCH v3 03/10] gdb/solib-rocm: add cached_target_fd to manage cached fd lifetime simon.marchi
2026-07-08 21:51 ` [PATCH v3 04/10] gdb: de-constify some methods of solib_ops simon.marchi
2026-07-08 21:51 ` simon.marchi [this message]
2026-07-08 21:51 ` [PATCH v3 06/10] gdb/solib-rocm: move per-inferior data to rocm_solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 07/10] gdb/solib-rocm: save inferior in rocm_solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 08/10] gdb: add objfile -> solib backlink simon.marchi
2026-07-21 17:31   ` Tom Tromey
2026-07-08 21:51 ` [PATCH v3 09/10] gdb: change default objfile iteration order to start with current objfile simon.marchi
2026-07-08 21:51 ` [PATCH v3 10/10] gdb: multiple solib_ops per program space simon.marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260708215145.93134-6-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=Lancelot.Six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox