2008-11-27 09:23:01 +00:00
|
|
|
/* Darwin support for GDB, the GNU debugger.
|
2011-01-01 15:34:07 +00:00
|
|
|
Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
Contributed by AdaCore.
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "gdbtypes.h"
|
|
|
|
#include "bfd.h"
|
|
|
|
#include "symfile.h"
|
|
|
|
#include "objfiles.h"
|
|
|
|
#include "buildsym.h"
|
|
|
|
#include "gdbcmd.h"
|
|
|
|
#include "gdbcore.h"
|
|
|
|
#include "mach-o.h"
|
|
|
|
#include "gdb_assert.h"
|
|
|
|
#include "aout/stab_gnu.h"
|
|
|
|
#include "vec.h"
|
gdb
* xcoffread.c: Include psymtab.h.
(xcoff_sym_fns): Update.
* symtab.h (struct partial_symbol): Remove.
(PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.
(struct partial_symtab): Remove.
(PSYMTAB_TO_SYMTAB): Remove.
(lookup_partial_symbol, lookup_partial_symtab, find_pc_psymtab)
(find_pc_sect_psymtab): Remove.
(find_pc_sect_symtab_via_partial): Declare.
(find_pc_psymtab, find_pc_sect_psymbol, psymtab_to_symtab)
(find_main_psymtab): Remove.
(find_main_filename): Declare.
(fixup_psymbol_section): Remove.
(fixup_section): Declare.
* symtab.c: Include psymtab.h.
(lookup_symtab): Use lookup_symtab method.
(lookup_partial_symtab): Remove.
(find_pc_sect_psymtab_closer): Remove.
(find_pc_sect_psymtab): Remove.
(find_pc_sect_symtab_via_partial): New function.
(find_pc_psymtab, find_pc_sect_psymbol, find_pc_psymbol): Remove.
(fixup_section): No longer static.
(fixup_psymbol_section): Remove.
(lookup_symbol_aux): Use lookup_symbol_aux_quick.
(lookup_global_symbol_from_objfile): Likewise.
(lookup_symbol_aux_psymtabs): Remove.
(lookup_symbol_aux_quick): New function.
(lookup_symbol_global): Use lookup_symbol_aux_quick.
(lookup_partial_symbol): Remove.
(basic_lookup_transparent_type_quick): New function.
(basic_lookup_transparent_type): Use it.
(find_main_psymtab): Remove.
(find_main_filename): New function.
(find_pc_sect_symtab): Use find_pc_sect_symtab method.
(find_line_symtab): Use expand_symtabs_with_filename method.
(output_partial_symbol_filename): New function.
(sources_info): Use map_partial_symbol_filenames.
(struct search_symbols_data): New type.
(search_symbols_file_matches): New function.
(search_symbols_name_matches): Likewise.
(search_symbols): Use expand_symtabs_matching method.
(struct add_name_data): Rename from add_macro_name_data.
(add_macro_name): Update.
(add_partial_symbol_name): New function.
(default_make_symbol_completion_list): Use
map_partial_symbol_names.
(struct add_partial_symbol_name): New type.
(maybe_add_partial_symtab_filename): New function.
(make_source_files_completion_list): Use
map_partial_symbol_filenames.
(expand_line_sal): Use expand_symtabs_with_filename method.
* symmisc.c: Include psymtab.h.
(print_objfile_statistics): Use print_stats method.
(dump_objfile): Use dump method.
(dump_psymtab, maintenance_print_psymbols)
(maintenance_info_psymtabs, maintenance_check_symtabs)
(extend_psymbol_list): Remove.
* symfile.h (struct quick_symbol_functions): New struct.
(struct sym_fns) <qf>: New field.
(sort_pst_symbols): Remove.
(increment_reading_symtab): Declare.
* symfile.c: Include psymtab.h.
(compare_psymbols, sort_pst_symbols): Remove.
(psymtab_to_symtab): Remove.
(increment_reading_symtab): New function.
(symbol_file_add_with_addrs_or_offsets): Use expand_all_symtabs
method.
(set_initial_language): Use find_main_filename.
(allocate_psymtab, discard_psymtab, cashier_psymtab): Remove.
(free_named_symtabs): Remove unused code.
(start_psymtab_common, add_psymbol_to_bcache)
(append_psymbol_to_list, add_psymbol_to_list, init_psymbol_list):
Remove.
* stack.c: Include psymtab.h, symfile.h.
(backtrace_command_1): Use find_pc_sect_symtab_via_partial.
* source.h (psymtab_to_fullname): Don't declare.
* source.c: Include psymtab.h.
(select_source_symtab): Use find_last_source_symtab method.
(forget_cached_source_info): Use forget_cached_source_info
method.
(find_and_open_source): No longer static.
(psymtab_to_fullname): Remove.
* somread.c: Include psymtab.h.
(som_sym_fns): Update.
* psympriv.h: New file.
* psymtab.h: New file.
* psymtab.c: New file.
* objfiles.h: (ALL_OBJFILE_PSYMTABS): Remove.
(ALL_PSYMTABS, ALL_PSPACE_PSYMTABS): Likewise.
* objfiles.c: Include psymtab.h.
(objfile_relocate1): Use relocate method.
(objfile_has_partial_symbols): Use has_symbols method.
* mipsread.c: Include psymtab.h.
(ecoff_sym_fns): Update.
* mi/mi-cmd-file.c: Include psymtab.h.
(print_partial_file_name): New function.
(mi_cmd_file_list_exec_source_files): Use
map_partial_symbol_filenames.
* mdebugread.c: Include psympriv.h.
* machoread.c: Include psympriv.h.
(macho_sym_fns): Update.
* m2-exp.y (yylex): Use lookup_symtab.
* elfread.c: Include psympriv.h.
(elf_sym_fns): Update.
* dwarf2read.c: Include psympriv.h.
* dbxread.c: Include psympriv.h.
(aout_sym_fns): Update.
* cp-support.c: Include psymtab.h.
(read_in_psymtabs): Remove.
(make_symbol_overload_list_qualified): Use
expand_symtabs_for_function method.
* coffread.c: Include psympriv.h.
(coff_sym_fns): Update.
* blockframe.c: Include psymtab.h.
(find_pc_partial_function): Use find_pc_sect_symtab method.
* ada-lang.h (ada_update_initial_language): Update.
* ada-lang.c: Include psymtab.h.
(ada_update_initial_language): Remove 'main_pst' argument.
(ada_lookup_partial_symbol): Remove.
(struct ada_psym_data): New type.
(ada_add_psyms): New function.
(ada_add_non_local_symbols): Use map_ada_symtabs method.
(struct add_partial_datum): New type.
(ada_add_partial_symbol_completions): New function.
(ada_make_symbol_completion_list): Use map_partial_symbol_names.
(ada_exception_support_info_sniffer): Update.
* Makefile.in (SFILES): Add psymtab.c.
(COMMON_OBS): Add psymtab.o.
(HFILES_NO_SRCDIR): Add psymtab.h, psympriv.h.
gdb/doc
* gdbint.texinfo (Symbol Handling): Update.
2010-03-10 18:20:08 +00:00
|
|
|
#include "psympriv.h"
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* If non-zero displays debugging message. */
|
|
|
|
static int mach_o_debug_level = 0;
|
|
|
|
|
|
|
|
/* Dwarf debugging information are never in the final executable. They stay
|
|
|
|
in object files and the executable contains the list of object files read
|
|
|
|
during the link.
|
|
|
|
Each time an oso (other source) is found in the executable, the reader
|
|
|
|
creates such a structure. They are read after the processing of the
|
2011-01-09 03:20:33 +00:00
|
|
|
executable. */
|
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
typedef struct oso_el
|
|
|
|
{
|
|
|
|
/* Object file name. */
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
/* Associated time stamp. */
|
|
|
|
unsigned long mtime;
|
|
|
|
|
|
|
|
/* Number of sections. This is the length of SYMBOLS and OFFSETS array. */
|
|
|
|
int num_sections;
|
|
|
|
|
|
|
|
/* Each seaction of the object file is represented by a symbol and its
|
2009-12-15 09:37:14 +00:00
|
|
|
offset. If the offset is 0, we assume that the symbol is at offset 0
|
|
|
|
in the OSO object file and a symbol lookup in the main file is
|
|
|
|
required to get the offset. */
|
2008-11-27 09:23:01 +00:00
|
|
|
asymbol **symbols;
|
|
|
|
bfd_vma *offsets;
|
|
|
|
}
|
|
|
|
oso_el;
|
|
|
|
|
2010-02-04 12:45:49 +00:00
|
|
|
/* Vector of object files to be read after the executable. This is one
|
|
|
|
global variable but it's life-time is the one of macho_symfile_read. */
|
2008-11-27 09:23:01 +00:00
|
|
|
DEF_VEC_O (oso_el);
|
|
|
|
static VEC (oso_el) *oso_vector;
|
|
|
|
|
2010-02-09 15:53:00 +00:00
|
|
|
struct macho_oso_data
|
|
|
|
{
|
|
|
|
/* Per objfile symbol table. This is used to apply relocation to sections
|
|
|
|
It is loaded only once, then relocated, and free after sections are
|
|
|
|
relocated. */
|
|
|
|
asymbol **symbol_table;
|
|
|
|
|
|
|
|
/* The offsets for this objfile. Used to relocate the symbol_table. */
|
|
|
|
struct oso_el *oso;
|
|
|
|
|
|
|
|
struct objfile *main_objfile;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Data for OSO being processed. */
|
|
|
|
|
|
|
|
static struct macho_oso_data current_oso;
|
|
|
|
|
2010-02-04 12:45:49 +00:00
|
|
|
static void
|
|
|
|
macho_new_init (struct objfile *objfile)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
macho_symfile_init (struct objfile *objfile)
|
|
|
|
{
|
|
|
|
objfile->flags |= OBJF_REORDERED;
|
|
|
|
init_entry_point_info (objfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a new OSO to the vector of OSO to load. */
|
2009-10-13 09:42:57 +00:00
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
static void
|
2010-02-04 12:45:49 +00:00
|
|
|
macho_register_oso (const asymbol *oso_sym, int nbr_sections,
|
|
|
|
asymbol **symbols, bfd_vma *offsets)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
oso_el el;
|
|
|
|
|
|
|
|
el.name = oso_sym->name;
|
|
|
|
el.mtime = oso_sym->value;
|
|
|
|
el.num_sections = nbr_sections;
|
|
|
|
el.symbols = symbols;
|
|
|
|
el.offsets = offsets;
|
|
|
|
VEC_safe_push (oso_el, oso_vector, &el);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the minimal symbol table from SYMBOL_TABLE of length
|
|
|
|
NUMBER_OF_SYMBOLS for OBJFILE.
|
|
|
|
Read OSO files at the end. */
|
2009-10-13 09:42:57 +00:00
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
static void
|
|
|
|
macho_symtab_read (struct objfile *objfile,
|
|
|
|
long number_of_symbols, asymbol **symbol_table)
|
|
|
|
{
|
|
|
|
struct gdbarch *gdbarch = get_objfile_arch (objfile);
|
|
|
|
long storage_needed;
|
|
|
|
long i, j;
|
|
|
|
CORE_ADDR offset;
|
|
|
|
enum minimal_symbol_type ms_type;
|
|
|
|
unsigned int nbr_sections = bfd_count_sections (objfile->obfd);
|
|
|
|
asymbol **first_symbol = NULL;
|
|
|
|
bfd_vma *first_offset = NULL;
|
|
|
|
const asymbol *oso_file = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < number_of_symbols; i++)
|
|
|
|
{
|
2009-06-19 Tristan Gingold <gingold@adacore.com>
* machoread.c (macho_symtab_read): Adjust for bfd changes.
* darwin-nat.h (struct darwin_exception_msg): New type to describe
a mach exception.
(struct private_thread_info): New type to describe the state of the
thread.
(DEF_VEC_I thread_t): Removed, replaced by ...
(DEF_VEC_O darwin_thread_t): ... this new type.
(struct darwin_inferior): Renamed to ...
(struct private_inferior): ... this type. Fields added.
(darwin_not_port): Moved into the private inferior structure.
* darwin-nat.c: Add includes, improve comments.
Rewrite to handle multiple threads and processes.
(darwin_resume_to): New function and protype.
(darwin_resume, darwin_wait_to, darwin_wait): Ditto.
(darwin_kill_inferior): Add ops argument.
(darwin_pid_to_str): New function.
(darwin_thread_alive): Ditto.
(darwin_inf, darwin_not_port): Removed.
(darwin_inf_fake_stop): New variable.
(msgin, msgout, msg_state, exc_msg): Removed.
(mach_check_error): Use warning instead of error.
(darwin_ptrace): Adjust debug level.
(cmp_thread_t): Fix names (typo).
(darwin_check_new_threads): Argument is now an inferior,
adjust for new structures, add no change check, ignore dead ports,
handle first thread case.
(find_inferior_task_it): New function.
(find_inferior_notify_it): Ditto.
(darwin_find_inferior_by_task): Ditto.
(darwin_find_inferior_by_notify): Ditto.
(darwin_find_thread): Ditto.
(darwin_suspend_inferior): Ditto.
(darwin_resume_inferior): Ditto.
(catch_exception_raise_state): Removed.
(catch_exception_raise_state_identity): Removed.
(darwin_suspend_inferior_it): New function.
(darwin_resume_inferior_it): Ditto.
(darwin_dump_message): New function, extracted from darwin_wait.
(darwin_decode_exception_message): New function.
(darwin_encode_reply): New function.
(catch_exception_raise): Removed.
(darwin_send_reply): New function, extracted from darwin_resume.
(darwin_resume_thread): New function, extracted from darwin_resume.
(struct resume_inferior_threads_param): New type.
(darwin_resume_inferior_threads_it): New function.
(darwin_resume_inferior_threads): New function.
(darwin_suspend_inferior_threads): New function.
(darwin_resume): Mostly rewritten to handle multiple threads and
some corner cases.
(darwin_decode_message): New function extracted from darwin_wait.
(cancel_breakpoint): New function.
(darwin_wait): Mostly rewritten. Handle multiple threads.
(darwin_mourn_inferior): Adjust for per process structures.
(darwin_reply_to_all_pending_messages): New function.
(darwin_stop_inferior): Adjust for per inferior structures.
(darwin_attach_pid): Ditto.
(darwin_init_thread_list): Ditto.
(darwin_attach): Ditto.
(darwin_detach): Ditto.
(darwin_files_info): Now empty.
(darwin_pid_to_str): Adjust returns string to match one expected by
the testsuite.
(darwin_read_write_inferior): Rename err variable to match other uses.
Adjust debug message. Handle submaps.
(darwin_xfer_memory): Adjust for per inferior structures.
(set_enable_mach_exceptions): Ditto.
(darwin_pid_to_exec_file): New function.
(darwin_get_ada_task_ptid): Ditto.
(darwin_supports_multi_process): Ditto.
(_initialize_darwin_inferior): Remove useless assertion, adjust for
per inferior structures. Add new target operations.
2009-06-19 14:30:30 +00:00
|
|
|
asymbol *sym = symbol_table[i];
|
|
|
|
bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym;
|
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
offset = ANOFFSET (objfile->section_offsets, sym->section->index);
|
|
|
|
|
|
|
|
if (sym->flags & BSF_DEBUGGING)
|
|
|
|
{
|
|
|
|
bfd_vma addr;
|
|
|
|
|
2009-12-15 09:37:14 +00:00
|
|
|
/* Debugging symbols are used to collect OSO file names as well
|
|
|
|
as section offsets. */
|
|
|
|
|
2009-06-19 Tristan Gingold <gingold@adacore.com>
* machoread.c (macho_symtab_read): Adjust for bfd changes.
* darwin-nat.h (struct darwin_exception_msg): New type to describe
a mach exception.
(struct private_thread_info): New type to describe the state of the
thread.
(DEF_VEC_I thread_t): Removed, replaced by ...
(DEF_VEC_O darwin_thread_t): ... this new type.
(struct darwin_inferior): Renamed to ...
(struct private_inferior): ... this type. Fields added.
(darwin_not_port): Moved into the private inferior structure.
* darwin-nat.c: Add includes, improve comments.
Rewrite to handle multiple threads and processes.
(darwin_resume_to): New function and protype.
(darwin_resume, darwin_wait_to, darwin_wait): Ditto.
(darwin_kill_inferior): Add ops argument.
(darwin_pid_to_str): New function.
(darwin_thread_alive): Ditto.
(darwin_inf, darwin_not_port): Removed.
(darwin_inf_fake_stop): New variable.
(msgin, msgout, msg_state, exc_msg): Removed.
(mach_check_error): Use warning instead of error.
(darwin_ptrace): Adjust debug level.
(cmp_thread_t): Fix names (typo).
(darwin_check_new_threads): Argument is now an inferior,
adjust for new structures, add no change check, ignore dead ports,
handle first thread case.
(find_inferior_task_it): New function.
(find_inferior_notify_it): Ditto.
(darwin_find_inferior_by_task): Ditto.
(darwin_find_inferior_by_notify): Ditto.
(darwin_find_thread): Ditto.
(darwin_suspend_inferior): Ditto.
(darwin_resume_inferior): Ditto.
(catch_exception_raise_state): Removed.
(catch_exception_raise_state_identity): Removed.
(darwin_suspend_inferior_it): New function.
(darwin_resume_inferior_it): Ditto.
(darwin_dump_message): New function, extracted from darwin_wait.
(darwin_decode_exception_message): New function.
(darwin_encode_reply): New function.
(catch_exception_raise): Removed.
(darwin_send_reply): New function, extracted from darwin_resume.
(darwin_resume_thread): New function, extracted from darwin_resume.
(struct resume_inferior_threads_param): New type.
(darwin_resume_inferior_threads_it): New function.
(darwin_resume_inferior_threads): New function.
(darwin_suspend_inferior_threads): New function.
(darwin_resume): Mostly rewritten to handle multiple threads and
some corner cases.
(darwin_decode_message): New function extracted from darwin_wait.
(cancel_breakpoint): New function.
(darwin_wait): Mostly rewritten. Handle multiple threads.
(darwin_mourn_inferior): Adjust for per process structures.
(darwin_reply_to_all_pending_messages): New function.
(darwin_stop_inferior): Adjust for per inferior structures.
(darwin_attach_pid): Ditto.
(darwin_init_thread_list): Ditto.
(darwin_attach): Ditto.
(darwin_detach): Ditto.
(darwin_files_info): Now empty.
(darwin_pid_to_str): Adjust returns string to match one expected by
the testsuite.
(darwin_read_write_inferior): Rename err variable to match other uses.
Adjust debug message. Handle submaps.
(darwin_xfer_memory): Adjust for per inferior structures.
(set_enable_mach_exceptions): Ditto.
(darwin_pid_to_exec_file): New function.
(darwin_get_ada_task_ptid): Ditto.
(darwin_supports_multi_process): Ditto.
(_initialize_darwin_inferior): Remove useless assertion, adjust for
per inferior structures. Add new target operations.
2009-06-19 14:30:30 +00:00
|
|
|
switch (mach_o_sym->n_type)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
case N_SO:
|
2009-12-15 09:37:14 +00:00
|
|
|
/* An empty SO entry terminates a chunk for an OSO file. */
|
|
|
|
if ((sym->name == NULL || sym->name[0] == 0) && oso_file != NULL)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
2010-02-04 12:45:49 +00:00
|
|
|
macho_register_oso (oso_file, nbr_sections,
|
|
|
|
first_symbol, first_offset);
|
2008-11-27 09:23:01 +00:00
|
|
|
first_symbol = NULL;
|
|
|
|
first_offset = NULL;
|
|
|
|
oso_file = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case N_FUN:
|
|
|
|
case N_STSYM:
|
|
|
|
if (sym->name == NULL || sym->name[0] == '\0')
|
|
|
|
break;
|
|
|
|
/* Fall through. */
|
|
|
|
case N_BNSYM:
|
|
|
|
gdb_assert (oso_file != NULL);
|
|
|
|
addr = sym->value
|
|
|
|
+ bfd_get_section_vma (sym->section->bfd, sym->section);
|
|
|
|
if (addr != 0
|
|
|
|
&& first_symbol[sym->section->index] == NULL)
|
|
|
|
{
|
2009-12-15 09:37:14 +00:00
|
|
|
/* These STAB entries can directly relocate a section. */
|
2008-11-27 09:23:01 +00:00
|
|
|
first_symbol[sym->section->index] = sym;
|
|
|
|
first_offset[sym->section->index] = addr + offset;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case N_GSYM:
|
|
|
|
gdb_assert (oso_file != NULL);
|
|
|
|
if (first_symbol[sym->section->index] == NULL)
|
2009-12-15 09:37:14 +00:00
|
|
|
{
|
|
|
|
/* This STAB entry needs a symbol look-up to relocate
|
|
|
|
the section. */
|
|
|
|
first_symbol[sym->section->index] = sym;
|
|
|
|
first_offset[sym->section->index] = 0;
|
|
|
|
}
|
2008-11-27 09:23:01 +00:00
|
|
|
break;
|
|
|
|
case N_OSO:
|
2009-12-15 09:37:14 +00:00
|
|
|
/* New OSO file. */
|
2008-11-27 09:23:01 +00:00
|
|
|
gdb_assert (oso_file == NULL);
|
|
|
|
first_symbol = (asymbol **)xmalloc (nbr_sections
|
|
|
|
* sizeof (asymbol *));
|
|
|
|
first_offset = (bfd_vma *)xmalloc (nbr_sections
|
|
|
|
* sizeof (bfd_vma));
|
|
|
|
for (j = 0; j < nbr_sections; j++)
|
|
|
|
first_symbol[j] = NULL;
|
|
|
|
oso_file = sym;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sym->name == NULL || *sym->name == '\0')
|
|
|
|
{
|
|
|
|
/* Skip names that don't exist (shouldn't happen), or names
|
2011-01-09 03:20:33 +00:00
|
|
|
that are null strings (may happen). */
|
2008-11-27 09:23:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
|
|
|
|
{
|
|
|
|
struct minimal_symbol *msym;
|
|
|
|
CORE_ADDR symaddr;
|
|
|
|
|
2011-01-09 03:20:33 +00:00
|
|
|
/* Bfd symbols are section relative. */
|
2008-11-27 09:23:01 +00:00
|
|
|
symaddr = sym->value + sym->section->vma;
|
|
|
|
|
|
|
|
/* Select global/local/weak symbols. Note that bfd puts abs
|
|
|
|
symbols in their own section, so all symbols we are
|
2011-01-09 03:20:33 +00:00
|
|
|
interested in will have a section. */
|
2008-11-27 09:23:01 +00:00
|
|
|
/* Relocate all non-absolute and non-TLS symbols by the
|
|
|
|
section offset. */
|
|
|
|
if (sym->section != &bfd_abs_section
|
|
|
|
&& !(sym->section->flags & SEC_THREAD_LOCAL))
|
|
|
|
symaddr += offset;
|
|
|
|
|
|
|
|
if (sym->section == &bfd_abs_section)
|
|
|
|
ms_type = mst_abs;
|
|
|
|
else if (sym->section->flags & SEC_CODE)
|
|
|
|
{
|
|
|
|
if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
|
|
|
|
ms_type = mst_text;
|
|
|
|
else
|
|
|
|
ms_type = mst_file_text;
|
|
|
|
}
|
|
|
|
else if (sym->section->flags & SEC_ALLOC)
|
|
|
|
{
|
|
|
|
if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
|
|
|
|
{
|
|
|
|
if (sym->section->flags & SEC_LOAD)
|
|
|
|
ms_type = mst_data;
|
|
|
|
else
|
|
|
|
ms_type = mst_bss;
|
|
|
|
}
|
|
|
|
else if (sym->flags & BSF_LOCAL)
|
|
|
|
{
|
|
|
|
/* Not a special stabs-in-elf symbol, do regular
|
|
|
|
symbol processing. */
|
|
|
|
if (sym->section->flags & SEC_LOAD)
|
|
|
|
ms_type = mst_file_data;
|
|
|
|
else
|
|
|
|
ms_type = mst_file_bss;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ms_type = mst_unknown;
|
|
|
|
}
|
|
|
|
else
|
2011-01-09 03:20:33 +00:00
|
|
|
continue; /* Skip this symbol. */
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
gdb_assert (sym->section->index < nbr_sections);
|
|
|
|
if (oso_file != NULL
|
|
|
|
&& first_symbol[sym->section->index] == NULL)
|
|
|
|
{
|
2009-12-15 09:37:14 +00:00
|
|
|
/* Standard symbols can directly relocate sections. */
|
2008-11-27 09:23:01 +00:00
|
|
|
first_symbol[sym->section->index] = sym;
|
|
|
|
first_offset[sym->section->index] = symaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
msym = prim_record_minimal_symbol_and_info
|
|
|
|
(sym->name, symaddr, ms_type, sym->section->index,
|
|
|
|
sym->section, objfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-15 09:37:14 +00:00
|
|
|
/* Just in case there is no trailing SO entry. */
|
2008-11-27 09:23:01 +00:00
|
|
|
if (oso_file != NULL)
|
2010-02-04 12:45:49 +00:00
|
|
|
macho_register_oso (oso_file, nbr_sections, first_symbol, first_offset);
|
2008-11-27 09:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If NAME describes an archive member (ie: ARCHIVE '(' MEMBER ')'),
|
|
|
|
returns the length of the archive name.
|
|
|
|
Returns -1 otherwise. */
|
2009-10-13 09:42:57 +00:00
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
static int
|
|
|
|
get_archive_prefix_len (const char *name)
|
|
|
|
{
|
|
|
|
char *lparen;
|
|
|
|
int name_len = strlen (name);
|
|
|
|
|
|
|
|
if (name_len == 0 || name[name_len - 1] != ')')
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
lparen = strrchr (name, '(');
|
|
|
|
if (lparen == NULL || lparen == name)
|
|
|
|
return -1;
|
|
|
|
return lparen - name;
|
|
|
|
}
|
|
|
|
|
2009-10-13 09:42:57 +00:00
|
|
|
static int
|
|
|
|
oso_el_compare_name (const void *vl, const void *vr)
|
|
|
|
{
|
|
|
|
const oso_el *l = (const oso_el *)vl;
|
|
|
|
const oso_el *r = (const oso_el *)vr;
|
|
|
|
|
|
|
|
return strcmp (l->name, r->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add an oso file as a symbol file. */
|
|
|
|
|
|
|
|
static void
|
2010-01-14 12:47:44 +00:00
|
|
|
macho_add_oso_symfile (oso_el *oso, bfd *abfd,
|
|
|
|
struct objfile *main_objfile, int symfile_flags)
|
2009-10-13 09:42:57 +00:00
|
|
|
{
|
2010-01-14 12:47:44 +00:00
|
|
|
struct objfile *objfile;
|
2009-10-13 09:42:57 +00:00
|
|
|
int i;
|
|
|
|
char leading_char;
|
|
|
|
|
|
|
|
if (mach_o_debug_level > 0)
|
|
|
|
printf_unfiltered (_("Loading symbols from oso: %s\n"), oso->name);
|
2010-02-04 12:45:49 +00:00
|
|
|
|
2009-10-13 09:42:57 +00:00
|
|
|
if (!bfd_check_format (abfd, bfd_object))
|
|
|
|
{
|
|
|
|
warning (_("`%s': can't read symbols: %s."), oso->name,
|
|
|
|
bfd_errmsg (bfd_get_error ()));
|
|
|
|
bfd_close (abfd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bfd_set_cacheable (abfd, 1);
|
2010-02-09 15:53:00 +00:00
|
|
|
|
|
|
|
/* Relocate sections. */
|
2009-10-13 09:42:57 +00:00
|
|
|
|
|
|
|
leading_char = bfd_get_symbol_leading_char (main_objfile->obfd);
|
|
|
|
|
|
|
|
for (i = 0; i < oso->num_sections; i++)
|
|
|
|
{
|
2010-02-09 15:53:00 +00:00
|
|
|
asection *sect;
|
|
|
|
const char *sectname;
|
|
|
|
bfd_vma vma;
|
|
|
|
|
|
|
|
/* Empty slot. */
|
|
|
|
if (oso->symbols[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (oso->offsets[i])
|
|
|
|
vma = oso->offsets[i];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct minimal_symbol *msym;
|
|
|
|
const char *name = oso->symbols[i]->name;
|
|
|
|
|
|
|
|
if (name[0] == leading_char)
|
|
|
|
++name;
|
|
|
|
|
|
|
|
if (mach_o_debug_level > 3)
|
|
|
|
printf_unfiltered (_("resolve sect %s with %s\n"),
|
|
|
|
oso->symbols[i]->section->name,
|
|
|
|
oso->symbols[i]->name);
|
|
|
|
msym = lookup_minimal_symbol (name, NULL, main_objfile);
|
|
|
|
if (msym == NULL)
|
|
|
|
{
|
|
|
|
warning (_("can't find symbol '%s' in minsymtab"), name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vma = SYMBOL_VALUE_ADDRESS (msym);
|
|
|
|
}
|
|
|
|
sectname = (char *)oso->symbols[i]->section->name;
|
|
|
|
|
|
|
|
sect = bfd_get_section_by_name (abfd, sectname);
|
|
|
|
if (sect == NULL)
|
|
|
|
{
|
|
|
|
warning (_("can't find section '%s' in OSO file %s"),
|
|
|
|
sectname, oso->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bfd_set_section_vma (abfd, sect, vma);
|
|
|
|
|
|
|
|
if (mach_o_debug_level > 1)
|
2009-10-13 09:42:57 +00:00
|
|
|
printf_unfiltered (_(" %s: %s\n"),
|
2010-02-09 15:53:00 +00:00
|
|
|
core_addr_to_string (vma), sectname);
|
2009-10-13 09:42:57 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 12:47:44 +00:00
|
|
|
/* Make sure that the filename was malloc'ed. The current filename comes
|
|
|
|
either from an OSO symbol name or from an archive name. Memory for both
|
|
|
|
is not managed by gdb. */
|
|
|
|
abfd->filename = xstrdup (abfd->filename);
|
|
|
|
|
2010-02-09 15:53:00 +00:00
|
|
|
gdb_assert (current_oso.symbol_table == NULL);
|
|
|
|
current_oso.main_objfile = main_objfile;
|
|
|
|
|
2010-01-14 12:47:44 +00:00
|
|
|
/* We need to clear SYMFILE_MAINLINE to avoid interractive question
|
|
|
|
from symfile.c:symbol_file_add_with_addrs_or_offsets. */
|
|
|
|
objfile = symbol_file_add_from_bfd
|
2010-02-09 15:53:00 +00:00
|
|
|
(abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
|
2010-01-14 12:47:44 +00:00
|
|
|
main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
|
2011-04-17 18:38:46 +00:00
|
|
|
| OBJF_READNOW | OBJF_USERLOADED),
|
|
|
|
main_objfile);
|
2010-02-09 15:53:00 +00:00
|
|
|
|
|
|
|
current_oso.main_objfile = NULL;
|
|
|
|
if (current_oso.symbol_table)
|
|
|
|
{
|
|
|
|
xfree (current_oso.symbol_table);
|
|
|
|
current_oso.symbol_table = NULL;
|
|
|
|
}
|
2009-10-13 09:42:57 +00:00
|
|
|
}
|
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
/* Read symbols from the vector of oso files. */
|
2009-10-13 09:42:57 +00:00
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
static void
|
2010-02-04 12:45:49 +00:00
|
|
|
macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
VEC (oso_el) *vec;
|
|
|
|
oso_el *oso;
|
|
|
|
|
|
|
|
vec = oso_vector;
|
|
|
|
oso_vector = NULL;
|
|
|
|
|
2009-10-13 09:42:57 +00:00
|
|
|
/* Sort oso by name so that files from libraries are gathered. */
|
|
|
|
qsort (VEC_address (oso_el, vec), VEC_length (oso_el, vec),
|
|
|
|
sizeof (oso_el), oso_el_compare_name);
|
2008-11-27 09:23:01 +00:00
|
|
|
|
2009-10-13 09:42:57 +00:00
|
|
|
for (ix = 0; VEC_iterate (oso_el, vec, ix, oso);)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
int pfx_len;
|
|
|
|
|
|
|
|
/* Check if this is a library name. */
|
|
|
|
pfx_len = get_archive_prefix_len (oso->name);
|
|
|
|
if (pfx_len > 0)
|
|
|
|
{
|
|
|
|
bfd *archive_bfd;
|
|
|
|
bfd *member_bfd;
|
2009-10-13 09:42:57 +00:00
|
|
|
char *archive_name = XNEWVEC (char, pfx_len + 1);
|
|
|
|
int last_ix;
|
|
|
|
oso_el *oso2;
|
|
|
|
int ix2;
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
memcpy (archive_name, oso->name, pfx_len);
|
|
|
|
archive_name[pfx_len] = '\0';
|
|
|
|
|
2009-10-13 09:42:57 +00:00
|
|
|
/* Compute number of oso for this archive. */
|
|
|
|
for (last_ix = ix;
|
|
|
|
VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++)
|
|
|
|
{
|
|
|
|
if (strncmp (oso2->name, archive_name, pfx_len) != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
/* Open the archive and check the format. */
|
|
|
|
archive_bfd = bfd_openr (archive_name, gnutarget);
|
|
|
|
if (archive_bfd == NULL)
|
|
|
|
{
|
|
|
|
warning (_("Could not open OSO archive file \"%s\""),
|
|
|
|
archive_name);
|
2009-10-13 09:42:57 +00:00
|
|
|
ix = last_ix;
|
2008-11-27 09:23:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!bfd_check_format (archive_bfd, bfd_archive))
|
|
|
|
{
|
|
|
|
warning (_("OSO archive file \"%s\" not an archive."),
|
|
|
|
archive_name);
|
|
|
|
bfd_close (archive_bfd);
|
2009-10-13 09:42:57 +00:00
|
|
|
ix = last_ix;
|
2008-11-27 09:23:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
member_bfd = bfd_openr_next_archived_file (archive_bfd, NULL);
|
|
|
|
|
|
|
|
if (member_bfd == NULL)
|
|
|
|
{
|
|
|
|
warning (_("Could not read archive members out of "
|
|
|
|
"OSO archive \"%s\""), archive_name);
|
|
|
|
bfd_close (archive_bfd);
|
2009-10-13 09:42:57 +00:00
|
|
|
ix = last_ix;
|
2008-11-27 09:23:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-10-13 09:42:57 +00:00
|
|
|
|
|
|
|
/* Load all oso in this library. */
|
2008-11-27 09:23:01 +00:00
|
|
|
while (member_bfd != NULL)
|
|
|
|
{
|
2009-10-13 09:42:57 +00:00
|
|
|
bfd *prev;
|
2008-11-27 09:23:01 +00:00
|
|
|
const char *member_name = member_bfd->filename;
|
2009-10-13 09:42:57 +00:00
|
|
|
int member_len = strlen (member_name);
|
|
|
|
|
2009-11-18 14:10:47 +00:00
|
|
|
/* If this member is referenced, add it as a symfile. */
|
2009-10-13 09:42:57 +00:00
|
|
|
for (ix2 = ix; ix2 < last_ix; ix2++)
|
|
|
|
{
|
|
|
|
oso2 = VEC_index (oso_el, vec, ix2);
|
|
|
|
|
|
|
|
if (oso2->name
|
|
|
|
&& strlen (oso2->name) == pfx_len + member_len + 2
|
|
|
|
&& !memcmp (member_name, oso2->name + pfx_len + 1,
|
|
|
|
member_len))
|
|
|
|
{
|
2010-01-14 12:47:44 +00:00
|
|
|
macho_add_oso_symfile (oso2, member_bfd,
|
|
|
|
main_objfile, symfile_flags);
|
2009-10-13 09:42:57 +00:00
|
|
|
oso2->name = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = member_bfd;
|
2008-11-27 09:23:01 +00:00
|
|
|
member_bfd = bfd_openr_next_archived_file
|
|
|
|
(archive_bfd, member_bfd);
|
2009-11-18 14:10:47 +00:00
|
|
|
|
|
|
|
/* Free previous member if not referenced by an oso. */
|
|
|
|
if (ix2 >= last_ix)
|
2009-10-13 09:42:57 +00:00
|
|
|
bfd_close (prev);
|
2008-11-27 09:23:01 +00:00
|
|
|
}
|
2009-10-13 09:42:57 +00:00
|
|
|
for (ix2 = ix; ix2 < last_ix; ix2++)
|
|
|
|
{
|
|
|
|
oso_el *oso2 = VEC_index (oso_el, vec, ix2);
|
|
|
|
|
|
|
|
if (oso2->name != NULL)
|
|
|
|
warning (_("Could not find specified archive member "
|
|
|
|
"for OSO name \"%s\""), oso->name);
|
|
|
|
}
|
|
|
|
ix = last_ix;
|
2008-11-27 09:23:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-13 09:42:57 +00:00
|
|
|
bfd *abfd;
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
abfd = bfd_openr (oso->name, gnutarget);
|
|
|
|
if (!abfd)
|
2009-10-13 09:42:57 +00:00
|
|
|
warning (_("`%s': can't open to read symbols: %s."), oso->name,
|
|
|
|
bfd_errmsg (bfd_get_error ()));
|
|
|
|
else
|
2010-01-14 12:47:44 +00:00
|
|
|
macho_add_oso_symfile (oso, abfd, main_objfile, symfile_flags);
|
2009-10-13 09:42:57 +00:00
|
|
|
|
|
|
|
ix++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ix = 0; VEC_iterate (oso_el, vec, ix, oso); ix++)
|
|
|
|
{
|
2008-11-27 09:23:01 +00:00
|
|
|
xfree (oso->symbols);
|
|
|
|
xfree (oso->offsets);
|
|
|
|
}
|
|
|
|
VEC_free (oso_el, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DSYM (debug symbols) files contain the debug info of an executable.
|
|
|
|
This is a separate file created by dsymutil(1) and is similar to debug
|
|
|
|
link feature on ELF.
|
|
|
|
DSYM files are located in a subdirectory. Append DSYM_SUFFIX to the
|
|
|
|
executable name and the executable base name to get the DSYM file name. */
|
|
|
|
#define DSYM_SUFFIX ".dSYM/Contents/Resources/DWARF/"
|
|
|
|
|
|
|
|
/* Check if a dsym file exists for OBJFILE. If so, returns a bfd for it.
|
|
|
|
Return NULL if no valid dsym file is found. */
|
2009-10-13 09:42:57 +00:00
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
static bfd *
|
|
|
|
macho_check_dsym (struct objfile *objfile)
|
|
|
|
{
|
|
|
|
size_t name_len = strlen (objfile->name);
|
|
|
|
size_t dsym_len = strlen (DSYM_SUFFIX);
|
|
|
|
const char *base_name = lbasename (objfile->name);
|
|
|
|
size_t base_len = strlen (base_name);
|
|
|
|
char *dsym_filename = alloca (name_len + dsym_len + base_len + 1);
|
|
|
|
bfd *dsym_bfd;
|
2009-12-15 09:41:16 +00:00
|
|
|
bfd_mach_o_load_command *main_uuid;
|
|
|
|
bfd_mach_o_load_command *dsym_uuid;
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
strcpy (dsym_filename, objfile->name);
|
|
|
|
strcpy (dsym_filename + name_len, DSYM_SUFFIX);
|
|
|
|
strcpy (dsym_filename + name_len + dsym_len, base_name);
|
|
|
|
|
|
|
|
if (access (dsym_filename, R_OK) != 0)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-15 09:41:16 +00:00
|
|
|
if (bfd_mach_o_lookup_command (objfile->obfd,
|
|
|
|
BFD_MACH_O_LC_UUID, &main_uuid) == 0)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
warning (_("can't find UUID in %s"), objfile->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
dsym_filename = xstrdup (dsym_filename);
|
|
|
|
dsym_bfd = bfd_openr (dsym_filename, gnutarget);
|
|
|
|
if (dsym_bfd == NULL)
|
|
|
|
{
|
|
|
|
warning (_("can't open dsym file %s"), dsym_filename);
|
|
|
|
xfree (dsym_filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bfd_check_format (dsym_bfd, bfd_object))
|
|
|
|
{
|
|
|
|
bfd_close (dsym_bfd);
|
|
|
|
warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
|
|
|
|
xfree (dsym_filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-15 09:41:16 +00:00
|
|
|
if (bfd_mach_o_lookup_command (dsym_bfd,
|
|
|
|
BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
warning (_("can't find UUID in %s"), dsym_filename);
|
|
|
|
bfd_close (dsym_bfd);
|
|
|
|
xfree (dsym_filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-15 09:41:16 +00:00
|
|
|
if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
|
|
|
|
sizeof (main_uuid->command.uuid.uuid)))
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
warning (_("dsym file UUID doesn't match the one in %s"), objfile->name);
|
|
|
|
bfd_close (dsym_bfd);
|
|
|
|
xfree (dsym_filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return dsym_bfd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-07 09:47:40 +00:00
|
|
|
macho_symfile_read (struct objfile *objfile, int symfile_flags)
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
bfd *abfd = objfile->obfd;
|
|
|
|
struct cleanup *back_to;
|
|
|
|
CORE_ADDR offset;
|
|
|
|
long storage_needed;
|
|
|
|
bfd *dsym_bfd;
|
|
|
|
|
|
|
|
init_minimal_symbol_collection ();
|
|
|
|
back_to = make_cleanup_discard_minimal_symbols ();
|
|
|
|
|
|
|
|
/* Get symbols from the symbol table only if the file is an executable.
|
|
|
|
The symbol table of object files is not relocated and is expected to
|
|
|
|
be in the executable. */
|
2009-02-04 08:47:56 +00:00
|
|
|
if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
/* Process the normal symbol table first. */
|
|
|
|
storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
|
|
|
|
if (storage_needed < 0)
|
|
|
|
error (_("Can't read symbols from %s: %s"),
|
|
|
|
bfd_get_filename (objfile->obfd),
|
|
|
|
bfd_errmsg (bfd_get_error ()));
|
|
|
|
|
|
|
|
if (storage_needed > 0)
|
|
|
|
{
|
|
|
|
asymbol **symbol_table;
|
|
|
|
long symcount;
|
|
|
|
|
|
|
|
symbol_table = (asymbol **) xmalloc (storage_needed);
|
|
|
|
make_cleanup (xfree, symbol_table);
|
|
|
|
symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
|
|
|
|
|
|
|
|
if (symcount < 0)
|
|
|
|
error (_("Can't read symbols from %s: %s"),
|
|
|
|
bfd_get_filename (objfile->obfd),
|
|
|
|
bfd_errmsg (bfd_get_error ()));
|
|
|
|
|
|
|
|
macho_symtab_read (objfile, symcount, symbol_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
install_minimal_symbols (objfile);
|
|
|
|
|
2009-02-04 08:47:56 +00:00
|
|
|
/* Try to read .eh_frame / .debug_frame. */
|
|
|
|
/* First, locate these sections. We ignore the result status
|
|
|
|
as it only checks for debug info. */
|
2011-05-26 07:47:10 +00:00
|
|
|
dwarf2_has_info (objfile, NULL);
|
2009-02-04 08:47:56 +00:00
|
|
|
dwarf2_build_frame_info (objfile);
|
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
/* Check for DSYM file. */
|
|
|
|
dsym_bfd = macho_check_dsym (objfile);
|
|
|
|
if (dsym_bfd != NULL)
|
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
oso_el *oso;
|
2009-12-15 09:56:23 +00:00
|
|
|
struct bfd_section *asect, *dsect;
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
if (mach_o_debug_level > 0)
|
|
|
|
printf_unfiltered (_("dsym file found\n"));
|
|
|
|
|
|
|
|
/* Remove oso. They won't be used. */
|
|
|
|
for (ix = 0; VEC_iterate (oso_el, oso_vector, ix, oso); ix++)
|
|
|
|
{
|
|
|
|
xfree (oso->symbols);
|
|
|
|
xfree (oso->offsets);
|
|
|
|
}
|
|
|
|
VEC_free (oso_el, oso_vector);
|
|
|
|
oso_vector = NULL;
|
|
|
|
|
2009-12-15 09:56:23 +00:00
|
|
|
/* Set dsym section size. */
|
|
|
|
for (asect = objfile->obfd->sections, dsect = dsym_bfd->sections;
|
|
|
|
asect && dsect;
|
|
|
|
asect = asect->next, dsect = dsect->next)
|
|
|
|
{
|
|
|
|
if (strcmp (asect->name, dsect->name) != 0)
|
|
|
|
break;
|
|
|
|
bfd_set_section_size (dsym_bfd, dsect,
|
|
|
|
bfd_get_section_size (asect));
|
|
|
|
}
|
|
|
|
|
2009-12-09 14:53:25 +00:00
|
|
|
/* Add the dsym file as a separate file. */
|
|
|
|
symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
|
2008-11-27 09:23:01 +00:00
|
|
|
|
2009-02-04 08:47:56 +00:00
|
|
|
/* Don't try to read dwarf2 from main file or shared libraries. */
|
2009-12-09 14:53:25 +00:00
|
|
|
return;
|
2008-11-27 09:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 07:47:10 +00:00
|
|
|
if (dwarf2_has_info (objfile, NULL))
|
2008-11-27 09:23:01 +00:00
|
|
|
{
|
|
|
|
/* DWARF 2 sections */
|
2009-12-02 11:44:35 +00:00
|
|
|
dwarf2_build_psymtabs (objfile);
|
2008-11-27 09:23:01 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 08:47:56 +00:00
|
|
|
/* Do not try to read .eh_frame/.debug_frame as they are not relocated
|
|
|
|
and dwarf2_build_frame_info cannot deal with unrelocated sections. */
|
2008-11-27 09:23:01 +00:00
|
|
|
|
|
|
|
/* Then the oso. */
|
|
|
|
if (oso_vector != NULL)
|
2010-02-04 12:45:49 +00:00
|
|
|
macho_symfile_read_all_oso (objfile, symfile_flags);
|
2008-11-27 09:23:01 +00:00
|
|
|
}
|
|
|
|
|
2010-02-09 15:53:00 +00:00
|
|
|
static bfd_byte *
|
|
|
|
macho_symfile_relocate (struct objfile *objfile, asection *sectp,
|
|
|
|
bfd_byte *buf)
|
|
|
|
{
|
|
|
|
bfd *abfd = objfile->obfd;
|
|
|
|
|
|
|
|
/* We're only interested in sections with relocation
|
|
|
|
information. */
|
|
|
|
if ((sectp->flags & SEC_RELOC) == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (mach_o_debug_level > 0)
|
|
|
|
printf_unfiltered (_("Relocate section '%s' of %s\n"),
|
|
|
|
sectp->name, objfile->name);
|
|
|
|
|
|
|
|
if (current_oso.symbol_table == NULL)
|
|
|
|
{
|
|
|
|
int storage;
|
|
|
|
int i;
|
|
|
|
char leading_char;
|
|
|
|
|
|
|
|
storage = bfd_get_symtab_upper_bound (abfd);
|
|
|
|
current_oso.symbol_table = (asymbol **) xmalloc (storage);
|
|
|
|
bfd_canonicalize_symtab (abfd, current_oso.symbol_table);
|
|
|
|
|
|
|
|
leading_char = bfd_get_symbol_leading_char (abfd);
|
|
|
|
|
|
|
|
for (i = 0; current_oso.symbol_table[i]; i++)
|
|
|
|
{
|
|
|
|
asymbol *sym = current_oso.symbol_table[i];
|
|
|
|
|
|
|
|
if (bfd_is_com_section (sym->section))
|
|
|
|
{
|
|
|
|
/* This one must be solved. */
|
|
|
|
struct minimal_symbol *msym;
|
|
|
|
const char *name = sym->name;
|
|
|
|
|
|
|
|
if (name[0] == leading_char)
|
|
|
|
name++;
|
|
|
|
|
|
|
|
msym = lookup_minimal_symbol
|
|
|
|
(name, NULL, current_oso.main_objfile);
|
|
|
|
if (msym == NULL)
|
|
|
|
{
|
|
|
|
warning (_("can't find symbol '%s' in minsymtab"), name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sym->section = &bfd_abs_section;
|
|
|
|
sym->value = SYMBOL_VALUE_ADDRESS (msym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
|
|
|
|
}
|
|
|
|
|
2008-11-27 09:23:01 +00:00
|
|
|
static void
|
|
|
|
macho_symfile_finish (struct objfile *objfile)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
macho_symfile_offsets (struct objfile *objfile,
|
|
|
|
struct section_addr_info *addrs)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int num_sections;
|
|
|
|
struct obj_section *osect;
|
|
|
|
|
|
|
|
/* Allocate section_offsets. */
|
|
|
|
objfile->num_sections = bfd_count_sections (objfile->obfd);
|
|
|
|
objfile->section_offsets = (struct section_offsets *)
|
|
|
|
obstack_alloc (&objfile->objfile_obstack,
|
|
|
|
SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
|
|
|
|
memset (objfile->section_offsets, 0,
|
|
|
|
SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
|
|
|
|
|
|
|
|
/* This code is run when we first add the objfile with
|
|
|
|
symfile_add_with_addrs_or_offsets, when "addrs" not "offsets" are
|
|
|
|
passed in. The place in symfile.c where the addrs are applied
|
|
|
|
depends on the addrs having section names. But in the dyld code
|
|
|
|
we build an anonymous array of addrs, so that code is a no-op.
|
|
|
|
Because of that, we have to apply the addrs to the sections here.
|
|
|
|
N.B. if an objfile slides after we've already created it, then it
|
|
|
|
goes through objfile_relocate. */
|
|
|
|
|
|
|
|
for (i = 0; i < addrs->num_sections; i++)
|
|
|
|
{
|
|
|
|
if (addrs->other[i].name == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ALL_OBJFILE_OSECTIONS (objfile, osect)
|
|
|
|
{
|
|
|
|
const char *bfd_sect_name = osect->the_bfd_section->name;
|
|
|
|
|
|
|
|
if (strcmp (bfd_sect_name, addrs->other[i].name) == 0)
|
|
|
|
{
|
|
|
|
obj_section_offset (osect) = addrs->other[i].addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
objfile->sect_index_text = 0;
|
|
|
|
|
|
|
|
ALL_OBJFILE_OSECTIONS (objfile, osect)
|
|
|
|
{
|
|
|
|
const char *bfd_sect_name = osect->the_bfd_section->name;
|
|
|
|
int sect_index = osect->the_bfd_section->index;
|
2009-02-04 08:47:56 +00:00
|
|
|
|
|
|
|
if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
|
|
|
|
bfd_sect_name += 11;
|
|
|
|
if (strcmp (bfd_sect_name, "__TEXT") == 0
|
|
|
|
|| strcmp (bfd_sect_name, "__TEXT.__text") == 0)
|
2008-11-27 09:23:01 +00:00
|
|
|
objfile->sect_index_text = sect_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-30 19:14:30 +00:00
|
|
|
static const struct sym_fns macho_sym_fns = {
|
2008-11-27 09:23:01 +00:00
|
|
|
bfd_target_mach_o_flavour,
|
|
|
|
|
2011-01-05 22:22:53 +00:00
|
|
|
macho_new_init, /* init anything gbl to entire symtab */
|
|
|
|
macho_symfile_init, /* read initial info, setup for sym_read() */
|
|
|
|
macho_symfile_read, /* read a symbol file into symtab */
|
2011-03-07 16:17:29 +00:00
|
|
|
NULL, /* sym_read_psymbols */
|
2011-01-05 22:22:53 +00:00
|
|
|
macho_symfile_finish, /* finished with file, cleanup */
|
|
|
|
macho_symfile_offsets, /* xlate external to internal form */
|
|
|
|
default_symfile_segments, /* Get segment information from a file. */
|
|
|
|
NULL,
|
|
|
|
macho_symfile_relocate, /* Relocate a debug section. */
|
2010-09-30 19:14:30 +00:00
|
|
|
&psym_functions
|
2008-11-27 09:23:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_initialize_machoread ()
|
|
|
|
{
|
|
|
|
add_symtab_fns (&macho_sym_fns);
|
|
|
|
|
|
|
|
add_setshow_zinteger_cmd ("mach-o", class_obscure,
|
2011-01-05 22:22:53 +00:00
|
|
|
&mach_o_debug_level,
|
|
|
|
_("Set if printing Mach-O symbols processing."),
|
|
|
|
_("Show if printing Mach-O symbols processing."),
|
|
|
|
NULL, NULL, NULL,
|
2008-11-27 09:23:01 +00:00
|
|
|
&setdebuglist, &showdebuglist);
|
|
|
|
}
|