1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 2008-2014 Free Software Foundation, Inc.
4 Contributed by AdaCore.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 #include "gdb_assert.h"
32 #include "aout/stab_gnu.h"
35 #include "complaints.h"
40 /* If non-zero displays debugging message. */
41 static unsigned int mach_o_debug_level = 0;
43 /* Dwarf debugging information are never in the final executable. They stay
44 in object files and the executable contains the list of object files read
46 Each time an oso (other source) is found in the executable, the reader
47 creates such a structure. They are read after the processing of the
52 /* Object file name. Can also be a member name. */
55 /* Associated time stamp. */
58 /* Stab symbols range for this OSO. */
62 /* Number of interesting stabs in the range. */
63 unsigned int nbr_syms;
67 /* Vector of object files to be read after the executable. */
71 macho_new_init (struct objfile *objfile)
76 macho_symfile_init (struct objfile *objfile)
78 objfile->flags |= OBJF_REORDERED;
81 /* Add a new OSO to the vector of OSO to load. */
84 macho_register_oso (VEC (oso_el) **oso_vector_ptr,
85 struct objfile *objfile,
86 asymbol **oso_sym, asymbol **end_sym,
87 unsigned int nbr_syms)
91 el.name = (*oso_sym)->name;
92 el.mtime = (*oso_sym)->value;
95 el.nbr_syms = nbr_syms;
96 VEC_safe_push (oso_el, *oso_vector_ptr, &el);
99 /* Add symbol SYM to the minimal symbol table of OBJFILE. */
102 macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
104 if (sym->name == NULL || *sym->name == '\0')
106 /* Skip names that don't exist (shouldn't happen), or names
107 that are null strings (may happen). */
111 if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
114 enum minimal_symbol_type ms_type;
116 /* Bfd symbols are section relative. */
117 symaddr = sym->value + sym->section->vma;
119 if (sym->section == bfd_abs_section_ptr)
121 else if (sym->section->flags & SEC_CODE)
123 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
126 ms_type = mst_file_text;
128 else if (sym->section->flags & SEC_ALLOC)
130 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
132 if (sym->section->flags & SEC_LOAD)
137 else if (sym->flags & BSF_LOCAL)
139 /* Not a special stabs-in-elf symbol, do regular
140 symbol processing. */
141 if (sym->section->flags & SEC_LOAD)
142 ms_type = mst_file_data;
144 ms_type = mst_file_bss;
147 ms_type = mst_unknown;
150 return; /* Skip this symbol. */
152 prim_record_minimal_symbol_and_info
153 (sym->name, symaddr, ms_type,
154 gdb_bfd_section_index (objfile->obfd, sym->section),
159 /* Build the minimal symbol table from SYMBOL_TABLE of length
160 NUMBER_OF_SYMBOLS for OBJFILE. Registers OSO filenames found. */
163 macho_symtab_read (struct objfile *objfile,
164 long number_of_symbols, asymbol **symbol_table,
165 VEC (oso_el) **oso_vector_ptr)
168 const asymbol *dir_so = NULL;
169 const asymbol *file_so = NULL;
170 asymbol **oso_file = NULL;
171 unsigned int nbr_syms = 0;
173 /* Current state while reading stabs. */
176 /* Not within an SO part. Only non-debugging symbols should be present,
177 and will be added to the minimal symbols table. */
180 /* First SO read. Introduce an SO section, and may be followed by a second
181 SO. The SO section should contain onl debugging symbols. */
184 /* Second non-null SO found, just after the first one. Means that the first
185 is in fact a directory name. */
188 /* Non-null OSO found. Debugging info are DWARF in this OSO file. */
194 for (i = 0; i < number_of_symbols; i++)
196 const asymbol *sym = symbol_table[i];
197 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
202 if (mach_o_sym->n_type == N_SO)
204 /* Start of object stab. */
205 if (sym->name == NULL || sym->name[0] == 0)
207 /* Unexpected empty N_SO. */
208 complaint (&symfile_complaints,
209 _("Unexpected empty N_SO stab"));
218 else if (sym->flags & BSF_DEBUGGING)
220 if (mach_o_sym->n_type == N_OPT)
222 /* No complaint for OPT. */
226 /* Debugging symbols are not expected here. */
227 complaint (&symfile_complaints,
228 _("%s: Unexpected debug stab outside SO markers"),
229 objfile_name (objfile));
233 /* Non-debugging symbols go to the minimal symbol table. */
234 macho_symtab_add_minsym (objfile, sym);
240 if (mach_o_sym->n_type == N_SO)
242 if (sym->name == NULL || sym->name[0] == 0)
244 /* Unexpected empty N_SO. */
245 complaint (&symfile_complaints, _("Empty SO section"));
248 else if (state == S_FIRST_SO)
250 /* Second SO stab for the file name. */
256 complaint (&symfile_complaints, _("Three SO in a raw"));
258 else if (mach_o_sym->n_type == N_OSO)
260 if (sym->name == NULL || sym->name[0] == 0)
262 /* Empty OSO. Means that this file was compiled with
265 warning (_("stabs debugging not supported for %s"),
270 /* Non-empty OSO for a Dwarf file. */
271 oso_file = symbol_table + i;
273 state = S_DWARF_FILE;
277 complaint (&symfile_complaints,
278 _("Unexpected stab after SO"));
283 if (mach_o_sym->n_type == N_SO)
285 if (sym->name == NULL || sym->name[0] == 0)
288 if (state == S_DWARF_FILE)
289 macho_register_oso (oso_vector_ptr, objfile,
290 oso_file, symbol_table + i,
296 complaint (&symfile_complaints, _("Missing nul SO"));
302 else if (sym->flags & BSF_DEBUGGING)
304 if (state == S_STAB_FILE)
306 /* FIXME: to be implemented. */
310 switch (mach_o_sym->n_type)
313 if (sym->name == NULL || sym->name[0] == 0)
317 /* Interesting symbol. */
325 complaint (&symfile_complaints,
326 _("unhandled stab for dwarf OSO file"));
332 complaint (&symfile_complaints,
333 _("non-debugging symbol within SO"));
338 if (state != S_NO_SO)
339 complaint (&symfile_complaints, _("missing nul SO"));
342 /* If NAME describes an archive member (ie: ARCHIVE '(' MEMBER ')'),
343 returns the length of the archive name.
344 Returns -1 otherwise. */
347 get_archive_prefix_len (const char *name)
350 int name_len = strlen (name);
352 if (name_len == 0 || name[name_len - 1] != ')')
355 lparen = strrchr (name, '(');
356 if (lparen == NULL || lparen == name)
358 return lparen - name;
361 /* Compare function to qsort OSOs, so that members of a library are
365 oso_el_compare_name (const void *vl, const void *vr)
367 const oso_el *l = (const oso_el *)vl;
368 const oso_el *r = (const oso_el *)vr;
370 return strcmp (l->name, r->name);
373 /* Hash table entry structure for the stabs symbols in the main object file.
374 This is used to speed up lookup for symbols in the OSO. */
376 struct macho_sym_hash_entry
378 struct bfd_hash_entry base;
382 /* Routine to create an entry in the hash table. */
384 static struct bfd_hash_entry *
385 macho_sym_hash_newfunc (struct bfd_hash_entry *entry,
386 struct bfd_hash_table *table,
389 struct macho_sym_hash_entry *ret = (struct macho_sym_hash_entry *) entry;
391 /* Allocate the structure if it has not already been allocated by a
394 ret = (struct macho_sym_hash_entry *) bfd_hash_allocate (table,
399 /* Call the allocation method of the superclass. */
400 ret = (struct macho_sym_hash_entry *)
401 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string);
405 /* Initialize the local fields. */
409 return (struct bfd_hash_entry *) ret;
412 /* Get the value of SYM from the minimal symtab of MAIN_OBJFILE. This is used
413 to get the value of global and common symbols. */
416 macho_resolve_oso_sym_with_minsym (struct objfile *main_objfile, asymbol *sym)
418 /* For common symbol and global symbols, use the min symtab. */
419 struct bound_minimal_symbol msym;
420 const char *name = sym->name;
422 if (name[0] == bfd_get_symbol_leading_char (main_objfile->obfd))
424 msym = lookup_minimal_symbol (name, NULL, main_objfile);
425 if (msym.minsym == NULL)
427 warning (_("can't find symbol '%s' in minsymtab"), name);
431 return BMSYMBOL_VALUE_ADDRESS (msym);
434 /* Add oso file OSO/ABFD as a symbol file. */
437 macho_add_oso_symfile (oso_el *oso, bfd *abfd, const char *name,
438 struct objfile *main_objfile, int symfile_flags)
442 asymbol **symbol_table;
444 struct bfd_hash_table table;
446 struct cleanup *cleanup;
448 /* Per section flag to mark which section have been rebased. */
449 unsigned char *sections_rebased;
451 if (mach_o_debug_level > 0)
453 (_("Loading debugging symbols from oso: %s\n"), oso->name);
455 if (!bfd_check_format (abfd, bfd_object))
457 warning (_("`%s': can't read symbols: %s."), oso->name,
458 bfd_errmsg (bfd_get_error ()));
459 gdb_bfd_unref (abfd);
463 if (abfd->my_archive == NULL && oso->mtime != bfd_get_mtime (abfd))
465 warning (_("`%s': file time stamp mismatch."), oso->name);
466 gdb_bfd_unref (abfd);
470 if (!bfd_hash_table_init_n (&table, macho_sym_hash_newfunc,
471 sizeof (struct macho_sym_hash_entry),
474 warning (_("`%s': can't create hash table"), oso->name);
475 gdb_bfd_unref (abfd);
479 bfd_set_cacheable (abfd, 1);
481 /* Read symbols table. */
482 storage = bfd_get_symtab_upper_bound (abfd);
483 symbol_table = (asymbol **) xmalloc (storage);
484 bfd_canonicalize_symtab (abfd, symbol_table);
486 /* Init section flags. */
487 nbr_sections = bfd_count_sections (abfd);
488 sections_rebased = (unsigned char *) alloca (nbr_sections);
489 for (i = 0; i < nbr_sections; i++)
490 sections_rebased[i] = 0;
492 /* Put symbols for the OSO file in the hash table. */
493 for (symp = oso->oso_sym; symp != oso->end_sym; symp++)
495 const asymbol *sym = *symp;
496 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
498 switch (mach_o_sym->n_type)
506 if (sym->name == NULL || sym->name[0] == 0)
517 struct macho_sym_hash_entry *ent;
519 ent = (struct macho_sym_hash_entry *)
520 bfd_hash_lookup (&table, sym->name, TRUE, FALSE);
521 if (ent->sym != NULL)
522 complaint (&symfile_complaints,
523 _("Duplicated symbol %s in symbol table"), sym->name);
526 if (mach_o_debug_level > 4)
528 struct gdbarch *arch = get_objfile_arch (main_objfile);
530 (_("Adding symbol %s (addr: %s)\n"),
531 sym->name, paddress (arch, sym->value));
538 /* Relocate symbols of the OSO. */
539 for (i = 0; symbol_table[i]; i++)
541 asymbol *sym = symbol_table[i];
542 bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
544 if (mach_o_sym->n_type & BFD_MACH_O_N_STAB)
546 if ((mach_o_sym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_UNDF
549 /* For common symbol use the min symtab and modify the OSO
553 res = macho_resolve_oso_sym_with_minsym (main_objfile, sym);
556 sym->section = bfd_com_section_ptr;
560 else if ((mach_o_sym->n_type & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_SECT)
563 asection *sec = sym->section;
564 bfd_mach_o_section *msec;
565 unsigned int sec_type;
567 /* Skip buggy ones. */
568 if (sec == NULL || sections_rebased[sec->index] != 0)
571 /* Only consider regular, non-debugging sections. */
572 msec = bfd_mach_o_get_mach_o_section (sec);
573 sec_type = msec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
574 if ((sec_type == BFD_MACH_O_S_REGULAR
575 || sec_type == BFD_MACH_O_S_ZEROFILL)
576 && (msec->flags & BFD_MACH_O_S_ATTR_DEBUG) == 0)
580 if ((mach_o_sym->n_type & BFD_MACH_O_N_EXT) != 0)
582 /* Use the min symtab for global symbols. */
583 addr = macho_resolve_oso_sym_with_minsym (main_objfile, sym);
587 struct macho_sym_hash_entry *ent;
589 ent = (struct macho_sym_hash_entry *)
590 bfd_hash_lookup (&table, sym->name, FALSE, FALSE);
592 addr = bfd_asymbol_value (ent->sym);
595 /* Adjust the section. */
598 CORE_ADDR res = addr - sym->value;
600 if (mach_o_debug_level > 3)
602 struct gdbarch *arch = get_objfile_arch (main_objfile);
604 (_("resolve sect %s with %s (set to %s)\n"),
605 sec->name, sym->name,
606 paddress (arch, res));
608 bfd_set_section_vma (abfd, sec, res);
609 sections_rebased[sec->index] = 1;
614 /* Mark the section as never rebased. */
615 sections_rebased[sec->index] = 2;
620 bfd_hash_table_free (&table);
622 /* We need to clear SYMFILE_MAINLINE to avoid interractive question
623 from symfile.c:symbol_file_add_with_addrs_or_offsets. */
624 cleanup = make_cleanup_bfd_unref (abfd);
625 symbol_file_add_from_bfd
626 (abfd, name, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
627 main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
628 | OBJF_READNOW | OBJF_USERLOADED),
630 do_cleanups (cleanup);
633 /* Read symbols from the vector of oso files.
635 Note that this function sorts OSO_VECTOR_PTR. */
638 macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
639 struct objfile *main_objfile,
643 VEC (oso_el) *vec = *oso_vector_ptr;
645 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
647 /* Sort oso by name so that files from libraries are gathered. */
648 qsort (VEC_address (oso_el, vec), VEC_length (oso_el, vec),
649 sizeof (oso_el), oso_el_compare_name);
651 for (ix = 0; VEC_iterate (oso_el, vec, ix, oso);)
655 /* Check if this is a library name. */
656 pfx_len = get_archive_prefix_len (oso->name);
661 char *archive_name = XNEWVEC (char, pfx_len + 1);
666 memcpy (archive_name, oso->name, pfx_len);
667 archive_name[pfx_len] = '\0';
669 make_cleanup (xfree, archive_name);
671 /* Compute number of oso for this archive. */
673 VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++)
675 if (strncmp (oso2->name, archive_name, pfx_len) != 0)
679 /* Open the archive and check the format. */
680 archive_bfd = gdb_bfd_open (archive_name, gnutarget, -1);
681 if (archive_bfd == NULL)
683 warning (_("Could not open OSO archive file \"%s\""),
688 if (!bfd_check_format (archive_bfd, bfd_archive))
690 warning (_("OSO archive file \"%s\" not an archive."),
692 gdb_bfd_unref (archive_bfd);
697 member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd, NULL);
699 if (member_bfd == NULL)
701 warning (_("Could not read archive members out of "
702 "OSO archive \"%s\""), archive_name);
703 gdb_bfd_unref (archive_bfd);
708 /* Load all oso in this library. */
709 while (member_bfd != NULL)
712 const char *member_name = member_bfd->filename;
713 int member_len = strlen (member_name);
715 /* If this member is referenced, add it as a symfile. */
716 for (ix2 = ix; ix2 < last_ix; ix2++)
718 oso2 = VEC_index (oso_el, vec, ix2);
721 && strlen (oso2->name) == pfx_len + member_len + 2
722 && !memcmp (member_name, oso2->name + pfx_len + 1,
725 macho_add_oso_symfile (oso2, member_bfd,
726 bfd_get_filename (member_bfd),
727 main_objfile, symfile_flags);
734 member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd,
737 /* Free previous member if not referenced by an oso. */
739 gdb_bfd_unref (prev);
741 for (ix2 = ix; ix2 < last_ix; ix2++)
743 oso_el *oso2 = VEC_index (oso_el, vec, ix2);
745 if (oso2->name != NULL)
746 warning (_("Could not find specified archive member "
747 "for OSO name \"%s\""), oso->name);
755 abfd = gdb_bfd_open (oso->name, gnutarget, -1);
757 warning (_("`%s': can't open to read symbols: %s."), oso->name,
758 bfd_errmsg (bfd_get_error ()));
760 macho_add_oso_symfile (oso, abfd, oso->name, main_objfile,
767 do_cleanups (cleanup);
770 /* DSYM (debug symbols) files contain the debug info of an executable.
771 This is a separate file created by dsymutil(1) and is similar to debug
773 DSYM files are located in a subdirectory. Append DSYM_SUFFIX to the
774 executable name and the executable base name to get the DSYM file name. */
775 #define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/"
777 /* Check if a dsym file exists for OBJFILE. If so, returns a bfd for it
778 and return *FILENAMEP with its original xmalloc-ated filename.
779 Return NULL if no valid dsym file is found (FILENAMEP is not used in
783 macho_check_dsym (struct objfile *objfile, char **filenamep)
785 size_t name_len = strlen (objfile_name (objfile));
786 size_t dsym_len = strlen (DSYM_SUFFIX);
787 const char *base_name = lbasename (objfile_name (objfile));
788 size_t base_len = strlen (base_name);
789 char *dsym_filename = alloca (name_len + dsym_len + base_len + 1);
791 bfd_mach_o_load_command *main_uuid;
792 bfd_mach_o_load_command *dsym_uuid;
794 strcpy (dsym_filename, objfile_name (objfile));
795 strcpy (dsym_filename + name_len, DSYM_SUFFIX);
796 strcpy (dsym_filename + name_len + dsym_len, base_name);
798 if (access (dsym_filename, R_OK) != 0)
801 if (bfd_mach_o_lookup_command (objfile->obfd,
802 BFD_MACH_O_LC_UUID, &main_uuid) == 0)
804 warning (_("can't find UUID in %s"), objfile_name (objfile));
807 dsym_bfd = gdb_bfd_openr (dsym_filename, gnutarget);
808 if (dsym_bfd == NULL)
810 warning (_("can't open dsym file %s"), dsym_filename);
814 if (!bfd_check_format (dsym_bfd, bfd_object))
816 gdb_bfd_unref (dsym_bfd);
817 warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
821 if (bfd_mach_o_lookup_command (dsym_bfd,
822 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
824 warning (_("can't find UUID in %s"), dsym_filename);
825 gdb_bfd_unref (dsym_bfd);
828 if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
829 sizeof (main_uuid->command.uuid.uuid)))
831 warning (_("dsym file UUID doesn't match the one in %s"),
832 objfile_name (objfile));
833 gdb_bfd_unref (dsym_bfd);
836 *filenamep = xstrdup (dsym_filename);
841 macho_symfile_read (struct objfile *objfile, int symfile_flags)
843 bfd *abfd = objfile->obfd;
847 VEC (oso_el) *oso_vector = NULL;
848 struct cleanup *old_chain = make_cleanup (VEC_cleanup (oso_el), &oso_vector);
850 /* Get symbols from the symbol table only if the file is an executable.
851 The symbol table of object files is not relocated and is expected to
852 be in the executable. */
853 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
857 /* Process the normal symbol table first. */
858 storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
859 if (storage_needed < 0)
860 error (_("Can't read symbols from %s: %s"),
861 bfd_get_filename (objfile->obfd),
862 bfd_errmsg (bfd_get_error ()));
864 if (storage_needed > 0)
866 asymbol **symbol_table;
869 symbol_table = (asymbol **) xmalloc (storage_needed);
870 make_cleanup (xfree, symbol_table);
872 init_minimal_symbol_collection ();
873 make_cleanup_discard_minimal_symbols ();
875 symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
878 error (_("Can't read symbols from %s: %s"),
879 bfd_get_filename (objfile->obfd),
880 bfd_errmsg (bfd_get_error ()));
882 macho_symtab_read (objfile, symcount, symbol_table, &oso_vector);
884 install_minimal_symbols (objfile);
887 /* Try to read .eh_frame / .debug_frame. */
888 /* First, locate these sections. We ignore the result status
889 as it only checks for debug info. */
890 dwarf2_has_info (objfile, NULL);
891 dwarf2_build_frame_info (objfile);
893 /* Check for DSYM file. */
894 dsym_bfd = macho_check_dsym (objfile, &dsym_filename);
895 if (dsym_bfd != NULL)
899 struct bfd_section *asect, *dsect;
901 make_cleanup (xfree, dsym_filename);
903 if (mach_o_debug_level > 0)
904 printf_unfiltered (_("dsym file found\n"));
906 /* Set dsym section size. */
907 for (asect = objfile->obfd->sections, dsect = dsym_bfd->sections;
909 asect = asect->next, dsect = dsect->next)
911 if (strcmp (asect->name, dsect->name) != 0)
913 bfd_set_section_size (dsym_bfd, dsect,
914 bfd_get_section_size (asect));
917 /* Add the dsym file as a separate file. */
918 make_cleanup_bfd_unref (dsym_bfd);
919 symbol_file_add_separate (dsym_bfd, dsym_filename, symfile_flags,
922 /* Don't try to read dwarf2 from main file or shared libraries. */
923 do_cleanups (old_chain);
928 if (dwarf2_has_info (objfile, NULL))
930 /* DWARF 2 sections */
931 dwarf2_build_psymtabs (objfile);
935 if (oso_vector != NULL)
936 macho_symfile_read_all_oso (&oso_vector, objfile, symfile_flags);
938 do_cleanups (old_chain);
942 macho_symfile_relocate (struct objfile *objfile, asection *sectp,
945 bfd *abfd = objfile->obfd;
947 /* We're only interested in sections with relocation
949 if ((sectp->flags & SEC_RELOC) == 0)
952 if (mach_o_debug_level > 0)
953 printf_unfiltered (_("Relocate section '%s' of %s\n"),
954 sectp->name, objfile_name (objfile));
956 return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
960 macho_symfile_finish (struct objfile *objfile)
965 macho_symfile_offsets (struct objfile *objfile,
966 const struct section_addr_info *addrs)
969 unsigned int num_sections;
970 struct obj_section *osect;
972 /* Allocate section_offsets. */
973 objfile->num_sections = bfd_count_sections (objfile->obfd);
974 objfile->section_offsets = (struct section_offsets *)
975 obstack_alloc (&objfile->objfile_obstack,
976 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
977 memset (objfile->section_offsets, 0,
978 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
980 /* This code is run when we first add the objfile with
981 symfile_add_with_addrs_or_offsets, when "addrs" not "offsets" are
982 passed in. The place in symfile.c where the addrs are applied
983 depends on the addrs having section names. But in the dyld code
984 we build an anonymous array of addrs, so that code is a no-op.
985 Because of that, we have to apply the addrs to the sections here.
986 N.B. if an objfile slides after we've already created it, then it
987 goes through objfile_relocate. */
989 for (i = 0; i < addrs->num_sections; i++)
991 ALL_OBJFILE_OSECTIONS (objfile, osect)
993 const char *bfd_sect_name = osect->the_bfd_section->name;
995 if (strcmp (bfd_sect_name, addrs->other[i].name) == 0)
997 obj_section_offset (osect) = addrs->other[i].addr;
1003 objfile->sect_index_text = 0;
1005 ALL_OBJFILE_OSECTIONS (objfile, osect)
1007 const char *bfd_sect_name = osect->the_bfd_section->name;
1008 int sect_index = osect - objfile->sections;;
1010 if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
1011 bfd_sect_name += 11;
1012 if (strcmp (bfd_sect_name, "__TEXT") == 0
1013 || strcmp (bfd_sect_name, "__TEXT.__text") == 0)
1014 objfile->sect_index_text = sect_index;
1018 static const struct sym_fns macho_sym_fns = {
1019 macho_new_init, /* init anything gbl to entire symtab */
1020 macho_symfile_init, /* read initial info, setup for sym_read() */
1021 macho_symfile_read, /* read a symbol file into symtab */
1022 NULL, /* sym_read_psymbols */
1023 macho_symfile_finish, /* finished with file, cleanup */
1024 macho_symfile_offsets, /* xlate external to internal form */
1025 default_symfile_segments, /* Get segment information from a file. */
1027 macho_symfile_relocate, /* Relocate a debug section. */
1028 NULL, /* sym_get_probes */
1032 /* -Wmissing-prototypes */
1033 extern initialize_file_ftype _initialize_machoread;
1036 _initialize_machoread (void)
1038 add_symtab_fns (bfd_target_mach_o_flavour, &macho_sym_fns);
1040 add_setshow_zuinteger_cmd ("mach-o", class_obscure,
1041 &mach_o_debug_level,
1042 _("Set if printing Mach-O symbols processing."),
1043 _("Show if printing Mach-O symbols processing."),
1045 &setdebuglist, &showdebuglist);