]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use function_view in gdb_bfd_lookup_symbol
authorTom Tromey <tom@tromey.com>
Sun, 19 Mar 2023 22:12:58 +0000 (16:12 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 28 Mar 2023 21:12:40 +0000 (15:12 -0600)
This changes gdb_bfd_lookup_symbol to use a function_view.  This
simplifies the code a little bit.

gdb/solib-dsbt.c
gdb/solib-frv.c
gdb/solib-svr4.c
gdb/solib.c
gdb/solib.h

index 557df74eb00d17677ab8a2f6c447e330ec1198e6..866087ef3a5a524d0143ff8810d7bf35feeb6ccd 100644 (file)
@@ -662,14 +662,6 @@ enable_break_failure_warning (void)
             "and track explicitly loaded dynamic code."));
 }
 
-/* Helper function for gdb_bfd_lookup_symbol.  */
-
-static int
-cmp_name (const asymbol *sym, const void *data)
-{
-  return (strcmp (sym->name, (const char *) data) == 0);
-}
-
 /* The dynamic linkers has, as part of its debugger interface, support
    for arranging for the inferior to hit a breakpoint after mapping in
    the shared libraries.  This function enables that breakpoint.
@@ -759,8 +751,13 @@ enable_break (void)
            = info->interp_plt_sect_low + bfd_section_size (interp_sect);
        }
 
-      addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), cmp_name,
-                                   "_dl_debug_state");
+      addr = (gdb_bfd_lookup_symbol
+             (tmp_bfd.get (),
+              [] (const asymbol *sym)
+              {
+                return strcmp (sym->name, "_dl_debug_state") == 0;
+              }));
+
       if (addr != 0)
        {
          if (solib_dsbt_debug)
index 38aed7a6ca4def3708fa628202a5733abb45b8d2..240b4da5d9da67caba19a26d8cc319f09ed66fd8 100644 (file)
@@ -472,14 +472,6 @@ enable_break_failure_warning (void)
           "and track explicitly loaded dynamic code."));
 }
 
-/* Helper function for gdb_bfd_lookup_symbol.  */
-
-static int
-cmp_name (const asymbol *sym, const void *data)
-{
-  return (strcmp (sym->name, (const char *) data) == 0);
-}
-
 /* Arrange for dynamic linker to hit breakpoint.
 
    The dynamic linkers has, as part of its debugger interface, support
@@ -602,7 +594,12 @@ enable_break2 (void)
            interp_plt_sect_low + bfd_section_size (interp_sect);
        }
 
-      addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), cmp_name, "_dl_debug_addr");
+      addr = (gdb_bfd_lookup_symbol
+             (tmp_bfd.get (),
+              [] (const asymbol *sym)
+              {
+                return strcmp (sym->name, "_dl_debug_addr") == 0;
+              }));
 
       if (addr == 0)
        {
index b3f6b6adaf24444d1f064a8e285254b596df2dfc..5a728939111a8865de873bce876750d0002aaa60 100644 (file)
@@ -2301,14 +2301,6 @@ svr4_create_solib_event_breakpoints (svr4_info *info, struct gdbarch *gdbarch,
     }
 }
 
-/* Helper function for gdb_bfd_lookup_symbol.  */
-
-static int
-cmp_name_and_sec_flags (const asymbol *sym, const void *data)
-{
-  return (strcmp (sym->name, (const char *) data) == 0
-         && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0);
-}
 /* Arrange for dynamic linker to hit breakpoint.
 
    Both the SunOS and the SVR4 dynamic linkers have, as part of their
@@ -2553,9 +2545,15 @@ enable_break (struct svr4_info *info, int from_tty)
       /* Now try to set a breakpoint in the dynamic linker.  */
       for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
        {
-         sym_addr = gdb_bfd_lookup_symbol (tmp_bfd.get (),
-                                           cmp_name_and_sec_flags,
-                                           *bkpt_namep);
+         sym_addr
+           = (gdb_bfd_lookup_symbol
+              (tmp_bfd.get (),
+               [=] (const asymbol *sym)
+               {
+                 return (strcmp (sym->name, *bkpt_namep) == 0
+                         && ((sym->section->flags & (SEC_CODE | SEC_DATA))
+                             != 0));
+               }));
          if (sym_addr != 0)
            break;
        }
index ce10fc5aaf2c495a595a67eeab89ba28ae0235c3..54f1723debfe0cb7960d89b8df01a34138c0fe4a 100644 (file)
@@ -1475,13 +1475,11 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
 /* 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
-   function.  Return NULL if symbol is not found.  */
+   function.  Return 0 if symbol is not found.  */
 
 CORE_ADDR
-gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-                                  int (*match_sym) (const asymbol *,
-                                                    const void *),
-                                  const void *data)
+gdb_bfd_lookup_symbol_from_symtab
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
 {
   long storage_needed = bfd_get_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1499,7 +1497,7 @@ gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
        {
          asymbol *sym  = *symbol_table++;
 
-         if (match_sym (sym, data))
+         if (match_sym (sym))
            {
              struct gdbarch *gdbarch = target_gdbarch ();
              symaddr = sym->value;
@@ -1671,14 +1669,12 @@ gdb_bfd_read_elf_soname (const char *filename)
 
 /* Lookup the value for a specific symbol from 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 function.  Return NULL
+   up a symbol.  DATA is the input of this callback function.  Return 0
    if symbol is not found.  */
 
 static CORE_ADDR
-bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
-                                  int (*match_sym) (const asymbol *,
-                                                    const void *),
-                                  const void *data)
+bfd_lookup_symbol_from_dyn_symtab
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
 {
   long storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
   CORE_ADDR symaddr = 0;
@@ -1695,7 +1691,7 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
        {
          asymbol *sym = *symbol_table++;
 
-         if (match_sym (sym, data))
+         if (match_sym (sym))
            {
              /* BFD symbols are section relative.  */
              symaddr = sym->value + sym->section->vma;
@@ -1709,20 +1705,19 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd,
 /* Lookup the value for a specific symbol from symbol table and 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 function.  Return NULL if symbol is not
+   input of this callback function.  Return 0 if symbol is not
    found.  */
 
 CORE_ADDR
-gdb_bfd_lookup_symbol (bfd *abfd,
-                      int (*match_sym) (const asymbol *, const void *),
-                      const void *data)
+gdb_bfd_lookup_symbol
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym)
 {
-  CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym, data);
+  CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym);
 
   /* On FreeBSD, the dynamic linker is stripped by default.  So we'll
      have to check the dynamic string table too.  */
   if (symaddr == 0)
-    symaddr = bfd_lookup_symbol_from_dyn_symtab (abfd, match_sym, data);
+    symaddr = bfd_lookup_symbol_from_dyn_symtab (abfd, match_sym);
 
   return symaddr;
 }
index 24c365a0ae0f7520a27f42e5cb90e8a46c8681af..77e023002edf784e5e55e0857408c6cf22f70ef1 100644 (file)
@@ -28,6 +28,7 @@ struct program_space;
 
 #include "gdb_bfd.h"
 #include "symfile-add-flags.h"
+#include "gdbsupport/function-view.h"
 
 /* Value of the 'set debug solib' configuration variable.  */
 
@@ -107,18 +108,13 @@ extern bool libpthread_name_p (const char *name);
 
 /* Look up symbol from both symbol table and dynamic string table.  */
 
-extern CORE_ADDR gdb_bfd_lookup_symbol (bfd *abfd,
-                                       int (*match_sym) (const asymbol *,
-                                                         const void *),
-                                       const void *data);
+extern CORE_ADDR gdb_bfd_lookup_symbol
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym);
 
 /* Look up symbol from symbol table.  */
 
-extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
-                                                   int (*match_sym)
-                                                     (const asymbol *,
-                                                      const void *),
-                                                   const void *data);
+extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab
+     (bfd *abfd, gdb::function_view<bool (const asymbol *)> match_sym);
 
 /* Scan for DESIRED_DYNTAG in .dynamic section of ABFD.  If DESIRED_DYNTAG is
    found, 1 is returned and the corresponding PTR and PTR_ADDR are set.  */