]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove ALL_SO_LIBS and so_list_head
authorTom Tromey <tom@tromey.com>
Fri, 8 May 2020 20:21:22 +0000 (14:21 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 8 May 2020 20:21:22 +0000 (14:21 -0600)
This patch started as an attempt to replace ALL_SO_LIBS with an
ordinary C++ iterator.  However, then I tripped over the so_list_head
define again, and decided to remove it as well.

gdb/ChangeLog
2020-05-08  Tom Tromey  <tom@tromey.com>

* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Update.
* solib-svr4.c (svr4_fetch_objfile_link_map): Update.
(enable_break): Update.
* solib-frv.c (frv_fdpic_find_global_pointer): Update.
(frv_fdpic_find_canonical_descriptor): Update.
(frv_fetch_objfile_link_map): Update.
* progspace.c (program_space::free_all_objfiles): Update.
(program_space::solibs): New method.
* progspace.h (struct program_space) <solibs>: New method.
* solist.h (master_so_list): Don't declare.
(ALL_SO_LIBS): Remove.
* solib.h (so_list_head): Remove.
(update_solib_list): Update comment.
* solib.c (master_so_list): Remove.
(solib_used, update_solib_list, solib_add)
(info_sharedlibrary_command, clear_solib)
(reload_shared_libraries_1, remove_user_added_objfile): Update.

gdb/ChangeLog
gdb/mi/mi-cmd-file.c
gdb/progspace.c
gdb/progspace.h
gdb/solib-frv.c
gdb/solib-svr4.c
gdb/solib.c
gdb/solib.h
gdb/solist.h

index be55c41d67f920dc519e6f1fc68b3049cb525dd0..3badfbd2d89226ad305d19eb992f0220588d9781 100644 (file)
@@ -1,3 +1,23 @@
+2020-05-08  Tom Tromey  <tom@tromey.com>
+
+       * mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Update.
+       * solib-svr4.c (svr4_fetch_objfile_link_map): Update.
+       (enable_break): Update.
+       * solib-frv.c (frv_fdpic_find_global_pointer): Update.
+       (frv_fdpic_find_canonical_descriptor): Update.
+       (frv_fetch_objfile_link_map): Update.
+       * progspace.c (program_space::free_all_objfiles): Update.
+       (program_space::solibs): New method.
+       * progspace.h (struct program_space) <solibs>: New method.
+       * solist.h (master_so_list): Don't declare.
+       (ALL_SO_LIBS): Remove.
+       * solib.h (so_list_head): Remove.
+       (update_solib_list): Update comment.
+       * solib.c (master_so_list): Remove.
+       (solib_used, update_solib_list, solib_add)
+       (info_sharedlibrary_command, clear_solib)
+       (reload_shared_libraries_1, remove_user_added_objfile): Update.
+
 2020-05-08  Tom Tromey  <tom@tromey.com>
 
        * extension.c (extension_languages): Now a std::array.
index b5835a52bf88a1f05df6d64e482e94f53fd6812f..3b0261c6c9fc028657765e48dcd9d0352b31ef07 100644 (file)
@@ -121,7 +121,6 @@ mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   const char *pattern;
-  struct so_list *so = NULL;
 
   switch (argc)
     {
@@ -148,7 +147,7 @@ mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc)
   /* Print the table header.  */
   ui_out_emit_list list_emitter (uiout, "shared-libraries");
 
-  ALL_SO_LIBS (so)
+  for (struct so_list *so : current_program_space->solibs ())
     {
       if (so->so_name[0] == '\0')
        continue;
index 6419f01770448a238183b328d4b8f0f3aa5510ab..252b62e02d751ecc25926a1a8311770f5ca940c4 100644 (file)
@@ -192,10 +192,8 @@ program_space::~program_space ()
 void
 program_space::free_all_objfiles ()
 {
-  struct so_list *so;
-
   /* Any objfile reference would become stale.  */
-  for (so = master_so_list (); so; so = so->next)
+  for (struct so_list *so : current_program_space->solibs ())
     gdb_assert (so->objfile == NULL);
 
   while (!objfiles_list.empty ())
@@ -239,6 +237,14 @@ program_space::remove_objfile (struct objfile *objfile)
     symfile_object_file = NULL;
 }
 
+/* See progspace.h.  */
+
+next_adapter<struct so_list>
+program_space::solibs () const
+{
+  return next_adapter<struct so_list> (this->so_list);
+}
+
 /* Copies program space SRC to DEST.  Copies the main executable file,
    and the main symbol file.  Returns DEST.  */
 
index 2b887847e17ac4236c4404c922c858825b5e5277..0e32224f02d1da9cdba475e3ba8eab1765898bf3 100644 (file)
@@ -37,6 +37,7 @@ struct exec;
 struct address_space;
 struct program_space_data;
 struct address_space_data;
+struct so_list;
 
 typedef std::list<std::shared_ptr<objfile>> objfile_list;
 
@@ -264,6 +265,12 @@ struct program_space
   /* Free all the objfiles associated with this program space.  */
   void free_all_objfiles ();
 
+  /* Return a range adapter for iterating over all the solibs in this
+     program space.  Use it like:
+
+     for (so_list *so : pspace->solibs ()) { ... }  */
+  next_adapter<struct so_list> solibs () const;
+
 
   /* Pointer to next in linked list.  */
   struct program_space *next = NULL;
index 582f2d5ede60e4a4d05bdef17db96af69081539e..62e7b05b4907e6356f3a66b7407581b9156ab205 100644 (file)
@@ -908,10 +908,7 @@ main_got (void)
 CORE_ADDR
 frv_fdpic_find_global_pointer (CORE_ADDR addr)
 {
-  struct so_list *so;
-
-  so = master_so_list ();
-  while (so)
+  for (struct so_list *so : current_program_space->solibs ())
     {
       int seg;
       lm_info_frv *li = (lm_info_frv *) so->lm_info;
@@ -923,8 +920,6 @@ frv_fdpic_find_global_pointer (CORE_ADDR addr)
              && addr < map->segs[seg].addr + map->segs[seg].p_memsz)
            return li->got_value;
        }
-
-      so = so->next;
     }
 
   /* Didn't find it in any of the shared objects.  So assume it's in the
@@ -969,10 +964,7 @@ frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point)
      in list of shared objects.  */
   if (addr == 0)
     {
-      struct so_list *so;
-
-      so = master_so_list ();
-      while (so)
+      for (struct so_list *so : current_program_space->solibs ())
        {
          lm_info_frv *li = (lm_info_frv *) so->lm_info;
 
@@ -981,8 +973,6 @@ frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point)
 
          if (addr != 0)
            break;
-
-         so = so->next;
        }
     }
 
@@ -1116,8 +1106,6 @@ find_canonical_descriptor_in_load_object
 CORE_ADDR
 frv_fetch_objfile_link_map (struct objfile *objfile)
 {
-  struct so_list *so;
-
   /* Cause frv_current_sos() to be run if it hasn't been already.  */
   if (main_lm_addr == 0)
     solib_add (0, 0, 1);
@@ -1128,7 +1116,7 @@ frv_fetch_objfile_link_map (struct objfile *objfile)
 
   /* The other link map addresses may be found by examining the list
      of shared libraries.  */
-  for (so = master_so_list (); so; so = so->next)
+  for (struct so_list *so : current_program_space->solibs ())
     {
       lm_info_frv *li = (lm_info_frv *) so->lm_info;
 
index 38c832f8f5a141acbcd724d60008e3c71d71e747..19d1105ae95f78c5e4b429670165e7eca2712e65 100644 (file)
@@ -1537,7 +1537,6 @@ svr4_current_sos (void)
 CORE_ADDR
 svr4_fetch_objfile_link_map (struct objfile *objfile)
 {
-  struct so_list *so;
   struct svr4_info *info = get_svr4_info (objfile->pspace);
 
   /* Cause svr4_current_sos() to be run if it hasn't been already.  */
@@ -1555,7 +1554,7 @@ svr4_fetch_objfile_link_map (struct objfile *objfile)
 
   /* The other link map addresses may be found by examining the list
      of shared libraries.  */
-  for (so = master_so_list (); so; so = so->next)
+  for (struct so_list *so : current_program_space->solibs ())
     if (so->objfile == objfile)
       {
        lm_info_svr4 *li = (lm_info_svr4 *) so->lm_info;
@@ -2307,7 +2306,6 @@ enable_break (struct svr4_info *info, int from_tty)
       CORE_ADDR load_addr = 0;
       int load_addr_found = 0;
       int loader_found_in_list = 0;
-      struct so_list *so;
       struct target_ops *tmp_bfd_target;
 
       sym_addr = 0;
@@ -2340,8 +2338,7 @@ enable_break (struct svr4_info *info, int from_tty)
 
       /* On a running target, we can get the dynamic linker's base
          address from the shared library table.  */
-      so = master_so_list ();
-      while (so)
+      for (struct so_list *so : current_program_space->solibs ())
        {
          if (svr4_same_1 (interp_name, so->so_original_name))
            {
@@ -2350,7 +2347,6 @@ enable_break (struct svr4_info *info, int from_tty)
              load_addr = lm_addr_check (so, tmp_bfd.get ());
              break;
            }
-         so = so->next;
        }
 
       /* If we were not able to find the base address of the loader
index ba388d77e8d00c1def086f9b59ae33d6d9821a0a..cd410bb9e3e0998dd7a0a02665fa085693f2f0a8 100644 (file)
@@ -647,13 +647,6 @@ free_so (struct so_list *so)
 }
 
 
-/* Return address of first so_list entry in master shared object list.  */
-struct so_list *
-master_so_list (void)
-{
-  return so_list_head;
-}
-
 /* Read in symbols for shared object SO.  If SYMFILE_VERBOSE is set in FLAGS,
    be chatty about it.  Return true if any symbols were actually loaded.  */
 
@@ -713,15 +706,13 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
   return false;
 }
 
-/* Return true if KNOWN->objfile is used by any other so_list object in the
-   SO_LIST_HEAD list.  Return false otherwise.  */
+/* Return true if KNOWN->objfile is used by any other so_list object
+   in the list of shared libraries.  Return false otherwise.  */
 
 static bool
 solib_used (const struct so_list *const known)
 {
-  const struct so_list *pivot;
-
-  for (pivot = so_list_head; pivot != NULL; pivot = pivot->next)
+  for (const struct so_list *pivot : current_program_space->solibs ())
     if (pivot != known && pivot->objfile == known->objfile)
       return true;
   return false;
@@ -784,8 +775,8 @@ update_solib_list (int from_tty)
      the time we're done walking GDB's list, the inferior's list
      contains only the new shared objects, which we then add.  */
 
-  gdb = so_list_head;
-  gdb_link = &so_list_head;
+  gdb = current_program_space->so_list;
+  gdb_link = &current_program_space->so_list;
   while (gdb)
     {
       struct so_list *i = inferior;
@@ -943,8 +934,6 @@ libpthread_solib_p (struct so_list *so)
 void
 solib_add (const char *pattern, int from_tty, int readsyms)
 {
-  struct so_list *gdb;
-
   if (print_symbol_loading_p (from_tty, 0, 0))
     {
       if (pattern != NULL)
@@ -979,7 +968,7 @@ solib_add (const char *pattern, int from_tty, int readsyms)
     if (from_tty)
         add_flags |= SYMFILE_VERBOSE;
 
-    for (gdb = so_list_head; gdb; gdb = gdb->next)
+    for (struct so_list *gdb : current_program_space->solibs ())
       if (! pattern || re_exec (gdb->so_name))
        {
           /* Normally, we would read the symbols from that library
@@ -1030,7 +1019,6 @@ solib_add (const char *pattern, int from_tty, int readsyms)
 static void
 info_sharedlibrary_command (const char *pattern, int from_tty)
 {
-  struct so_list *so = NULL;   /* link map state variable */
   bool so_missing_debug_info = false;
   int addr_width;
   int nr_libs;
@@ -1053,7 +1041,8 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
   /* ui_out_emit_table table_emitter needs to know the number of rows,
      so we need to make two passes over the libs.  */
 
-  for (nr_libs = 0, so = so_list_head; so; so = so->next)
+  nr_libs = 0;
+  for (struct so_list *so : current_program_space->solibs ())
     {
       if (so->so_name[0])
        {
@@ -1074,7 +1063,7 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
 
     uiout->table_body ();
 
-    ALL_SO_LIBS (so)
+    for (struct so_list *so : current_program_space->solibs ())
       {
        if (! so->so_name[0])
          continue;
@@ -1185,11 +1174,11 @@ clear_solib (void)
 
   disable_breakpoints_in_shlibs ();
 
-  while (so_list_head)
+  while (current_program_space->so_list)
     {
-      struct so_list *so = so_list_head;
+      struct so_list *so = current_program_space->so_list;
 
-      so_list_head = so->next;
+      current_program_space->so_list = so->next;
       gdb::observers::solib_unloaded.notify (so);
       remove_target_sections (so);
       free_so (so);
@@ -1284,12 +1273,10 @@ handle_solib_event (void)
 static void
 reload_shared_libraries_1 (int from_tty)
 {
-  struct so_list *so;
-
   if (print_symbol_loading_p (from_tty, 0, 0))
     printf_unfiltered (_("Loading symbols for shared libraries.\n"));
 
-  for (so = so_list_head; so != NULL; so = so->next)
+  for (struct so_list *so : current_program_space->solibs ())
     {
       const char *found_pathname = NULL;
       bool was_loaded = so->symbols_loaded != 0;
@@ -1552,18 +1539,17 @@ gdb_bfd_lookup_symbol (bfd *abfd,
   return symaddr;
 }
 
-/* SO_LIST_HEAD may contain user-loaded object files that can be removed
-   out-of-band by the user.  So upon notification of free_objfile remove
-   all references to any user-loaded file that is about to be freed.  */
+/* The shared library list may contain user-loaded object files that
+   can be removed out-of-band by the user.  So upon notification of
+   free_objfile remove all references to any user-loaded file that is
+   about to be freed.  */
 
 static void
 remove_user_added_objfile (struct objfile *objfile)
 {
-  struct so_list *so;
-
   if (objfile != 0 && objfile->flags & OBJF_USERLOADED)
     {
-      for (so = so_list_head; so != NULL; so = so->next)
+      for (struct so_list *so : current_program_space->solibs ())
        if (so->objfile == objfile)
          so->objfile = NULL;
     }
index 2628ca0c2b799c3904a931fa9f06e1cf3f5653d1..801965fcd53c0389ae6885c306a758d71b115769 100644 (file)
@@ -28,9 +28,6 @@ struct program_space;
 
 #include "symfile-add-flags.h"
 
-/* List of known shared objects */
-#define so_list_head current_program_space->so_list
-
 /* Called when we free all symtabs, to free the shared library information
    as well.  */
 
@@ -81,9 +78,9 @@ extern void set_solib_ops (struct gdbarch *gdbarch,
 /* Synchronize GDB's shared object list with inferior's.
 
    Extract the list of currently loaded shared objects from the
-   inferior, and compare it with the list of shared objects currently
-   in GDB's so_list_head list.  Edit so_list_head to bring it in sync
-   with the inferior's new list.
+   inferior, and compare it with the list of shared objects in the
+   current program space's list of shared libraries.  Edit
+   so_list_head to bring it in sync with the inferior's new list.
 
    If we notice that the inferior has unloaded some shared objects,
    free any symbolic info GDB had read about those shared objects.
index 068aeba2f0ecaccf9b3edff436cff4f2b46c652b..0360d342ae8e3ca29f9a080c434e4ed59a565bee 100644 (file)
 #include "symtab.h"
 #include "gdb_bfd.h"
 
-#define ALL_SO_LIBS(so) \
-    for (so = so_list_head; \
-        so != NULL; \
-        so = so->next)
-
 /* Base class for target-specific link map information.  */
 
 struct lm_info_base
@@ -183,9 +178,6 @@ struct so_deleter
 /* A unique pointer to a so_list.  */
 typedef std::unique_ptr<so_list, so_deleter> so_list_up;
 
-/* Return address of first so_list entry in master shared object list.  */
-struct so_list *master_so_list (void);
-
 /* Find main executable binary file.  */
 extern gdb::unique_xmalloc_ptr<char> exec_file_find (const char *in_pathname,
                                                     int *fd);