31 #include "aout/stab_gnu.h" 84 asymbol **oso_sym, asymbol **end_sym,
85 unsigned int nbr_syms)
89 el.
name = (*oso_sym)->name;
90 el.
mtime = (*oso_sym)->value;
103 if (sym->name == NULL || *sym->name ==
'\0')
110 if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
116 symaddr = sym->value + sym->section->vma;
118 if (sym->section == bfd_abs_section_ptr)
120 else if (sym->section->flags & SEC_CODE)
122 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
127 else if (sym->section->flags & SEC_ALLOC)
129 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
131 if (sym->section->flags & SEC_LOAD)
136 else if (sym->flags & BSF_LOCAL)
140 if (sym->section->flags & SEC_LOAD)
163 long number_of_symbols, asymbol **symbol_table,
167 const asymbol *file_so = NULL;
168 asymbol **oso_file = NULL;
169 unsigned int nbr_syms = 0;
192 for (i = 0; i < number_of_symbols; i++)
194 const asymbol *sym = symbol_table[i];
195 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
200 if (mach_o_sym->n_type == N_SO)
203 if (sym->name == NULL || sym->name[0] == 0)
207 _(
"Unexpected empty N_SO stab"));
215 else if (sym->flags & BSF_DEBUGGING)
217 if (mach_o_sym->n_type == N_OPT)
225 _(
"%s: Unexpected debug stab outside SO markers"),
237 if (mach_o_sym->n_type == N_SO)
239 if (sym->name == NULL || sym->name[0] == 0)
245 else if (state == S_FIRST_SO)
254 else if (mach_o_sym->n_type == N_OSO)
256 if (sym->name == NULL || sym->name[0] == 0)
261 warning (
_(
"stabs debugging not supported for %s"),
267 oso_file = symbol_table + i;
269 state = S_DWARF_FILE;
274 _(
"Unexpected stab after SO"));
279 if (mach_o_sym->n_type == N_SO)
281 if (sym->name == NULL || sym->name[0] == 0)
284 if (state == S_DWARF_FILE)
286 oso_file, symbol_table + i,
297 else if (sym->flags & BSF_DEBUGGING)
299 if (state == S_STAB_FILE)
305 switch (mach_o_sym->n_type)
308 if (sym->name == NULL || sym->name[0] == 0)
321 _(
"unhandled stab for dwarf OSO file"));
328 _(
"non-debugging symbol within SO"));
333 if (state != S_NO_SO)
345 int name_len = strlen (
name);
347 if (name_len == 0 ||
name[name_len - 1] !=
')')
350 lparen = strrchr (
name,
'(');
351 if (lparen == NULL || lparen ==
name)
353 return lparen -
name;
379 static struct bfd_hash_entry *
381 struct bfd_hash_table *table,
396 bfd_hash_newfunc ((
struct bfd_hash_entry *) ret, table,
string);
404 return (
struct bfd_hash_entry *) ret;
415 const char *
name = sym->name;
417 if (
name[0] == bfd_get_symbol_leading_char (main_objfile->
obfd))
422 warning (
_(
"can't find symbol '%s' in minsymtab"),
name);
435 symfile_add_flags symfile_flags)
439 asymbol **symbol_table;
441 struct bfd_hash_table table;
445 unsigned char *sections_rebased;
449 (
_(
"Loading debugging symbols from oso: %s\n"), oso->
name);
451 if (!bfd_check_format (abfd.
get (), bfd_object))
454 bfd_errmsg (bfd_get_error ()));
458 if (abfd->my_archive == NULL && oso->
mtime != bfd_get_mtime (abfd.
get ()))
460 warning (
_(
"`%s': file time stamp mismatch."), oso->
name);
468 warning (
_(
"`%s': can't create hash table"), oso->
name);
472 bfd_set_cacheable (abfd.
get (), 1);
475 storage = bfd_get_symtab_upper_bound (abfd.
get ());
476 symbol_table = (asymbol **)
xmalloc (storage);
477 bfd_canonicalize_symtab (abfd.
get (), symbol_table);
480 nbr_sections = bfd_count_sections (abfd.
get ());
481 sections_rebased = (
unsigned char *) alloca (nbr_sections);
482 for (i = 0; i < nbr_sections; i++)
483 sections_rebased[i] = 0;
488 const asymbol *sym = *symp;
489 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
491 switch (mach_o_sym->n_type)
499 if (sym->name == NULL || sym->name[0] == 0)
513 bfd_hash_lookup (&table,
sym->name, TRUE, FALSE);
514 if (ent->
sym != NULL)
516 _(
"Duplicated symbol %s in symbol table"),
sym->name);
523 (
_(
"Adding symbol %s (addr: %s)\n"),
524 sym->name,
paddress (arch, sym->value));
532 for (i = 0; symbol_table[i]; i++)
534 asymbol *sym = symbol_table[i];
535 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
537 if (mach_o_sym->n_type & BFD_MACH_O_N_STAB)
539 if ((mach_o_sym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_UNDF
549 sym->section = bfd_com_section_ptr;
553 else if ((mach_o_sym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_SECT)
556 asection *sec = sym->section;
557 bfd_mach_o_section *msec;
558 unsigned int sec_type;
561 if (sec == NULL || sections_rebased[sec->index] != 0)
565 msec = bfd_mach_o_get_mach_o_section (sec);
566 sec_type = msec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
567 if ((sec_type == BFD_MACH_O_S_REGULAR
568 || sec_type == BFD_MACH_O_S_ZEROFILL)
569 && (msec->flags & BFD_MACH_O_S_ATTR_DEBUG) == 0)
573 if ((mach_o_sym->n_type & BFD_MACH_O_N_EXT) != 0)
583 bfd_hash_lookup (&table,
sym->name, FALSE, FALSE);
585 addr = bfd_asymbol_value (ent->
sym);
597 (
_(
"resolve sect %s with %s (set to %s)\n"),
598 sec->name, sym->name,
601 bfd_set_section_vma (abfd.
get (), sec, res);
602 sections_rebased[sec->index] = 1;
608 sections_rebased[sec->index] = 2;
613 bfd_hash_table_free (&table);
632 symfile_add_flags symfile_flags)
660 if (strncmp (oso2->
name, archive_name.c_str (), pfx_len) != 0)
667 if (archive_bfd == NULL)
669 warning (
_(
"Could not open OSO archive file \"%s\""),
670 archive_name.c_str ());
674 if (!bfd_check_format (archive_bfd.
get (), bfd_archive))
676 warning (
_(
"OSO archive file \"%s\" not an archive."),
677 archive_name.c_str ());
685 if (member_bfd == NULL)
687 warning (
_(
"Could not read archive members out of " 688 "OSO archive \"%s\""), archive_name.c_str ());
694 while (member_bfd != NULL)
696 const char *member_name = member_bfd->filename;
697 int member_len = strlen (member_name);
700 for (ix2 = ix; ix2 < last_ix; ix2++)
705 && strlen (oso2->
name) == pfx_len + member_len + 2
706 && !memcmp (member_name, oso2->
name + pfx_len + 1,
710 bfd_get_filename (member_bfd),
711 main_objfile, symfile_flags);
720 for (ix2 = ix; ix2 < last_ix; ix2++)
724 if (oso2->
name != NULL)
725 warning (
_(
"Could not find specified archive member " 726 "for OSO name \"%s\""), oso->
name);
734 warning (
_(
"`%s': can't open to read symbols: %s."), oso->
name,
735 bfd_errmsg (bfd_get_error ()));
750 #define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/" 763 size_t base_len = strlen (base_name);
764 char *dsym_filename = (
char *) alloca (name_len + dsym_len + base_len + 1);
765 bfd_mach_o_load_command *main_uuid;
766 bfd_mach_o_load_command *dsym_uuid;
770 strcpy (dsym_filename + name_len + dsym_len, base_name);
772 if (access (dsym_filename, R_OK) != 0)
776 BFD_MACH_O_LC_UUID, &main_uuid) == 0)
782 if (dsym_bfd == NULL)
784 warning (
_(
"can't open dsym file %s"), dsym_filename);
788 if (!bfd_check_format (dsym_bfd.
get (), bfd_object))
790 warning (
_(
"bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
794 if (bfd_mach_o_lookup_command (dsym_bfd.
get (),
795 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
797 warning (
_(
"can't find UUID in %s"), dsym_filename);
800 if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
801 sizeof (main_uuid->command.uuid.uuid)))
803 warning (
_(
"dsym file UUID doesn't match the one in %s"),
807 *filenamep = xstrdup (dsym_filename);
822 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
827 storage_needed = bfd_get_symtab_upper_bound (
objfile->
obfd);
828 if (storage_needed < 0)
829 error (
_(
"Can't read symbols from %s: %s"),
831 bfd_errmsg (bfd_get_error ()));
833 if (storage_needed > 0)
835 asymbol **symbol_table;
838 symbol_table = (asymbol **)
xmalloc (storage_needed);
843 symcount = bfd_canonicalize_symtab (
objfile->
obfd, symbol_table);
846 error (
_(
"Can't read symbols from %s: %s"),
848 bfd_errmsg (bfd_get_error ()));
864 if (dsym_bfd != NULL)
866 struct bfd_section *asect, *dsect;
874 for (asect =
objfile->
obfd->sections, dsect = dsym_bfd->sections;
876 asect = asect->next, dsect = dsect->next)
878 if (strcmp (asect->name, dsect->name) != 0)
880 bfd_set_section_size (dsym_bfd.
get (), dsect,
881 bfd_get_section_size (asect));
901 if (oso_vector != NULL)
915 if ((sectp->flags & SEC_RELOC) == 0)
922 return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
960 if (strcmp (bfd_sect_name, addrs->
other[i].
name) == 0)
975 if (
startswith (bfd_sect_name,
"LC_SEGMENT."))
977 if (strcmp (bfd_sect_name,
"__TEXT") == 0
978 || strcmp (bfd_sect_name,
"__TEXT.__text") == 0)
1004 _(
"Set if printing Mach-O symbols processing."),
1005 _(
"Show if printing Mach-O symbols processing."),
int dwarf2_has_info(struct objfile *objfile, const struct dwarf2_debug_sections *names)
static void macho_symfile_init(struct objfile *objfile)
void dwarf2_build_frame_info(struct objfile *objfile)
static void macho_symfile_offsets(struct objfile *objfile, const struct section_addr_info *addrs)
static bfd_byte * macho_symfile_relocate(struct objfile *objfile, asection *sectp, bfd_byte *buf)
int gdb_bfd_section_index(bfd *abfd, asection *section)
struct bfd_section * the_bfd_section
#define BMSYMBOL_VALUE_ADDRESS(symbol)
void warning(const char *fmt,...)
#define obj_section_offset(s)
void * memset(T *s, int c, size_t n)=delete
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *sf)
struct symfile_segment_data * default_symfile_segments(bfd *abfd)
static int get_archive_prefix_len(const char *name)
void dwarf2_build_psymtabs(struct objfile *objfile)
#define ALL_OBJFILE_OSECTIONS(objfile, osect)
#define VEC_safe_push(T, V, O)
static void macho_symfile_finish(struct objfile *objfile)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static void macho_add_oso_symfile(oso_el *oso, const gdb_bfd_ref_ptr &abfd, const char *name, struct objfile *main_objfile, symfile_add_flags symfile_flags)
struct bfd_hash_entry base
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
#define SIZEOF_N_SECTION_OFFSETS(n)
#define VEC_iterate(T, V, I, P)
struct objfile * symbol_file_add_from_bfd(bfd *abfd, const char *name, symfile_add_flags add_flags, struct section_addr_info *addrs, objfile_flags flags, struct objfile *parent)
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd)
static void macho_register_oso(VEC(oso_el) **oso_vector_ptr, struct objfile *objfile, asymbol **oso_sym, asymbol **end_sym, unsigned int nbr_syms)
static unsigned int mach_o_debug_level
void _initialize_machoread(void)
static const struct sym_fns macho_sym_fns
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
struct obj_section * sections
#define VEC_index(T, V, I)
#define complaint(COMPLAINTS, FMT,...)
static int startswith(const char *string, const char *pattern)
static void macho_symtab_add_minsym(minimal_symbol_reader &reader, struct objfile *objfile, const asymbol *sym)
void printf_unfiltered(const char *format,...)
struct cmd_list_element * setdebuglist
static gdb_bfd_ref_ptr macho_check_dsym(struct objfile *objfile, char **filenamep)
const char * objfile_name(const struct objfile *objfile)
static void macho_new_init(struct objfile *objfile)
static void macho_symfile_read_all_oso(VEC(oso_el) **oso_vector_ptr, struct objfile *main_objfile, symfile_add_flags symfile_flags)
static int oso_el_compare_name(const void *vl, const void *vr)
static CORE_ADDR macho_resolve_oso_sym_with_minsym(struct objfile *main_objfile, asymbol *sym)
gdb_bfd_ref_ptr gdb_bfd_openr(const char *filename, const char *target)
struct minimal_symbol * record_with_info(const char *name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
struct complaints * symfile_complaints
struct minimal_symbol * minsym
const struct quick_symbol_functions psym_functions
static void macho_symtab_read(minimal_symbol_reader &reader, struct objfile *objfile, long number_of_symbols, asymbol **symbol_table, VEC(oso_el) **oso_vector_ptr)
#define VEC_address(T, V)
struct other_sections other[1]
struct cmd_list_element * showdebuglist
static void macho_symfile_read(struct objfile *objfile, symfile_add_flags symfile_flags)
struct section_offsets * section_offsets
static struct bfd_hash_entry * macho_sym_hash_newfunc(struct bfd_hash_entry *entry, struct bfd_hash_table *table, const char *string)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
gdb_bfd_ref_ptr gdb_bfd_openr_next_archived_file(bfd *archive, bfd *previous)
void error(const char *fmt,...)
void do_cleanups(struct cleanup *old_chain)
void symbol_file_add_separate(bfd *bfd, const char *name, symfile_add_flags symfile_flags, struct objfile *objfile)