Replace solib_global_lookup with gdbarch_iterate_over_objfiles_in_search_order
authorChristian Biesinger <cbiesinger@google.com>
Thu, 1 Aug 2019 16:53:03 +0000 (11:53 -0500)
committerChristian Biesinger <cbiesinger@google.com>
Sat, 21 Sep 2019 02:09:15 +0000 (21:09 -0500)
All implementations of either function use it for the same purpose (except
Darwin, which is a no-op): to prefer a symbol in the current objfile over
symbols with the same name in other objfiles. There does not seem to be a
reason to have both mechanisms for that purpose.

gdb/ChangeLog:

2019-09-20  Christian Biesinger  <cbiesinger@google.com>

* solib-darwin.c (darwin_lookup_lib_symbol): Remove.
(_initialize_darwin_solib): Don't set
darwin_so_ops.lookup_lib_global_symbol.
* solib-svr4.c (set_solib_svr4_fetch_link_map_offsets): Call
set_gdbarch_iterate_over_objfiles_in_search_order.
(elf_lookup_lib_symbol): Rename to...
(svr4_iterate_over_objfiles_in_search_order): this, and update
to iterate semantics.
(_initialize_svr4_solib): Don't set lookup_lib_global_symbol.
* solib.c (solib_global_lookup): Remove.
* solist.h (struct target_so_ops): Remove lookup_lib_global_symbol.
(solib_global_lookup): Remove.
* symtab.c (lookup_global_or_static_symbol): Remove call to
solib_global_lookup.

gdb/ChangeLog
gdb/solib-darwin.c
gdb/solib-svr4.c
gdb/solib.c
gdb/solist.h
gdb/symtab.c

index 67aba3ed2d77c481b216a52a6d29920fbad13e3a..3d0975afd8165a7cae158e798c7871a7cf916b09 100644 (file)
@@ -1,3 +1,20 @@
+2019-09-20  Christian Biesinger  <cbiesinger@google.com>
+
+       * solib-darwin.c (darwin_lookup_lib_symbol): Remove.
+       (_initialize_darwin_solib): Don't set
+       darwin_so_ops.lookup_lib_global_symbol.
+       * solib-svr4.c (set_solib_svr4_fetch_link_map_offsets): Call
+       set_gdbarch_iterate_over_objfiles_in_search_order.
+       (elf_lookup_lib_symbol): Rename to...
+       (svr4_iterate_over_objfiles_in_search_order): this, and update
+       to iterate semantics.
+       (_initialize_svr4_solib): Don't set lookup_lib_global_symbol.
+       * solib.c (solib_global_lookup): Remove.
+       * solist.h (struct target_so_ops): Remove lookup_lib_global_symbol.
+       (solib_global_lookup): Remove.
+       * symtab.c (lookup_global_or_static_symbol): Remove call to
+       solib_global_lookup.
+
 2019-09-20  Joel Brobecker  <brobecker@adacore.com>
 
        * NEWS: Move entries about default MI version now being
index 778c6d9f6173dd6f45fc25e32f1d222a71b5f07f..286e38558f20331e5af8847da792eed2adc2752e 100644 (file)
@@ -638,14 +638,6 @@ darwin_relocate_section_addresses (struct so_list *so,
     so->addr_low = sec->addr;
 }
 \f
-static struct block_symbol
-darwin_lookup_lib_symbol (struct objfile *objfile,
-                         const char *name,
-                         const domain_enum domain)
-{
-  return {};
-}
-
 static gdb_bfd_ref_ptr
 darwin_bfd_open (const char *pathname)
 {
@@ -687,6 +679,5 @@ _initialize_darwin_solib (void)
   darwin_so_ops.current_sos = darwin_current_sos;
   darwin_so_ops.open_symbol_file_object = open_symbol_file_object;
   darwin_so_ops.in_dynsym_resolve_code = darwin_in_dynsym_resolve_code;
-  darwin_so_ops.lookup_lib_global_symbol = darwin_lookup_lib_symbol;
   darwin_so_ops.bfd_open = darwin_bfd_open;
 }
index e04fde942d15b8fb0d9827d77f1794b35a3c76d3..dc635491058a7af4d974bfd0e4403eabdb6bc935 100644 (file)
@@ -51,6 +51,10 @@ static int svr4_have_link_map_offsets (void);
 static void svr4_relocate_main_executable (void);
 static void svr4_free_library_list (void *p_list);
 static void probes_table_remove_objfile_probes (struct objfile *objfile);
+static void svr4_iterate_over_objfiles_in_search_order (
+  struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb,
+  void *cb_data, struct objfile *objfile);
+
 
 /* On SVR4 systems, a list of symbols in the dynamic linker where
    GDB can try to place a breakpoint to monitor shared library
@@ -3102,6 +3106,8 @@ set_solib_svr4_fetch_link_map_offsets (struct gdbarch *gdbarch,
   ops->fetch_link_map_offsets = flmo;
 
   set_solib_ops (gdbarch, &svr4_so_ops);
+  set_gdbarch_iterate_over_objfiles_in_search_order
+    (gdbarch, svr4_iterate_over_objfiles_in_search_order);
 }
 
 /* Fetch a link_map_offsets structure using the architecture-specific
@@ -3200,32 +3206,45 @@ svr4_lp64_fetch_link_map_offsets (void)
 
 struct target_so_ops svr4_so_ops;
 
-/* Lookup global symbol for ELF DSOs linked with -Bsymbolic.  Those DSOs have a
+/* Search order for ELF DSOs linked with -Bsymbolic.  Those DSOs have a
    different rule for symbol lookup.  The lookup begins here in the DSO, not in
    the main executable.  */
 
-static struct block_symbol
-elf_lookup_lib_symbol (struct objfile *objfile,
-                      const char *name,
-                      const domain_enum domain)
+static void
+svr4_iterate_over_objfiles_in_search_order
+  (struct gdbarch *gdbarch,
+   iterate_over_objfiles_in_search_order_cb_ftype *cb,
+   void *cb_data, struct objfile *current_objfile)
 {
-  bfd *abfd;
-
-  if (objfile == symfile_objfile)
-    abfd = exec_bfd;
-  else
+  bool checked_current_objfile = false;
+  if (current_objfile != nullptr)
     {
-      /* OBJFILE should have been passed as the non-debug one.  */
-      gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
+      bfd *abfd;
 
-      abfd = objfile->obfd;
-    }
+      if (current_objfile->separate_debug_objfile_backlink != nullptr)
+        current_objfile = current_objfile->separate_debug_objfile_backlink;
 
-  if (abfd == NULL || scan_dyntag (DT_SYMBOLIC, abfd, NULL, NULL) != 1)
-    return {};
+      if (current_objfile == symfile_objfile)
+       abfd = exec_bfd;
+      else
+       abfd = current_objfile->obfd;
+
+      if (abfd != nullptr &&
+         scan_dyntag (DT_SYMBOLIC, abfd, nullptr, nullptr) == 1)
+       {
+         checked_current_objfile = true;
+         if (cb (current_objfile, cb_data) != 0)
+           return;
+       }
+    }
 
-  return lookup_global_symbol_from_objfile (objfile, GLOBAL_BLOCK, name,
-                                           domain);
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      if (checked_current_objfile && objfile == current_objfile)
+       continue;
+      if (cb (objfile, cb_data) != 0)
+       return;
+    }
 }
 
 void
@@ -3242,7 +3261,6 @@ _initialize_svr4_solib (void)
   svr4_so_ops.open_symbol_file_object = open_symbol_file_object;
   svr4_so_ops.in_dynsym_resolve_code = svr4_in_dynsym_resolve_code;
   svr4_so_ops.bfd_open = solib_bfd_open;
-  svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
   svr4_so_ops.same = svr4_same;
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
   svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
index b9a61e265b1657813bc68636b76a6dd101a52e91..5b1246929b5b1346447f43de8954a0001bb1b93a 100644 (file)
@@ -1441,21 +1441,6 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
 }
 
 
-/* Handler for library-specific lookup of global symbol NAME in OBJFILE.  Call
-   the library-specific handler if it is installed for the current target.  */
-
-struct block_symbol
-solib_global_lookup (struct objfile *objfile,
-                    const char *name,
-                    const domain_enum domain)
-{
-  const struct target_so_ops *ops = solib_ops (target_gdbarch ());
-
-  if (ops->lookup_lib_global_symbol != NULL)
-    return ops->lookup_lib_global_symbol (objfile, name, domain);
-  return {};
-}
-
 /* Lookup the value for a specific symbol from dynamic symbol table.  Look
    up symbol from ABFD.  MATCH_SYM is a callback function to determine
    whether to pick up a symbol.  DATA is the input of this callback
index e1410c2b79005f8e1e08c6fa6a83c097fee26327..ee99fc815b5da3cc50e61b5d8fe4f17b906094af 100644 (file)
@@ -139,12 +139,6 @@ struct target_so_ops
                              unsigned o_flags,
                              gdb::unique_xmalloc_ptr<char> *temp_pathname);
 
-  /* Hook for looking up global symbols in a library-specific way.  */
-  struct block_symbol (*lookup_lib_global_symbol)
-    (struct objfile *objfile,
-     const char *name,
-     const domain_enum domain);
-
   /* Given two so_list objects, one from the GDB thread list
      and another from the list returned by current_sos, return 1
      if they represent the same library.
@@ -209,9 +203,4 @@ extern gdb_bfd_ref_ptr solib_bfd_open (const char *in_pathname);
 /* FIXME: gdbarch needs to control this variable.  */
 extern struct target_so_ops *current_target_so_ops;
 
-/* Handler for library-specific global symbol lookup in solib.c.  */
-struct block_symbol solib_global_lookup (struct objfile *objfile,
-                                           const char *name,
-                                           const domain_enum domain);
-
 #endif
index 35eab08cb37c381dd6a3ee6c24d842c979f8a779..54c7ed9c7c784a91f9cd1e2d2afcd5115f3c54e5 100644 (file)
@@ -2634,11 +2634,7 @@ lookup_global_or_static_symbol (const char *name,
       return result;
     }
 
-  /* Call library-specific lookup procedure.  */
-  if (objfile != NULL)
-    result = solib_global_lookup (objfile, name, domain);
-
-  /* If that didn't work go a global search (of global blocks, heh).  */
+  /* Do a global search (of global blocks, heh).  */
   if (result.symbol == NULL)
     {
       memset (&lookup_data, 0, sizeof (lookup_data));
This page took 0.034365 seconds and 4 git commands to generate.