1 /* Darwin support for GDB, the GNU debugger.
2 Copyright (C) 2008-2023 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/>. */
30 #include "aout/stab_gnu.h"
31 #include "complaints.h"
35 #include "dwarf2/public.h"
37 /* If non-zero displays debugging message. */
38 static unsigned int mach_o_debug_level
= 0;
40 #define macho_debug(LEVEL, FMT, ...) \
41 debug_prefixed_printf_cond_nofunc (mach_o_debug_level > LEVEL, \
42 "machoread", FMT, ## __VA_ARGS__)
44 /* Dwarf debugging information are never in the final executable. They stay
45 in object files and the executable contains the list of object files read
47 Each time an oso (other source) is found in the executable, the reader
48 creates such a structure. They are read after the processing of the
53 oso_el (asymbol
**oso_sym_
, asymbol
**end_sym_
, unsigned int nbr_syms_
)
54 : name((*oso_sym_
)->name
),
55 mtime((*oso_sym_
)->value
),
62 /* Object file name. Can also be a member name. */
65 /* Associated time stamp. */
68 /* Stab symbols range for this OSO. */
72 /* Number of interesting stabs in the range. */
73 unsigned int nbr_syms
;
77 macho_new_init (struct objfile
*objfile
)
82 macho_symfile_init (struct objfile
*objfile
)
86 /* Add symbol SYM to the minimal symbol table of OBJFILE. */
89 macho_symtab_add_minsym (minimal_symbol_reader
&reader
,
90 struct objfile
*objfile
, const asymbol
*sym
)
92 if (sym
->name
== NULL
|| *sym
->name
== '\0')
94 /* Skip names that don't exist (shouldn't happen), or names
95 that are null strings (may happen). */
99 if (sym
->flags
& (BSF_GLOBAL
| BSF_LOCAL
| BSF_WEAK
))
101 unrelocated_addr symaddr
;
102 enum minimal_symbol_type ms_type
;
104 /* Bfd symbols are section relative. */
105 symaddr
= unrelocated_addr (sym
->value
+ sym
->section
->vma
);
107 if (sym
->section
== bfd_abs_section_ptr
)
109 else if (sym
->section
->flags
& SEC_CODE
)
111 if (sym
->flags
& (BSF_GLOBAL
| BSF_WEAK
))
114 ms_type
= mst_file_text
;
116 else if (sym
->section
->flags
& SEC_ALLOC
)
118 if (sym
->flags
& (BSF_GLOBAL
| BSF_WEAK
))
120 if (sym
->section
->flags
& SEC_LOAD
)
125 else if (sym
->flags
& BSF_LOCAL
)
127 /* Not a special stabs-in-elf symbol, do regular
128 symbol processing. */
129 if (sym
->section
->flags
& SEC_LOAD
)
130 ms_type
= mst_file_data
;
132 ms_type
= mst_file_bss
;
135 ms_type
= mst_unknown
;
138 return; /* Skip this symbol. */
140 reader
.record_with_info (sym
->name
, symaddr
, ms_type
,
141 gdb_bfd_section_index (objfile
->obfd
.get (),
146 /* Build the minimal symbol table from SYMBOL_TABLE of length
147 NUMBER_OF_SYMBOLS for OBJFILE. Registers OSO filenames found. */
150 macho_symtab_read (minimal_symbol_reader
&reader
,
151 struct objfile
*objfile
,
152 long number_of_symbols
, asymbol
**symbol_table
,
153 std::vector
<oso_el
> *oso_vector_ptr
)
156 const asymbol
*file_so
= NULL
;
157 asymbol
**oso_file
= NULL
;
158 unsigned int nbr_syms
= 0;
160 /* Current state while reading stabs. */
163 /* Not within an SO part. Only non-debugging symbols should be present,
164 and will be added to the minimal symbols table. */
167 /* First SO read. Introduce an SO section, and may be followed by a second
168 SO. The SO section should contain onl debugging symbols. */
171 /* Second non-null SO found, just after the first one. Means that the first
172 is in fact a directory name. */
175 /* Non-null OSO found. Debugging info are DWARF in this OSO file. */
181 for (i
= 0; i
< number_of_symbols
; i
++)
183 const asymbol
*sym
= symbol_table
[i
];
184 bfd_mach_o_asymbol
*mach_o_sym
= (bfd_mach_o_asymbol
*)sym
;
189 if (mach_o_sym
->n_type
== N_SO
)
191 /* Start of object stab. */
192 if (sym
->name
== NULL
|| sym
->name
[0] == 0)
194 /* Unexpected empty N_SO. */
195 complaint (_("Unexpected empty N_SO stab"));
203 else if (sym
->flags
& BSF_DEBUGGING
)
205 if (mach_o_sym
->n_type
== N_OPT
)
207 /* No complaint for OPT. */
211 /* Debugging symbols are not expected here. */
212 complaint (_("%s: Unexpected debug stab outside SO markers"),
213 objfile_name (objfile
));
217 /* Non-debugging symbols go to the minimal symbol table. */
218 macho_symtab_add_minsym (reader
, objfile
, sym
);
224 if (mach_o_sym
->n_type
== N_SO
)
226 if (sym
->name
== NULL
|| sym
->name
[0] == 0)
228 /* Unexpected empty N_SO. */
229 complaint (_("Empty SO section"));
232 else if (state
== S_FIRST_SO
)
234 /* Second SO stab for the file name. */
239 complaint (_("Three SO in a raw"));
241 else if (mach_o_sym
->n_type
== N_OSO
)
243 if (sym
->name
== NULL
|| sym
->name
[0] == 0)
245 /* Empty OSO. Means that this file was compiled with
248 warning (_("stabs debugging not supported for %s"),
253 /* Non-empty OSO for a Dwarf file. */
254 oso_file
= symbol_table
+ i
;
256 state
= S_DWARF_FILE
;
260 complaint (_("Unexpected stab after SO"));
265 if (mach_o_sym
->n_type
== N_SO
)
267 if (sym
->name
== NULL
|| sym
->name
[0] == 0)
270 if (state
== S_DWARF_FILE
)
271 oso_vector_ptr
->emplace_back (oso_file
, symbol_table
+ i
,
277 complaint (_("Missing nul SO"));
282 else if (sym
->flags
& BSF_DEBUGGING
)
284 if (state
== S_STAB_FILE
)
286 /* FIXME: to be implemented. */
290 switch (mach_o_sym
->n_type
)
293 if (sym
->name
== NULL
|| sym
->name
[0] == 0)
297 /* Interesting symbol. */
305 complaint (_("unhandled stab for dwarf OSO file"));
311 complaint (_("non-debugging symbol within SO"));
316 if (state
!= S_NO_SO
)
317 complaint (_("missing nul SO"));
320 /* If NAME describes an archive member (ie: ARCHIVE '(' MEMBER ')'),
321 returns the length of the archive name.
322 Returns -1 otherwise. */
325 get_archive_prefix_len (const char *name
)
328 int name_len
= strlen (name
);
330 if (name_len
== 0 || name
[name_len
- 1] != ')')
333 lparen
= strrchr (name
, '(');
334 if (lparen
== NULL
|| lparen
== name
)
336 return lparen
- name
;
339 /* Compare function to std::sort OSOs, so that members of a library
343 oso_el_compare_name (const oso_el
&l
, const oso_el
&r
)
345 return strcmp (l
.name
, r
.name
) < 0;
348 /* Hash table entry structure for the stabs symbols in the main object file.
349 This is used to speed up lookup for symbols in the OSO. */
351 struct macho_sym_hash_entry
353 struct bfd_hash_entry base
;
357 /* Routine to create an entry in the hash table. */
359 static struct bfd_hash_entry
*
360 macho_sym_hash_newfunc (struct bfd_hash_entry
*entry
,
361 struct bfd_hash_table
*table
,
364 struct macho_sym_hash_entry
*ret
= (struct macho_sym_hash_entry
*) entry
;
366 /* Allocate the structure if it has not already been allocated by a
369 ret
= (struct macho_sym_hash_entry
*) bfd_hash_allocate (table
,
374 /* Call the allocation method of the superclass. */
375 ret
= (struct macho_sym_hash_entry
*)
376 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
);
380 /* Initialize the local fields. */
384 return (struct bfd_hash_entry
*) ret
;
387 /* Get the value of SYM from the minimal symtab of MAIN_OBJFILE. This is used
388 to get the value of global and common symbols. */
391 macho_resolve_oso_sym_with_minsym (struct objfile
*main_objfile
, asymbol
*sym
)
393 /* For common symbol and global symbols, use the min symtab. */
394 struct bound_minimal_symbol msym
;
395 const char *name
= sym
->name
;
398 && *name
== bfd_get_symbol_leading_char (main_objfile
->obfd
.get ()))
400 msym
= lookup_minimal_symbol (name
, NULL
, main_objfile
);
401 if (msym
.minsym
== NULL
)
403 warning (_("can't find symbol '%s' in minsymtab"), name
);
407 return msym
.value_address ();
410 /* Add oso file OSO/ABFD as a symbol file. */
413 macho_add_oso_symfile (oso_el
*oso
, const gdb_bfd_ref_ptr
&abfd
,
415 struct objfile
*main_objfile
,
416 symfile_add_flags symfile_flags
)
420 asymbol
**symbol_table
;
422 struct bfd_hash_table table
;
425 /* Per section flag to mark which section have been rebased. */
426 unsigned char *sections_rebased
;
428 macho_debug (0, _("Loading debugging symbols from oso: %s\n"), oso
->name
);
430 if (!bfd_check_format (abfd
.get (), bfd_object
))
432 warning (_("`%s': can't read symbols: %s."), oso
->name
,
433 bfd_errmsg (bfd_get_error ()));
437 if (abfd
->my_archive
== NULL
&& oso
->mtime
!= bfd_get_mtime (abfd
.get ()))
439 warning (_("`%s': file time stamp mismatch."), oso
->name
);
443 if (!bfd_hash_table_init_n (&table
, macho_sym_hash_newfunc
,
444 sizeof (struct macho_sym_hash_entry
),
447 warning (_("`%s': can't create hash table"), oso
->name
);
451 /* Read symbols table. */
452 storage
= bfd_get_symtab_upper_bound (abfd
.get ());
453 symbol_table
= (asymbol
**) xmalloc (storage
);
454 bfd_canonicalize_symtab (abfd
.get (), symbol_table
);
456 /* Init section flags. */
457 nbr_sections
= bfd_count_sections (abfd
.get ());
458 sections_rebased
= (unsigned char *) alloca (nbr_sections
);
459 for (i
= 0; i
< nbr_sections
; i
++)
460 sections_rebased
[i
] = 0;
462 /* Put symbols for the OSO file in the hash table. */
463 for (symp
= oso
->oso_sym
; symp
!= oso
->end_sym
; symp
++)
465 const asymbol
*sym
= *symp
;
466 bfd_mach_o_asymbol
*mach_o_sym
= (bfd_mach_o_asymbol
*)sym
;
468 switch (mach_o_sym
->n_type
)
476 if (sym
->name
== NULL
|| sym
->name
[0] == 0)
487 struct macho_sym_hash_entry
*ent
;
489 ent
= (struct macho_sym_hash_entry
*)
490 bfd_hash_lookup (&table
, sym
->name
, TRUE
, FALSE
);
491 if (ent
->sym
!= NULL
)
492 complaint (_("Duplicated symbol %s in symbol table"), sym
->name
);
495 macho_debug (4, _("Adding symbol %s (addr: %s)\n"),
496 sym
->name
, paddress (main_objfile
->arch (),
503 /* Relocate symbols of the OSO. */
504 for (i
= 0; symbol_table
[i
]; i
++)
506 asymbol
*sym
= symbol_table
[i
];
507 bfd_mach_o_asymbol
*mach_o_sym
= (bfd_mach_o_asymbol
*)sym
;
509 if (mach_o_sym
->n_type
& BFD_MACH_O_N_STAB
)
511 if ((mach_o_sym
->n_type
& BFD_MACH_O_N_TYPE
) == BFD_MACH_O_N_UNDF
514 /* For common symbol use the min symtab and modify the OSO
518 res
= macho_resolve_oso_sym_with_minsym (main_objfile
, sym
);
521 sym
->section
= bfd_com_section_ptr
;
525 else if ((mach_o_sym
->n_type
& BFD_MACH_O_N_TYPE
) == BFD_MACH_O_N_SECT
)
528 asection
*sec
= sym
->section
;
529 bfd_mach_o_section
*msec
;
530 unsigned int sec_type
;
532 /* Skip buggy ones. */
533 if (sec
== NULL
|| sections_rebased
[sec
->index
] != 0)
536 /* Only consider regular, non-debugging sections. */
537 msec
= bfd_mach_o_get_mach_o_section (sec
);
538 sec_type
= msec
->flags
& BFD_MACH_O_SECTION_TYPE_MASK
;
539 if ((sec_type
== BFD_MACH_O_S_REGULAR
540 || sec_type
== BFD_MACH_O_S_ZEROFILL
)
541 && (msec
->flags
& BFD_MACH_O_S_ATTR_DEBUG
) == 0)
545 if ((mach_o_sym
->n_type
& BFD_MACH_O_N_EXT
) != 0)
547 /* Use the min symtab for global symbols. */
548 addr
= macho_resolve_oso_sym_with_minsym (main_objfile
, sym
);
552 struct macho_sym_hash_entry
*ent
;
554 ent
= (struct macho_sym_hash_entry
*)
555 bfd_hash_lookup (&table
, sym
->name
, FALSE
, FALSE
);
557 addr
= bfd_asymbol_value (ent
->sym
);
560 /* Adjust the section. */
563 CORE_ADDR res
= addr
- sym
->value
;
565 macho_debug (3, _("resolve sect %s with %s (set to %s)\n"),
566 sec
->name
, sym
->name
,
567 paddress (main_objfile
->arch (), res
));
568 bfd_set_section_vma (sec
, res
);
569 sections_rebased
[sec
->index
] = 1;
574 /* Mark the section as never rebased. */
575 sections_rebased
[sec
->index
] = 2;
580 bfd_hash_table_free (&table
);
582 /* We need to clear SYMFILE_MAINLINE to avoid interactive question
583 from symfile.c:symbol_file_add_with_addrs_or_offsets. */
584 symbol_file_add_from_bfd
585 (abfd
, name
, symfile_flags
& ~(SYMFILE_MAINLINE
| SYMFILE_VERBOSE
),
587 main_objfile
->flags
& (OBJF_SHARED
| OBJF_READNOW
| OBJF_USERLOADED
),
591 /* Read symbols from the vector of oso files.
593 Note that this function sorts OSO_VECTOR_PTR. */
596 macho_symfile_read_all_oso (std::vector
<oso_el
> *oso_vector_ptr
,
597 struct objfile
*main_objfile
,
598 symfile_add_flags symfile_flags
)
603 /* Sort oso by name so that files from libraries are gathered. */
604 std::sort (oso_vector_ptr
->begin (), oso_vector_ptr
->end (),
605 oso_el_compare_name
);
607 for (ix
= 0; ix
< oso_vector_ptr
->size ();)
611 oso
= &(*oso_vector_ptr
)[ix
];
613 /* Check if this is a library name. */
614 pfx_len
= get_archive_prefix_len (oso
->name
);
621 std::string
archive_name (oso
->name
, pfx_len
);
623 /* Compute number of oso for this archive. */
624 for (last_ix
= ix
; last_ix
< oso_vector_ptr
->size (); last_ix
++)
626 oso2
= &(*oso_vector_ptr
)[last_ix
];
627 if (strncmp (oso2
->name
, archive_name
.c_str (), pfx_len
) != 0)
631 /* Open the archive and check the format. */
632 gdb_bfd_ref_ptr
archive_bfd (gdb_bfd_open (archive_name
.c_str (),
634 if (archive_bfd
== NULL
)
636 warning (_("Could not open OSO archive file \"%s\""),
637 archive_name
.c_str ());
641 if (!bfd_check_format (archive_bfd
.get (), bfd_archive
))
643 warning (_("OSO archive file \"%s\" not an archive."),
644 archive_name
.c_str ());
649 gdb_bfd_ref_ptr member_bfd
650 (gdb_bfd_openr_next_archived_file (archive_bfd
.get (), NULL
));
652 if (member_bfd
== NULL
)
654 warning (_("Could not read archive members out of "
655 "OSO archive \"%s\""), archive_name
.c_str ());
660 /* Load all oso in this library. */
661 while (member_bfd
!= NULL
)
663 const char *member_name
= bfd_get_filename (member_bfd
.get ());
664 int member_len
= strlen (member_name
);
666 /* If this member is referenced, add it as a symfile. */
667 for (ix2
= ix
; ix2
< last_ix
; ix2
++)
669 oso2
= &(*oso_vector_ptr
)[ix2
];
672 && strlen (oso2
->name
) == pfx_len
+ member_len
+ 2
673 && !memcmp (member_name
, oso2
->name
+ pfx_len
+ 1,
676 macho_add_oso_symfile (oso2
, member_bfd
,
677 bfd_get_filename (member_bfd
.get ()),
678 main_objfile
, symfile_flags
);
684 member_bfd
= gdb_bfd_openr_next_archived_file (archive_bfd
.get (),
687 for (ix2
= ix
; ix2
< last_ix
; ix2
++)
689 oso2
= &(*oso_vector_ptr
)[ix2
];
691 if (oso2
->name
!= NULL
)
692 warning (_("Could not find specified archive member "
693 "for OSO name \"%s\""), oso
->name
);
699 gdb_bfd_ref_ptr
abfd (gdb_bfd_open (oso
->name
, gnutarget
));
701 warning (_("`%s': can't open to read symbols: %s."), oso
->name
,
702 bfd_errmsg (bfd_get_error ()));
704 macho_add_oso_symfile (oso
, abfd
, oso
->name
, main_objfile
,
712 /* DSYM (debug symbols) files contain the debug info of an executable.
713 This is a separate file created by dsymutil(1) and is similar to debug
715 DSYM files are located in a subdirectory. Append DSYM_SUFFIX to the
716 executable name and the executable base name to get the DSYM file name. */
717 #define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/"
719 /* Check if a dsym file exists for OBJFILE. If so, returns a bfd for it
720 and return *FILENAMEP with its original filename.
721 Return NULL if no valid dsym file is found (FILENAMEP is not used in
724 static gdb_bfd_ref_ptr
725 macho_check_dsym (struct objfile
*objfile
, std::string
*filenamep
)
727 size_t name_len
= strlen (objfile_name (objfile
));
728 size_t dsym_len
= strlen (DSYM_SUFFIX
);
729 const char *base_name
= lbasename (objfile_name (objfile
));
730 size_t base_len
= strlen (base_name
);
731 char *dsym_filename
= (char *) alloca (name_len
+ dsym_len
+ base_len
+ 1);
732 bfd_mach_o_load_command
*main_uuid
;
733 bfd_mach_o_load_command
*dsym_uuid
;
735 strcpy (dsym_filename
, objfile_name (objfile
));
736 strcpy (dsym_filename
+ name_len
, DSYM_SUFFIX
);
737 strcpy (dsym_filename
+ name_len
+ dsym_len
, base_name
);
739 if (access (dsym_filename
, R_OK
) != 0)
742 if (bfd_mach_o_lookup_command (objfile
->obfd
.get (),
743 BFD_MACH_O_LC_UUID
, &main_uuid
) == 0)
745 warning (_("can't find UUID in %s"), objfile_name (objfile
));
748 gdb_bfd_ref_ptr
dsym_bfd (gdb_bfd_openr (dsym_filename
, gnutarget
));
749 if (dsym_bfd
== NULL
)
751 warning (_("can't open dsym file %s"), dsym_filename
);
755 if (!bfd_check_format (dsym_bfd
.get (), bfd_object
))
757 warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
761 if (bfd_mach_o_lookup_command (dsym_bfd
.get (),
762 BFD_MACH_O_LC_UUID
, &dsym_uuid
) == 0)
764 warning (_("can't find UUID in %s"), dsym_filename
);
767 if (memcmp (dsym_uuid
->command
.uuid
.uuid
, main_uuid
->command
.uuid
.uuid
,
768 sizeof (main_uuid
->command
.uuid
.uuid
)))
770 warning (_("dsym file UUID doesn't match the one in %s"),
771 objfile_name (objfile
));
774 *filenamep
= std::string (dsym_filename
);
779 macho_symfile_read (struct objfile
*objfile
, symfile_add_flags symfile_flags
)
781 bfd
*abfd
= objfile
->obfd
.get ();
783 std::vector
<oso_el
> oso_vector
;
784 /* We have to hold on to the symbol table until the call to
785 macho_symfile_read_all_oso at the end of this function. */
786 gdb::def_vector
<asymbol
*> symbol_table
;
788 /* Get symbols from the symbol table only if the file is an executable.
789 The symbol table of object files is not relocated and is expected to
790 be in the executable. */
791 if (bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
793 std::string dsym_filename
;
795 /* Process the normal symbol table first. */
796 storage_needed
= bfd_get_symtab_upper_bound (objfile
->obfd
.get ());
797 if (storage_needed
< 0)
798 error (_("Can't read symbols from %s: %s"),
799 bfd_get_filename (objfile
->obfd
.get ()),
800 bfd_errmsg (bfd_get_error ()));
802 if (storage_needed
> 0)
806 symbol_table
.resize (storage_needed
/ sizeof (asymbol
*));
808 minimal_symbol_reader
reader (objfile
);
810 symcount
= bfd_canonicalize_symtab (objfile
->obfd
.get (),
811 symbol_table
.data ());
814 error (_("Can't read symbols from %s: %s"),
815 bfd_get_filename (objfile
->obfd
.get ()),
816 bfd_errmsg (bfd_get_error ()));
818 macho_symtab_read (reader
, objfile
, symcount
, symbol_table
.data (),
824 /* Try to read .eh_frame / .debug_frame. */
825 /* First, locate these sections. We ignore the result status
826 as it only checks for debug info. */
827 dwarf2_has_info (objfile
, NULL
);
828 dwarf2_build_frame_info (objfile
);
830 /* Check for DSYM file. */
831 gdb_bfd_ref_ptr
dsym_bfd (macho_check_dsym (objfile
, &dsym_filename
));
832 if (dsym_bfd
!= NULL
)
834 struct bfd_section
*asect
, *dsect
;
836 macho_debug (0, _("dsym file found\n"));
838 /* Set dsym section size. */
839 for (asect
= objfile
->obfd
->sections
, dsect
= dsym_bfd
->sections
;
841 asect
= asect
->next
, dsect
= dsect
->next
)
843 if (strcmp (asect
->name
, dsect
->name
) != 0)
845 bfd_set_section_size (dsect
, bfd_section_size (asect
));
848 /* Add the dsym file as a separate file. */
849 symbol_file_add_separate (dsym_bfd
, dsym_filename
.c_str (),
850 symfile_flags
, objfile
);
852 /* Don't try to read dwarf2 from main file or shared libraries. */
857 if (dwarf2_has_info (objfile
, NULL
))
859 /* DWARF 2 sections */
860 dwarf2_initialize_objfile (objfile
);
864 if (!oso_vector
.empty ())
865 macho_symfile_read_all_oso (&oso_vector
, objfile
, symfile_flags
);
869 macho_symfile_relocate (struct objfile
*objfile
, asection
*sectp
,
872 bfd
*abfd
= objfile
->obfd
.get ();
874 /* We're only interested in sections with relocation
876 if ((sectp
->flags
& SEC_RELOC
) == 0)
879 macho_debug (0, _("Relocate section '%s' of %s\n"),
880 sectp
->name
, objfile_name (objfile
));
882 return bfd_simple_get_relocated_section_contents (abfd
, sectp
, buf
, NULL
);
886 macho_symfile_finish (struct objfile
*objfile
)
891 macho_symfile_offsets (struct objfile
*objfile
,
892 const section_addr_info
&addrs
)
896 /* Allocate section_offsets. */
897 objfile
->section_offsets
.assign (gdb_bfd_count_sections (objfile
->obfd
.get ()), 0);
899 /* This code is run when we first add the objfile with
900 symfile_add_with_addrs_or_offsets, when "addrs" not "offsets" are
901 passed in. The place in symfile.c where the addrs are applied
902 depends on the addrs having section names. But in the dyld code
903 we build an anonymous array of addrs, so that code is a no-op.
904 Because of that, we have to apply the addrs to the sections here.
905 N.B. if an objfile slides after we've already created it, then it
906 goes through objfile_relocate. */
908 for (i
= 0; i
< addrs
.size (); i
++)
910 for (obj_section
*osect
: objfile
->sections ())
912 const char *bfd_sect_name
= osect
->the_bfd_section
->name
;
914 if (bfd_sect_name
== addrs
[i
].name
)
916 osect
->set_offset (addrs
[i
].addr
);
922 objfile
->sect_index_text
= 0;
924 for (obj_section
*osect
: objfile
->sections ())
926 const char *bfd_sect_name
= osect
->the_bfd_section
->name
;
927 int sect_index
= osect
- objfile
->sections_start
;
929 if (startswith (bfd_sect_name
, "LC_SEGMENT."))
931 if (strcmp (bfd_sect_name
, "__TEXT") == 0
932 || strcmp (bfd_sect_name
, "__TEXT.__text") == 0)
933 objfile
->sect_index_text
= sect_index
;
937 static const struct sym_fns macho_sym_fns
= {
938 macho_new_init
, /* init anything gbl to entire symtab */
939 macho_symfile_init
, /* read initial info, setup for sym_read() */
940 macho_symfile_read
, /* read a symbol file into symtab */
941 macho_symfile_finish
, /* finished with file, cleanup */
942 macho_symfile_offsets
, /* xlate external to internal form */
943 default_symfile_segments
, /* Get segment information from a file. */
945 macho_symfile_relocate
, /* Relocate a debug section. */
946 NULL
, /* sym_get_probes */
949 void _initialize_machoread ();
951 _initialize_machoread ()
953 add_symtab_fns (bfd_target_mach_o_flavour
, &macho_sym_fns
);
955 add_setshow_zuinteger_cmd ("mach-o", class_obscure
,
957 _("Set if printing Mach-O symbols processing."),
958 _("Show if printing Mach-O symbols processing."),
960 &setdebuglist
, &showdebuglist
);