public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 02/24] gdb: add program_space parameter to target_so_ops::clear_solib
Date: Tue, 10 Oct 2023 16:39:57 -0400	[thread overview]
Message-ID: <20231010204213.111285-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20231010204213.111285-1-simon.marchi@efficios.com>

The clear_solib is implicitly meant to clear the resources associated to
the current program space (that's what the solib implementations that
actually support multi-program-space / multi-inferior do).  Make that
explicit by adding a program_space parameter and pass down
current_program_space in call sites.  The implementation of the
clear_solib callbacks is fairly simple, I don't think any of them rely
on global state other than accessing current_program_space.

Change-Id: I8d0cc4db7b4f8db8d7452879c0c62db03269bf46
---
 gdb/solib-darwin.c | 20 +++++++++-----------
 gdb/solib-dsbt.c   | 32 +++++++++++++-------------------
 gdb/solib-frv.c    |  2 +-
 gdb/solib-svr4.c   |  6 ++----
 gdb/solib.c        |  4 ++--
 gdb/solist.h       |  7 ++++---
 6 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 98c81bb3bdaa..4796315c373a 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -78,16 +78,14 @@ static const registry<program_space>::key<darwin_info>
 /* Get the current darwin data.  If none is found yet, add it now.  This
    function always returns a valid object.  */
 
-static struct darwin_info *
-get_darwin_info (void)
+static darwin_info *
+get_darwin_info (program_space *pspace)
 {
-  struct darwin_info *info;
-
-  info = solib_darwin_pspace_data.get (current_program_space);
-  if (info != NULL)
+  darwin_info *info = solib_darwin_pspace_data.get (pspace);
+  if (info != nullptr)
     return info;
 
-  return solib_darwin_pspace_data.emplace (current_program_space);
+  return solib_darwin_pspace_data.emplace (pspace);
 }
 
 /* Return non-zero if the version in dyld_all_image is known.  */
@@ -225,7 +223,7 @@ darwin_current_sos (void)
   struct so_list *head = NULL;
   struct so_list *tail = NULL;
   int i;
-  struct darwin_info *info = get_darwin_info ();
+  darwin_info *info = get_darwin_info (current_program_space);
 
   /* Be sure image infos are loaded.  */
   darwin_load_image_infos (info);
@@ -506,7 +504,7 @@ darwin_solib_create_inferior_hook (int from_tty)
   if (!target_has_execution ())
     return;
 
-  struct darwin_info *info = get_darwin_info ();
+  darwin_info *info = get_darwin_info (current_program_space);
   CORE_ADDR load_addr;
 
   info->all_image_addr = 0;
@@ -601,9 +599,9 @@ darwin_solib_create_inferior_hook (int from_tty)
 }
 
 static void
-darwin_clear_solib (void)
+darwin_clear_solib (program_space *pspace)
 {
-  struct darwin_info *info = get_darwin_info ();
+  darwin_info *info = get_darwin_info (pspace);
 
   info->all_image_addr = 0;
   info->all_image.version = 0;
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index c29b2b81b113..16fa78a3d8b2 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -169,16 +169,14 @@ static const registry<program_space>::key<dsbt_info> solib_dsbt_pspace_data;
 /* Get the current dsbt data.  If none is found yet, add it now.  This
    function always returns a valid object.  */
 
-static struct dsbt_info *
-get_dsbt_info (void)
+static dsbt_info *
+get_dsbt_info (program_space *pspace)
 {
-  struct dsbt_info *info;
-
-  info = solib_dsbt_pspace_data.get (current_program_space);
-  if (info != NULL)
+  dsbt_info *info = solib_dsbt_pspace_data.get (pspace);
+  if (info != nullptr)
     return info;
 
-  return solib_dsbt_pspace_data.emplace (current_program_space);
+  return solib_dsbt_pspace_data.emplace (pspace);
 }
 
 
@@ -270,9 +268,6 @@ decode_loadmap (const gdb_byte *buf)
   return int_ldmbuf;
 }
 
-
-static struct dsbt_info *get_dsbt_info (void);
-
 /* Interrogate the Linux kernel to find out where the program was loaded.
    There are two load maps; one for the executable and one for the
    interpreter (only in the case of a dynamically linked executable).  */
@@ -280,7 +275,7 @@ static struct dsbt_info *get_dsbt_info (void);
 static void
 dsbt_get_initial_loadmaps (void)
 {
-  struct dsbt_info *info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (current_program_space);
   gdb::optional<gdb::byte_vector> buf
     = target_read_alloc (current_inferior ()->top_target (),
 			 TARGET_OBJECT_FDPIC, "exec");
@@ -442,7 +437,7 @@ lm_base (void)
   struct bound_minimal_symbol got_sym;
   CORE_ADDR addr;
   gdb_byte buf[TIC6X_PTR_SIZE];
-  struct dsbt_info *info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (current_program_space);
 
   /* One of our assumptions is that the main executable has been relocated.
      Bail out if this has not happened.  (Note that post_create_inferior
@@ -524,7 +519,7 @@ dsbt_current_sos (void)
   CORE_ADDR lm_addr;
   struct so_list *sos_head = NULL;
   struct so_list **sos_next_ptr = &sos_head;
-  struct dsbt_info *info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (current_program_space);
 
   /* Make sure that the main executable has been relocated.  This is
      required in order to find the address of the global offset table,
@@ -645,7 +640,7 @@ dsbt_current_sos (void)
 static int
 dsbt_in_dynsym_resolve_code (CORE_ADDR pc)
 {
-  struct dsbt_info *info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (current_program_space);
 
   return ((pc >= info->interp_text_sect_low && pc < info->interp_text_sect_high)
 	  || (pc >= info->interp_plt_sect_low && pc < info->interp_plt_sect_high)
@@ -675,7 +670,6 @@ static int
 enable_break (void)
 {
   asection *interp_sect;
-  struct dsbt_info *info;
 
   if (current_program_space->exec_bfd () == NULL)
     return 0;
@@ -683,7 +677,7 @@ enable_break (void)
   if (!target_has_execution ())
     return 0;
 
-  info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (current_program_space);
 
   info->interp_text_sect_low = 0;
   info->interp_text_sect_high = 0;
@@ -803,7 +797,7 @@ dsbt_relocate_main_executable (void)
 {
   struct int_elf32_dsbt_loadmap *ldm;
   int changed;
-  struct dsbt_info *info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (current_program_space);
 
   dsbt_get_initial_loadmaps ();
   ldm = info->exec_loadmap;
@@ -875,9 +869,9 @@ dsbt_solib_create_inferior_hook (int from_tty)
 }
 
 static void
-dsbt_clear_solib (void)
+dsbt_clear_solib (program_space *pspace)
 {
-  struct dsbt_info *info = get_dsbt_info ();
+  dsbt_info *info = get_dsbt_info (pspace);
 
   info->lm_base_cache = 0;
   info->main_lm_addr = 0;
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index d4e84a1b528d..c61ed7910ee2 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -806,7 +806,7 @@ frv_solib_create_inferior_hook (int from_tty)
 }
 
 static void
-frv_clear_solib (void)
+frv_clear_solib (program_space *pspace)
 {
   lm_base_cache = 0;
   enable_break2_done = 0;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 7bc6ca45c373..1f8b8b34c00a 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3178,11 +3178,9 @@ svr4_solib_create_inferior_hook (int from_tty)
 }
 
 static void
-svr4_clear_solib (void)
+svr4_clear_solib (program_space *pspace)
 {
-  struct svr4_info *info;
-
-  info = get_svr4_info (current_program_space);
+  svr4_info *info = get_svr4_info (pspace);
   info->debug_base = 0;
   info->debug_loader_offset_p = 0;
   info->debug_loader_offset = 0;
diff --git a/gdb/solib.c b/gdb/solib.c
index e8211814283a..54a4c3942b0c 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1241,7 +1241,7 @@ clear_solib (void)
     }
 
   if (ops->clear_solib != nullptr)
-    ops->clear_solib ();
+    ops->clear_solib (current_program_space);
 }
 
 /* Shared library startup support.  When GDB starts up the inferior,
@@ -1411,7 +1411,7 @@ reload_shared_libraries (const char *ignored, int from_tty,
       /* Reset or free private data structures not associated with
 	 so_list entries.  */
       if (ops->clear_solib != nullptr)
-	ops->clear_solib ();
+	ops->clear_solib (current_program_space);
 
       /* Remove any previous solib event breakpoint.  This is usually
 	 done in common code, at breakpoint_init_inferior time, but
diff --git a/gdb/solist.h b/gdb/solist.h
index 0f764b264f74..b3a06b88c439 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -96,9 +96,10 @@ struct target_so_ops
      It is also called before free_so when SO is about to be freed.  */
   void (*clear_so) (struct so_list *so);
 
-  /* Reset or free private data structures not associated with
-     so_list entries.  */
-  void (*clear_solib) (void);
+  /* Free private data structures associated to PSPACE.  This method
+     should not free resources associated to individual so_list entries,
+     those are cleared by the clear_so method.  */
+  void (*clear_solib) (program_space *pspace);
 
   /* Target dependent code to run after child process fork.  */
   void (*solib_create_inferior_hook) (int from_tty);
-- 
2.42.0


  parent reply	other threads:[~2023-10-10 20:42 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 20:39 [PATCH 00/24] C++ification of struct so_list Simon Marchi
2023-10-10 20:39 ` [PATCH 01/24] gdb: remove empty clear_solib functions Simon Marchi
2023-10-10 20:39 ` Simon Marchi [this message]
2023-10-17 14:57   ` [PATCH 02/24] gdb: add program_space parameter to target_so_ops::clear_solib Pedro Alves
2023-10-17 15:19     ` Simon Marchi
2023-10-10 20:39 ` [PATCH 03/24] gdb: make interps_notify work with references Simon Marchi
2023-10-11  8:48   ` Lancelot SIX
2023-10-11 14:18     ` Simon Marchi
2023-10-10 20:39 ` [PATCH 04/24] gdb: replace some so_list parameters to use references Simon Marchi
2023-10-19 11:07   ` [PATCH 4/24] " Lancelot SIX
2023-10-19 14:49     ` Simon Marchi
2023-10-19 15:20       ` Lancelot SIX
2023-10-19 16:07         ` Simon Marchi
2023-10-10 20:40 ` [PATCH 05/24] gdbsupport: use "reference" and "pointer" type aliases in intrusive_list Simon Marchi
2023-10-10 20:40 ` [PATCH 06/24] gdbsupport: make intrusive_list's disposer accept a reference Simon Marchi
2023-10-12 19:05   ` Pedro Alves
2023-10-14 20:12     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 07/24] gdb: make get_cbfd_soname_build_id static Simon Marchi
2023-10-10 20:40 ` [PATCH 08/24] gdb: allocate so_list with new, deallocate with delete Simon Marchi
2023-10-10 20:40 ` [PATCH 09/24] gdb: rename lm_info_base to lm_info Simon Marchi
2023-10-10 20:40 ` [PATCH 10/24] gdb: remove target_so_ops::free_so Simon Marchi
2023-10-10 20:40 ` [PATCH 11/24] gdb: use gdb::checked_static_cast when casting lm_info Simon Marchi
2023-10-10 20:40 ` [PATCH 12/24] gdb: make solib-svr4 not use so_list internally Simon Marchi
2023-10-13 17:52   ` Lancelot SIX
2023-10-14 19:59     ` Simon Marchi
2023-10-19 11:08   ` Lancelot SIX
2023-10-19 14:50     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 13/24] gdb: make solib-rocm " Simon Marchi
2023-10-13 18:35   ` Lancelot SIX
2023-10-14 20:00     ` Simon Marchi
2023-10-17 15:23   ` Pedro Alves
2023-10-17 15:32     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 14/24] gdb: remove lm_info_vector typedef Simon Marchi
2023-10-10 20:40 ` [PATCH 15/24] gdb: make so_list::lm_info a unique_ptr Simon Marchi
2023-10-10 20:40 ` [PATCH 16/24] gdb: make clear_so a method of struct so_list Simon Marchi
2023-10-19 11:08   ` Lancelot SIX
2023-10-19 14:52     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 17/24] gdb: remove target_section_table typedef Simon Marchi
2023-10-10 20:40 ` [PATCH 18/24] gdb: make so_list::sections not a pointer Simon Marchi
2023-10-10 20:40 ` [PATCH 19/24] gdb: make so_list::abfd a gdb_bfd_ref_ptr Simon Marchi
2023-10-10 20:40 ` [PATCH 20/24] gdb: make so_list::{so_original_name,so_name} std::strings Simon Marchi
2023-10-13 22:28   ` [PATCH 20/24] gdb: make so_list::{so_original_name, so_name} std::strings Lancelot SIX
2023-10-14 20:01     ` Simon Marchi
2023-10-19 11:08   ` [PATCH 20/24] gdb: make so_list::{so_original_name,so_name} std::strings Lancelot SIX
2023-10-19 14:55     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 21/24] gdb: link so_list using intrusive_list Simon Marchi
2023-10-17 19:14   ` Pedro Alves
2023-10-17 19:38     ` Simon Marchi
2023-10-10 20:40 ` [PATCH 22/24] gdb: don't call so_list::clear in free_so Simon Marchi
2023-10-10 20:40 ` [PATCH 23/24] gdb: remove free_so function Simon Marchi
2023-10-10 20:49 ` [PATCH 24/24] gdb: rename struct so_list to so Simon Marchi
2023-10-17 19:20 ` [PATCH 00/24] C++ification of struct so_list Pedro Alves
2023-10-17 19:53   ` Simon Marchi
2023-10-20 14:40     ` Pedro Alves
2023-10-19 11:09 ` [PATCH 0/24] " Lancelot SIX
2023-10-19 14:57   ` 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=20231010204213.111285-3-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).