34#include "mach-o/external.h"
61#define DYLD_VERSION_MIN 1
62#define DYLD_VERSION_MAX 15
113 if (info->all_image_addr == 0)
118 len = 4 + 4 + 2 * ptr_type->
length ();
119 gdb_assert (len <=
sizeof (buf));
120 memset (&info->all_image, 0, sizeof (info->all_image));
134 (buf + 8 + ptr_type->
length (), ptr_type);
151 asymbol **symbol_table;
152 unsigned int number_of_symbols;
154 CORE_ADDR symaddr = 0;
156 storage_needed = bfd_get_symtab_upper_bound (abfd);
158 if (storage_needed <= 0)
161 symbol_table = (asymbol **)
xmalloc (storage_needed);
162 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
164 for (i = 0; i < number_of_symbols; i++)
166 asymbol *sym = symbol_table[i];
168 if (strcmp (sym->name, symname) == 0
169 && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0)
172 symaddr = sym->value + sym->section->vma;
176 xfree (symbol_table);
192 bfd_mach_o_load_command *cmd;
195 BFD_MACH_O_LC_LOAD_DYLINKER, &cmd) == 1)
196 return cmd->command.dylinker.name_str;
221 int ptr_len = ptr_type->
length ();
222 unsigned int image_info_size;
234 image_info_size = ptr_len * 3;
240 for (i = 0; i < info->all_image.count; i++)
242 CORE_ADDR iinfo = info->all_image.info + i * image_info_size;
243 gdb_byte buf[image_info_size];
246 struct mach_o_header_external hdr;
247 unsigned long hdr_val;
261 (hdr.magic, sizeof (hdr.magic), byte_order);
262 if (hdr_val != BFD_MACH_O_MH_MAGIC && hdr_val != BFD_MACH_O_MH_MAGIC_64)
266 (hdr.filetype, sizeof (hdr.filetype), byte_order);
267 if (hdr_val == BFD_MACH_O_MH_EXECUTE)
270 gdb::unique_xmalloc_ptr<char> file_path
272 if (file_path ==
nullptr)
276 gdb::unique_xmalloc_ptr<struct so_list> newobj (XCNEW (
struct so_list));
279 newobj->lm_info = li;
283 strcpy (newobj->so_original_name, newobj->so_name);
287 head = newobj.get ();
289 tail->
next = newobj.get ();
290 tail = newobj.release ();
303 struct mach_o_header_external hdr;
304 unsigned long hdr_val;
312 (hdr.magic, sizeof (hdr.magic), byte_order);
313 if (hdr_val != BFD_MACH_O_MH_MAGIC && hdr_val != BFD_MACH_O_MH_MAGIC_64)
318 (hdr.filetype, sizeof (hdr.filetype), byte_order);
319 if (hdr_val == BFD_MACH_O_MH_EXECUTE)
333 int ptr_len = ptr_type->
length ();
334 unsigned int image_info_size = ptr_len * 3;
338 for (i = 0; i < info->all_image.count; i++)
340 CORE_ADDR iinfo = info->all_image.info + i * image_info_size;
341 gdb_byte buf[image_info_size];
365 ULONGEST load_ptr_addr;
372 &load_ptr_addr) != REG_VALID)
399 const bfd_arch_info_type *arch)
401 bfd *result = bfd_mach_o_fat_extract (abfd, format, arch);
432 if (dyld_bfd != NULL)
448 CORE_ADDR load_addr = 0;
451 if (dyld_bfd == NULL)
458 - bfd_get_start_address (dyld_bfd.get ()));
461 info->all_image_addr =
464 if (
info->all_image_addr == 0)
467 info->all_image_addr += load_addr;
481 if (ptr_type->
length () > sizeof (buf))
486 NULL, buf, 0, ptr_type->
length ());
507 info->all_image_addr = 0;
511 if (info->all_image_addr == 0)
514 if (info->all_image_addr == 0)
521 warning (_(
"unhandled dyld version (%d)"), info->all_image.version);
525 if (info->all_image.count != 0)
548 if (vmaddr != load_addr)
554 CORE_ADDR notifier = info->all_image.notifier;
556 if (info->all_image.count == 0)
567 if (dyld_bfd != NULL)
569 CORE_ADDR dyld_bfd_start_address;
570 CORE_ADDR dyld_relocated_base_address;
573 dyld_bfd_start_address = bfd_get_start_address (dyld_bfd.get());
581 dyld_relocated_base_address = pc - dyld_bfd_start_address;
587 notifier += dyld_relocated_base_address;
603 info->all_image_addr = 0;
604 info->all_image.version = 0;
646 gdb::unique_xmalloc_ptr<char> found_pathname
648 if (found_pathname == NULL)
649 perror_with_name (pathname);
658 error (_(
"`%s': not a shared-library: %s"),
659 bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ()));
664 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)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
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