aboutsummaryrefslogtreecommitdiff
path: root/gdb/solib-darwin.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/solib-darwin.c')
-rw-r--r--gdb/solib-darwin.c112
1 files changed, 40 insertions, 72 deletions
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 6c7d906..aac8ab2 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -1,6 +1,6 @@
/* Handle Darwin shared libraries for GDB, the GNU Debugger.
- Copyright (C) 2009-2024 Free Software Foundation, Inc.
+ Copyright (C) 2009-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -27,12 +27,31 @@
#include "regcache.h"
#include "gdb_bfd.h"
-#include "solist.h"
+#include "solib.h"
#include "solib-darwin.h"
#include "mach-o.h"
#include "mach-o/external.h"
+/* solib_ops for Darwin systems. */
+
+struct darwin_solib_ops : public solib_ops
+{
+ void relocate_section_addresses (solib &so, target_section *) const override;
+ void clear_solib (program_space *pspace) const override;
+ void create_inferior_hook (int from_tty) const override;
+ owning_intrusive_list<solib> current_sos () const override;
+ gdb_bfd_ref_ptr bfd_open (const char *pathname) const override;
+};
+
+/* See solib-darwin.h. */
+
+solib_ops_up
+make_darwin_solib_ops ()
+{
+ return std::make_unique<darwin_solib_ops> ();
+}
+
struct gdb_dyld_image_info
{
/* Base address (which corresponds to the Mach-O header). */
@@ -133,7 +152,7 @@ darwin_load_image_infos (struct darwin_info *info)
(buf + 8 + ptr_type->length (), ptr_type);
}
-/* Link map info to include in an allocated so_list entry. */
+/* Link map info to include in an allocated solib entry. */
struct lm_info_darwin final : public lm_info
{
@@ -146,24 +165,13 @@ struct lm_info_darwin final : public lm_info
static CORE_ADDR
lookup_symbol_from_bfd (bfd *abfd, const char *symname)
{
- long storage_needed;
- asymbol **symbol_table;
- unsigned int number_of_symbols;
- unsigned int i;
CORE_ADDR symaddr = 0;
- storage_needed = bfd_get_symtab_upper_bound (abfd);
+ gdb::array_view<asymbol *> symbol_table
+ = gdb_bfd_canonicalize_symtab (abfd, false);
- if (storage_needed <= 0)
- return 0;
-
- symbol_table = (asymbol **) xmalloc (storage_needed);
- number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
-
- for (i = 0; i < number_of_symbols; i++)
+ for (const asymbol *sym : symbol_table)
{
- asymbol *sym = symbol_table[i];
-
if (strcmp (sym->name, symname) == 0
&& (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
{
@@ -172,7 +180,6 @@ lookup_symbol_from_bfd (bfd *abfd, const char *symname)
break;
}
}
- xfree (symbol_table);
return symaddr;
}
@@ -200,20 +207,8 @@ find_program_interpreter (void)
return buf;
}
-/* Not used. I don't see how the main symbol file can be found: the
- interpreter name is needed and it is known from the executable file.
- Note that darwin-nat.c implements pid_to_exec_file. */
-
-static int
-open_symbol_file_object (int from_tty)
-{
- return 0;
-}
-
-/* Build a list of currently loaded shared objects. See solib-svr4.c. */
-
-static owning_intrusive_list<solib>
-darwin_current_sos ()
+owning_intrusive_list<solib>
+darwin_solib_ops::current_sos () const
{
type *ptr_type
= builtin_type (current_inferior ()->arch ())->builtin_data_ptr;
@@ -272,12 +267,12 @@ darwin_current_sos ()
break;
/* Create and fill the new struct solib element. */
- auto &newobj = sos.emplace_back ();
+ auto &newobj = sos.emplace_back (*this);
auto li = std::make_unique<lm_info_darwin> ();
- newobj.so_name = file_path.get ();
- newobj.so_original_name = newobj.so_name;
+ newobj.name = file_path.get ();
+ newobj.original_name = newobj.name;
li->lm_addr = load_addr;
newobj.lm_info = std::move (li);
@@ -375,15 +370,6 @@ darwin_read_exec_load_addr_at_init (struct darwin_info *info)
return darwin_validate_exec_header (load_addr);
}
-/* Return 1 if PC lies in the dynamic symbol resolution code of the
- run time loader. */
-
-static int
-darwin_in_dynsym_resolve_code (CORE_ADDR pc)
-{
- return 0;
-}
-
/* A wrapper for bfd_mach_o_fat_extract that handles reference
counting properly. This will either return NULL, or return a new
reference to a BFD. */
@@ -488,10 +474,8 @@ darwin_solib_read_all_image_info_addr (struct darwin_info *info)
info->all_image_addr = extract_unsigned_integer (buf, len, BFD_ENDIAN_BIG);
}
-/* Shared library startup support. See documentation in solib-svr4.c. */
-
-static void
-darwin_solib_create_inferior_hook (int from_tty)
+void
+darwin_solib_ops::create_inferior_hook (int from_tty) const
{
/* Everything below only makes sense if we have a running inferior. */
if (!target_has_execution ())
@@ -591,8 +575,8 @@ darwin_solib_create_inferior_hook (int from_tty)
create_solib_event_breakpoint (current_inferior ()->arch (), notifier);
}
-static void
-darwin_clear_solib (program_space *pspace)
+void
+darwin_solib_ops::clear_solib (program_space *pspace) const
{
darwin_info *info = get_darwin_info (pspace);
@@ -603,8 +587,9 @@ darwin_clear_solib (program_space *pspace)
/* The section table is built from bfd sections using bfd VMAs.
Relocate these VMAs according to solib info. */
-static void
-darwin_relocate_section_addresses (solib &so, target_section *sec)
+void
+darwin_solib_ops::relocate_section_addresses (solib &so,
+ target_section *sec) const
{
auto *li = gdb::checked_static_cast<lm_info_darwin *> (so.lm_info.get ());
@@ -623,9 +608,9 @@ darwin_relocate_section_addresses (solib &so, target_section *sec)
if (sec->addr < so.addr_low)
so.addr_low = sec->addr;
}
-
-static gdb_bfd_ref_ptr
-darwin_bfd_open (const char *pathname)
+
+gdb_bfd_ref_ptr
+darwin_solib_ops::bfd_open (const char *pathname) const
{
int found_file;
@@ -653,20 +638,3 @@ darwin_bfd_open (const char *pathname)
return res;
}
-
-const solib_ops darwin_so_ops =
-{
- darwin_relocate_section_addresses,
- nullptr,
- darwin_clear_solib,
- darwin_solib_create_inferior_hook,
- darwin_current_sos,
- open_symbol_file_object,
- darwin_in_dynsym_resolve_code,
- darwin_bfd_open,
- nullptr,
- nullptr,
- nullptr,
- nullptr,
- default_find_solib_addr,
-};