[03/14] gdb: split no_shared_libraries, command vs implementation

Message ID 20240711195307.1544451-4-simon.marchi@polymtl.ca
State New
Headers
Series Some random program space cleanups |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Simon Marchi July 11, 2024, 7:51 p.m. UTC
  The `no_shared_libraries` function is currently used to implement the
`nosharedlibrary` command, but it also used internally by other
functions.  This does not make a very good internal API.

Add the `no_shared_libraries_command` function to implement the CLI
command.  Remove the unused parameters from `no_shared_libraries`.

Remove the `from_tty` parameter of `target_pre_inferior`, since it's now
unused.

Change-Id: I4fcba5ee1e0f7d250aab1a7b62b9ea16265fe962
---
 gdb/infcmd.c    |  8 ++++----
 gdb/infrun.c    |  2 +-
 gdb/progspace.c |  2 +-
 gdb/remote.c    |  2 +-
 gdb/solib.c     | 20 ++++++++++++++------
 gdb/solib.h     |  2 +-
 gdb/symfile.c   |  2 +-
 gdb/target.c    |  6 +++---
 gdb/target.h    |  2 +-
 9 files changed, 27 insertions(+), 19 deletions(-)
  

Patch

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 71514d5ba66e..5738bf05bf6b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -383,7 +383,7 @@  run_command_1 (const char *args, int from_tty, enum run_how run_how)
 
   /* Clean up any leftovers from other runs.  Some other things from
      this function should probably be moved into target_pre_inferior.  */
-  target_pre_inferior (from_tty);
+  target_pre_inferior ();
 
   /* The comment here used to read, "The exec file is re-read every
      time we do a generic_mourn_inferior, so we just have to worry
@@ -2628,7 +2628,7 @@  attach_command (const char *args, int from_tty)
 
   /* Clean up any leftovers from other runs.  Some other things from
      this function should probably be moved into target_pre_inferior.  */
-  target_pre_inferior (from_tty);
+  target_pre_inferior ();
 
   gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
   args = stripped.get ();
@@ -2827,7 +2827,7 @@  detach_command (const char *args, int from_tty)
   /* If the solist is global across inferiors, don't clear it when we
      detach from a single inferior.  */
   if (!gdbarch_has_global_solist (inf->arch ()))
-    no_shared_libraries (nullptr, from_tty);
+    no_shared_libraries ();
 
   if (deprecated_detach_hook)
     deprecated_detach_hook ();
@@ -2853,7 +2853,7 @@  disconnect_command (const char *args, int from_tty)
   query_if_trace_running (from_tty);
   disconnect_tracing ();
   target_disconnect (args, from_tty);
-  no_shared_libraries (nullptr, from_tty);
+  no_shared_libraries ();
   init_thread_list ();
   update_previous_thread ();
   if (deprecated_detach_hook)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 1f32a63ad541..b2dfd0c96b15 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1317,7 +1317,7 @@  follow_exec (ptid_t ptid, const char *exec_file_target)
   /* Also, loading a symbol file below may trigger symbol lookups, and
      we don't want those to be satisfied by the libraries of the
      previous incarnation of this process.  */
-  no_shared_libraries (nullptr, 0);
+  no_shared_libraries ();
 
   inferior *execing_inferior = current_inferior ();
   inferior *following_inferior;
diff --git a/gdb/progspace.c b/gdb/progspace.c
index d5b5ef20023b..580ebfbb6d1a 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -115,7 +115,7 @@  program_space::~program_space ()
   set_current_program_space (this);
 
   breakpoint_program_space_exit (this);
-  no_shared_libraries (NULL, 0);
+  no_shared_libraries ();
   free_all_objfiles ();
   /* Defer breakpoint re-set because we don't want to create new
      locations for this pspace which we're tearing down.  */
diff --git a/gdb/remote.c b/gdb/remote.c
index 90a4bd57a828..bff61ac8c52c 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -6271,7 +6271,7 @@  remote_target::open_1 (const char *name, int from_tty, int extended_p)
     }
 
   /* First delete any symbols previously loaded from shared libraries.  */
-  no_shared_libraries (NULL, 0);
+  no_shared_libraries ();
 
   /* Start the remote connection.  If error() or QUIT, discard this
      target (we'd otherwise be in an inconsistent state) and then
diff --git a/gdb/solib.c b/gdb/solib.c
index 8cfcc2f4024c..75eb9ecfd299 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1234,13 +1234,10 @@  sharedlibrary_command (const char *args, int from_tty)
   solib_add (args, from_tty, 1);
 }
 
-/* Implements the command "nosharedlibrary", which discards symbols
-   that have been auto-loaded from shared libraries.  Symbols from
-   shared libraries that were added by explicit request of the user
-   are not discarded.  Also called from remote.c.  */
+/* See solib.h.  */
 
 void
-no_shared_libraries (const char *ignored, int from_tty)
+no_shared_libraries ()
 {
   /* The order of the two routines below is important: clear_solib notifies
      the solib_unloaded observers, and some of these observers might need
@@ -1251,6 +1248,17 @@  no_shared_libraries (const char *ignored, int from_tty)
   objfile_purge_solibs (current_program_space);
 }
 
+/* Implements the command "nosharedlibrary", which discards symbols
+   that have been auto-loaded from shared libraries.  Symbols from
+   shared libraries that were added by explicit request of the user
+   are not discarded.  */
+
+static void
+no_shared_libraries_command (const char *ignored, int from_tty)
+{
+  no_shared_libraries ();
+}
+
 /* See solib.h.  */
 
 void
@@ -1725,7 +1733,7 @@  _initialize_solib ()
     = add_info ("sharedlibrary", info_sharedlibrary_command,
 		_ ("Status of loaded shared object libraries."));
   add_info_alias ("dll", info_sharedlibrary_cmd, 1);
-  add_com ("nosharedlibrary", class_files, no_shared_libraries,
+  add_com ("nosharedlibrary", class_files, no_shared_libraries_command,
 	   _ ("Unload all shared object library symbols."));
 
   add_setshow_boolean_cmd ("auto-solib-add", class_support, &auto_solib_add,
diff --git a/gdb/solib.h b/gdb/solib.h
index f7a93c0718f0..6b275c580fa4 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -82,7 +82,7 @@  extern bool in_solib_dynsym_resolve_code (CORE_ADDR);
 
 /* Discard symbols that were auto-loaded from shared libraries.  */
 
-extern void no_shared_libraries (const char *ignored, int from_tty);
+extern void no_shared_libraries ();
 
 /* Synchronize GDB's shared object list with inferior's.
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index b0510b4b4090..688dd74c32c0 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1209,7 +1209,7 @@  symbol_file_clear (int from_tty)
 
   /* solib descriptors may have handles to objfiles.  Wipe them before their
      objfiles get stale by free_all_objfiles.  */
-  no_shared_libraries (NULL, from_tty);
+  no_shared_libraries ();
 
   current_program_space->free_all_objfiles ();
 
diff --git a/gdb/target.c b/gdb/target.c
index 1b5aa11ed6f5..0ca708729a7a 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2428,7 +2428,7 @@  info_target_command (const char *args, int from_tty)
    resets (things which might change between targets).  */
 
 void
-target_pre_inferior (int from_tty)
+target_pre_inferior ()
 {
   /* Clear out solib state.  Otherwise the solib state of the previous
      inferior might have survived and is entirely wrong for the new
@@ -2452,7 +2452,7 @@  target_pre_inferior (int from_tty)
      memory regions and features.  */
   if (!gdbarch_has_global_solist (current_inferior ()->arch ()))
     {
-      no_shared_libraries (NULL, from_tty);
+      no_shared_libraries ();
 
       invalidate_target_mem_regions ();
 
@@ -2504,7 +2504,7 @@  target_preopen (int from_tty)
      live process to a core of the same program.  */
   current_inferior ()->pop_all_targets_above (file_stratum);
 
-  target_pre_inferior (from_tty);
+  target_pre_inferior ();
 }
 
 /* See target.h.  */
diff --git a/gdb/target.h b/gdb/target.h
index 81de4a678c3f..d0af584a2bb0 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2427,7 +2427,7 @@  struct target_unpusher
 
 typedef std::unique_ptr<struct target_ops, target_unpusher> target_unpush_up;
 
-extern void target_pre_inferior (int);
+extern void target_pre_inferior ();
 
 extern void target_preopen (int);