43#include "mach-o/external.h"
70#define DYLD_VERSION_MIN 1
71#define DYLD_VERSION_MAX 15
122 if (info->all_image_addr == 0)
127 len = 4 + 4 + 2 * ptr_type->
length ();
128 gdb_assert (len <=
sizeof (buf));
129 memset (&info->all_image, 0, sizeof (info->all_image));
143 (buf + 8 + ptr_type->
length (), ptr_type);
160 asymbol **symbol_table;
161 unsigned int number_of_symbols;
163 CORE_ADDR symaddr = 0;
165 storage_needed = bfd_get_symtab_upper_bound (abfd);
167 if (storage_needed <= 0)
170 symbol_table = (asymbol **)
xmalloc (storage_needed);
171 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
173 for (i = 0; i < number_of_symbols; i++)
175 asymbol *sym = symbol_table[i];
177 if (strcmp (sym->name, symname) == 0
178 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
181 symaddr = sym->value + sym->section->vma;
185 xfree (symbol_table);
201 bfd_mach_o_load_command *cmd;
204 BFD_MACH_O_LC_LOAD_DYLINKER, &cmd) == 1)
205 return cmd->command.dylinker.name_str;
230 int ptr_len = ptr_type->
length ();
231 unsigned int image_info_size;
243 image_info_size = ptr_len * 3;
249 for (i = 0; i < info->all_image.count; i++)
251 CORE_ADDR iinfo = info->all_image.info + i * image_info_size;
252 gdb_byte buf[image_info_size];
255 struct mach_o_header_external hdr;
256 unsigned long hdr_val;
270 (hdr.magic, sizeof (hdr.magic), byte_order);
271 if (hdr_val != BFD_MACH_O_MH_MAGIC && hdr_val != BFD_MACH_O_MH_MAGIC_64)
275 (hdr.filetype, sizeof (hdr.filetype), byte_order);
276 if (hdr_val == BFD_MACH_O_MH_EXECUTE)
279 gdb::unique_xmalloc_ptr<char> file_path
281 if (file_path ==
nullptr)
285 gdb::unique_xmalloc_ptr<struct so_list> newobj (XCNEW (
struct so_list));
288 newobj->lm_info = li;
292 strcpy (newobj->so_original_name, newobj->so_name);
296 head = newobj.get ();
298 tail->
next = newobj.get ();
299 tail = newobj.release ();
312 struct mach_o_header_external hdr;
313 unsigned long hdr_val;
321 (hdr.magic, sizeof (hdr.magic), byte_order);
322 if (hdr_val != BFD_MACH_O_MH_MAGIC && hdr_val != BFD_MACH_O_MH_MAGIC_64)
327 (hdr.filetype, sizeof (hdr.filetype), byte_order);
328 if (hdr_val == BFD_MACH_O_MH_EXECUTE)
342 int ptr_len = ptr_type->
length ();
343 unsigned int image_info_size = ptr_len * 3;
347 for (i = 0; i < info->all_image.count; i++)
349 CORE_ADDR iinfo = info->all_image.info + i * image_info_size;
350 gdb_byte buf[image_info_size];
374 ULONGEST load_ptr_addr;
381 &load_ptr_addr) != REG_VALID)
408 const bfd_arch_info_type *arch)
410 bfd *result = bfd_mach_o_fat_extract (abfd, format, arch);
441 if (dyld_bfd != NULL)
457 CORE_ADDR load_addr = 0;
460 if (dyld_bfd == NULL)
467 - bfd_get_start_address (dyld_bfd.get ()));
470 info->all_image_addr =
473 if (
info->all_image_addr == 0)
476 info->all_image_addr += load_addr;
490 if (ptr_type->
length () > sizeof (buf))
495 NULL, buf, 0, ptr_type->
length ());
516 info->all_image_addr = 0;
520 if (info->all_image_addr == 0)
523 if (info->all_image_addr == 0)
530 warning (_(
"unhandled dyld version (%d)"), info->all_image.version);
534 if (info->all_image.count != 0)
557 if (vmaddr != load_addr)
563 CORE_ADDR notifier = info->all_image.notifier;
565 if (info->all_image.count == 0)
576 if (dyld_bfd != NULL)
578 CORE_ADDR dyld_bfd_start_address;
579 CORE_ADDR dyld_relocated_base_address;
582 dyld_bfd_start_address = bfd_get_start_address (dyld_bfd.get());
590 dyld_relocated_base_address = pc - dyld_bfd_start_address;
596 notifier += dyld_relocated_base_address;
612 info->all_image_addr = 0;
613 info->all_image.version = 0;
655 gdb::unique_xmalloc_ptr<char> found_pathname
657 if (found_pathname == NULL)
667 error (_(
"`%s': not a shared-library: %s"),
668 bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ()));
673 bfd_set_filename (res.get (), pathname);
struct gdbarch * target_gdbarch(void)
struct breakpoint * create_solib_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
void gdb_bfd_mark_parent(bfd *child, bfd *parent)
void gdb_bfd_ref(struct bfd *abfd)
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd, bool warn_if_slow)
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
int gdbarch_addr_bit(struct gdbarch *gdbarch)
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
enum bfd_endian type_byte_order(const struct type *type)
struct inferior * current_inferior(void)
void objfile_rebase(struct objfile *objfile, CORE_ADDR slide)
struct program_space * current_program_space
CORE_ADDR regcache_read_pc(struct regcache *regcache)
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
struct regcache * get_current_regcache(void)
static struct so_list * darwin_current_sos(void)
static CORE_ADDR darwin_read_exec_load_addr_at_init(struct darwin_info *info)
static char * find_program_interpreter(void)
static void darwin_load_image_infos(struct darwin_info *info)
static int darwin_in_dynsym_resolve_code(CORE_ADDR pc)
static CORE_ADDR lookup_symbol_from_bfd(bfd *abfd, const char *symname)
static int open_symbol_file_object(int from_tty)
static void darwin_clear_solib(void)
static int darwin_dyld_version_ok(const struct darwin_info *info)
static void darwin_solib_read_all_image_info_addr(struct darwin_info *info)
static CORE_ADDR darwin_validate_exec_header(CORE_ADDR load_addr)
static gdb_bfd_ref_ptr darwin_bfd_open(const char *pathname)
static gdb_bfd_ref_ptr gdb_bfd_mach_o_fat_extract(bfd *abfd, bfd_format format, const bfd_arch_info_type *arch)
const struct target_so_ops darwin_so_ops
static const registry< program_space >::key< darwin_info > solib_darwin_pspace_data
static gdb_bfd_ref_ptr darwin_get_dyld_bfd()
static struct darwin_info * get_darwin_info(void)
static void darwin_solib_create_inferior_hook(int from_tty)
static void darwin_free_so(struct so_list *so)
static void darwin_solib_get_all_image_info_addr_at_init(struct darwin_info *info)
static void darwin_relocate_section_addresses(struct so_list *so, struct target_section *sec)
static CORE_ADDR darwin_read_exec_load_addr_from_dyld(struct darwin_info *info)
gdb_bfd_ref_ptr solib_bfd_fopen(const char *pathname, int fd)
gdb::unique_xmalloc_ptr< char > solib_find(const char *in_pathname, int *fd)
#define SO_NAME_MAX_PATH_SIZE
struct type * builtin_data_ptr
struct objfile * symfile_object_file
int target_read_string(CORE_ADDR addr, int len, int width, unsigned int fetchlimit, gdb::unique_xmalloc_ptr< gdb_byte > *buffer, int *bytes_read)
bool target_has_execution(inferior *inf)
LONGEST target_read(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *buf, ULONGEST offset, LONGEST len)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
@ TARGET_OBJECT_DARWIN_DYLD_INFO
void perror_with_name(const char *string)