31 #include "aout/stab_gnu.h"
82 struct objfile *objfile,
83 asymbol **oso_sym, asymbol **end_sym,
84 unsigned int nbr_syms)
88 el.
name = (*oso_sym)->name;
89 el.
mtime = (*oso_sym)->value;
101 if (sym->name == NULL || *sym->name ==
'\0')
108 if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
114 symaddr = sym->value + sym->section->vma;
116 if (sym->section == bfd_abs_section_ptr)
118 else if (sym->section->flags & SEC_CODE)
120 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
125 else if (sym->section->flags & SEC_ALLOC)
127 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
129 if (sym->section->flags & SEC_LOAD)
134 else if (sym->flags & BSF_LOCAL)
138 if (sym->section->flags & SEC_LOAD)
150 (sym->name, symaddr, ms_type,
161 long number_of_symbols, asymbol **symbol_table,
165 const asymbol *dir_so = NULL;
166 const asymbol *file_so = NULL;
167 asymbol **oso_file = NULL;
168 unsigned int nbr_syms = 0;
191 for (i = 0; i < number_of_symbols; i++)
193 const asymbol *sym = symbol_table[i];
194 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
199 if (mach_o_sym->n_type == N_SO)
202 if (sym->name == NULL || sym->name[0] == 0)
206 _(
"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)
255 else if (mach_o_sym->n_type == N_OSO)
257 if (sym->name == NULL || sym->name[0] == 0)
262 warning (
_(
"stabs debugging not supported for %s"),
268 oso_file = symbol_table + i;
270 state = S_DWARF_FILE;
275 _(
"Unexpected stab after SO"));
280 if (mach_o_sym->n_type == N_SO)
282 if (sym->name == NULL || sym->name[0] == 0)
285 if (state == S_DWARF_FILE)
287 oso_file, symbol_table + i,
299 else if (sym->flags & BSF_DEBUGGING)
301 if (state == S_STAB_FILE)
307 switch (mach_o_sym->n_type)
310 if (sym->name == NULL || sym->name[0] == 0)
323 _(
"unhandled stab for dwarf OSO file"));
330 _(
"non-debugging symbol within SO"));
335 if (state != S_NO_SO)
347 int name_len = strlen (name);
349 if (name_len == 0 || name[name_len - 1] !=
')')
352 lparen = strrchr (name,
'(');
353 if (lparen == NULL || lparen == name)
355 return lparen -
name;
381 static struct bfd_hash_entry *
383 struct bfd_hash_table *table,
398 bfd_hash_newfunc ((
struct bfd_hash_entry *) ret, table,
string);
406 return (
struct bfd_hash_entry *) ret;
417 const char *
name = sym->name;
419 if (name[0] == bfd_get_symbol_leading_char (main_objfile->
obfd))
424 warning (
_(
"can't find symbol '%s' in minsymtab"), name);
435 struct objfile *main_objfile,
int symfile_flags)
439 asymbol **symbol_table;
441 struct bfd_hash_table table;
446 unsigned char *sections_rebased;
448 if (mach_o_debug_level > 0)
450 (
_(
"Loading debugging symbols from oso: %s\n"), oso->
name);
452 if (!bfd_check_format (abfd, bfd_object))
455 bfd_errmsg (bfd_get_error ()));
460 if (abfd->my_archive == NULL && oso->
mtime != bfd_get_mtime (abfd))
462 warning (
_(
"`%s': file time stamp mismatch."), oso->
name);
471 warning (
_(
"`%s': can't create hash table"), oso->
name);
476 bfd_set_cacheable (abfd, 1);
479 storage = bfd_get_symtab_upper_bound (abfd);
480 symbol_table = (asymbol **)
xmalloc (storage);
481 bfd_canonicalize_symtab (abfd, symbol_table);
484 nbr_sections = bfd_count_sections (abfd);
485 sections_rebased = (
unsigned char *) alloca (nbr_sections);
486 for (i = 0; i < nbr_sections; i++)
487 sections_rebased[i] = 0;
492 const asymbol *sym = *symp;
493 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
495 switch (mach_o_sym->n_type)
503 if (sym->name == NULL || sym->name[0] == 0)
517 bfd_hash_lookup (&table, sym->name, TRUE, FALSE);
518 if (ent->
sym != NULL)
520 _(
"Duplicated symbol %s in symbol table"), sym->name);
523 if (mach_o_debug_level > 4)
527 (
_(
"Adding symbol %s (addr: %s)\n"),
528 sym->name,
paddress (arch, sym->value));
536 for (i = 0; symbol_table[i]; i++)
538 asymbol *sym = symbol_table[i];
539 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
541 if (mach_o_sym->n_type & BFD_MACH_O_N_STAB)
543 if ((mach_o_sym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_UNDF
553 sym->section = bfd_com_section_ptr;
557 else if ((mach_o_sym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_SECT)
560 asection *sec = sym->section;
561 bfd_mach_o_section *msec;
562 unsigned int sec_type;
565 if (sec == NULL || sections_rebased[sec->index] != 0)
569 msec = bfd_mach_o_get_mach_o_section (sec);
570 sec_type = msec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
571 if ((sec_type == BFD_MACH_O_S_REGULAR
572 || sec_type == BFD_MACH_O_S_ZEROFILL)
573 && (msec->flags & BFD_MACH_O_S_ATTR_DEBUG) == 0)
577 if ((mach_o_sym->n_type & BFD_MACH_O_N_EXT) != 0)
587 bfd_hash_lookup (&table, sym->name, FALSE, FALSE);
589 addr = bfd_asymbol_value (ent->
sym);
597 if (mach_o_debug_level > 3)
601 (
_(
"resolve sect %s with %s (set to %s)\n"),
602 sec->name, sym->name,
605 bfd_set_section_vma (abfd, sec, res);
606 sections_rebased[sec->index] = 1;
612 sections_rebased[sec->index] = 2;
617 bfd_hash_table_free (&table);
636 struct objfile *main_objfile,
658 char *archive_name = XNEWVEC (
char, pfx_len + 1);
663 memcpy (archive_name, oso->
name, pfx_len);
664 archive_name[pfx_len] =
'\0';
672 if (strncmp (oso2->
name, archive_name, pfx_len) != 0)
678 if (archive_bfd == NULL)
680 warning (
_(
"Could not open OSO archive file \"%s\""),
685 if (!bfd_check_format (archive_bfd, bfd_archive))
687 warning (
_(
"OSO archive file \"%s\" not an archive."),
696 if (member_bfd == NULL)
698 warning (
_(
"Could not read archive members out of "
699 "OSO archive \"%s\""), archive_name);
706 while (member_bfd != NULL)
709 const char *member_name = member_bfd->filename;
710 int member_len = strlen (member_name);
713 for (ix2 = ix; ix2 < last_ix; ix2++)
718 && strlen (oso2->
name) == pfx_len + member_len + 2
719 && !memcmp (member_name, oso2->
name + pfx_len + 1,
723 bfd_get_filename (member_bfd),
724 main_objfile, symfile_flags);
738 for (ix2 = ix; ix2 < last_ix; ix2++)
742 if (oso2->
name != NULL)
743 warning (
_(
"Could not find specified archive member "
744 "for OSO name \"%s\""), oso->
name);
754 warning (
_(
"`%s': can't open to read symbols: %s."), oso->
name,
755 bfd_errmsg (bfd_get_error ()));
772 #define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/"
784 const char *base_name = lbasename (
objfile_name (objfile));
785 size_t base_len = strlen (base_name);
786 char *dsym_filename = alloca (name_len + dsym_len + base_len + 1);
788 bfd_mach_o_load_command *main_uuid;
789 bfd_mach_o_load_command *dsym_uuid;
793 strcpy (dsym_filename + name_len + dsym_len, base_name);
795 if (access (dsym_filename, R_OK) != 0)
798 if (bfd_mach_o_lookup_command (objfile->
obfd,
799 BFD_MACH_O_LC_UUID, &main_uuid) == 0)
805 if (dsym_bfd == NULL)
807 warning (
_(
"can't open dsym file %s"), dsym_filename);
811 if (!bfd_check_format (dsym_bfd, bfd_object))
814 warning (
_(
"bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
818 if (bfd_mach_o_lookup_command (dsym_bfd,
819 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
821 warning (
_(
"can't find UUID in %s"), dsym_filename);
825 if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
826 sizeof (main_uuid->command.uuid.uuid)))
828 warning (
_(
"dsym file UUID doesn't match the one in %s"),
833 *filenamep = xstrdup (dsym_filename);
840 bfd *abfd = objfile->
obfd;
850 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
855 storage_needed = bfd_get_symtab_upper_bound (objfile->
obfd);
856 if (storage_needed < 0)
857 error (
_(
"Can't read symbols from %s: %s"),
858 bfd_get_filename (objfile->
obfd),
859 bfd_errmsg (bfd_get_error ()));
861 if (storage_needed > 0)
863 asymbol **symbol_table;
866 symbol_table = (asymbol **)
xmalloc (storage_needed);
872 symcount = bfd_canonicalize_symtab (objfile->
obfd, symbol_table);
875 error (
_(
"Can't read symbols from %s: %s"),
876 bfd_get_filename (objfile->
obfd),
877 bfd_errmsg (bfd_get_error ()));
892 if (dsym_bfd != NULL)
896 struct bfd_section *asect, *dsect;
900 if (mach_o_debug_level > 0)
904 for (asect = objfile->
obfd->sections, dsect = dsym_bfd->sections;
906 asect = asect->next, dsect = dsect->next)
908 if (strcmp (asect->name, dsect->name) != 0)
910 bfd_set_section_size (dsym_bfd, dsect,
911 bfd_get_section_size (asect));
932 if (oso_vector != NULL)
942 bfd *abfd = objfile->
obfd;
946 if ((sectp->flags & SEC_RELOC) == 0)
949 if (mach_o_debug_level > 0)
953 return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
966 unsigned int num_sections;
992 if (strcmp (bfd_sect_name, addrs->
other[i].
name) == 0)
1005 int sect_index = osect - objfile->
sections;;
1007 if (
startswith (bfd_sect_name,
"LC_SEGMENT."))
1008 bfd_sect_name += 11;
1009 if (strcmp (bfd_sect_name,
"__TEXT") == 0
1010 || strcmp (bfd_sect_name,
"__TEXT.__text") == 0)
1038 &mach_o_debug_level,
1039 _(
"Set if printing Mach-O symbols processing."),
1040 _(
"Show if printing Mach-O symbols processing."),
int dwarf2_has_info(struct objfile *objfile, const struct dwarf2_debug_sections *names)
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_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
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)
static void macho_symfile_read_all_oso(VEC(oso_el)**oso_vector_ptr, struct objfile *main_objfile, int symfile_flags)
struct objfile * symbol_file_add_from_bfd(bfd *abfd, const char *name, int add_flags, struct section_addr_info *addrs, int flags, struct objfile *parent)
struct bfd_section * the_bfd_section
#define BMSYMBOL_VALUE_ADDRESS(symbol)
void warning(const char *fmt,...)
static void macho_symtab_read(struct objfile *objfile, long number_of_symbols, asymbol **symbol_table, VEC(oso_el)**oso_vector_ptr)
#define obj_section_offset(s)
initialize_file_ftype _initialize_machoread
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_read(struct objfile *objfile, int symfile_flags)
struct minimal_symbol * prim_record_minimal_symbol_and_info(const char *name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section, struct objfile *objfile)
struct bfd * gdb_bfd_open(const char *name, const char *target, int fd)
static void macho_symfile_finish(struct objfile *objfile)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
struct bfd_hash_entry base
struct obstack objfile_obstack
void null_cleanup(void *arg)
#define SIZEOF_N_SECTION_OFFSETS(n)
#define VEC_iterate(T, V, I, P)
static unsigned int mach_o_debug_level
void gdb_bfd_unref(struct bfd *abfd)
void initialize_file_ftype(void)
void symbol_file_add_separate(bfd *bfd, const char *name, int symfile_flags, struct objfile *objfile)
void complaint(struct complaints **complaints, const char *fmt,...)
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)
static void macho_symtab_add_minsym(struct objfile *objfile, const asymbol *sym)
bfd * gdb_bfd_openr_next_archived_file(bfd *archive, bfd *previous)
static int startswith(const char *string, const char *pattern)
struct cleanup * make_cleanup_discard_minimal_symbols(void)
void printf_unfiltered(const char *format,...)
struct cmd_list_element * setdebuglist
const char * objfile_name(const struct objfile *objfile)
static void macho_new_init(struct objfile *objfile)
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
static bfd * macho_check_dsym(struct objfile *objfile, char **filenamep)
void init_minimal_symbol_collection(void)
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)
struct complaints * symfile_complaints
struct minimal_symbol * minsym
const struct quick_symbol_functions psym_functions
#define VEC_address(T, V)
struct other_sections other[1]
bfd * gdb_bfd_openr(const char *filename, const char *target)
struct cmd_list_element * showdebuglist
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)
static void macho_add_oso_symfile(oso_el *oso, bfd *abfd, const char *name, struct objfile *main_objfile, int symfile_flags)
void install_minimal_symbols(struct objfile *objfile)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
void error(const char *fmt,...)
void do_cleanups(struct cleanup *old_chain)
static void macho_register_oso(VEC(oso_el)**oso_vector_ptr, struct objfile *objfile, asymbol **oso_sym, asymbol **end_sym, unsigned int nbr_syms)