25 #include "elf/common.h"
26 #include "elf/internal.h"
37 #include "filenames.h"
52 extern const struct sym_fns elf_sym_fns_gdb_index;
53 extern const struct sym_fns elf_sym_fns_lazy_psyms;
74 #define SYMBOL_GOT_PLT_SUFFIX "@got.plt"
81 Elf_Internal_Phdr *phdrs, **segments;
87 phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
91 phdrs = alloca (phdrs_size);
92 num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
97 segments = alloca (
sizeof (Elf_Internal_Phdr *) * num_phdrs);
98 for (i = 0; i < num_phdrs; i++)
99 if (phdrs[i].p_type == PT_LOAD)
100 segments[num_segments++] = &phdrs[i];
102 if (num_segments == 0)
116 num_sections = bfd_count_sections (abfd);
119 for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
124 if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
127 vma = bfd_get_section_vma (abfd, sect);
130 if (segments[j]->p_memsz > 0
131 && vma >= segments[j]->p_vaddr
132 && (vma - segments[j]->p_vaddr) < segments[j]->p_memsz)
147 if (bfd_get_section_size (sect) > 0 && j == num_segments
148 && (bfd_get_section_flags (abfd, sect) & SEC_LOAD) != 0)
149 warning (
_(
"Loadable section \"%s\" outside of ELF segments"),
150 bfd_section_name (abfd, sect));
181 if (strcmp (sectp->name,
".stab") == 0)
185 else if (strcmp (sectp->name,
".mdebug") == 0)
224 #define ST_SYNTHETIC 2
228 long number_of_symbols, asymbol **symbol_table,
239 const char *filesymname =
"";
241 int stripped = (bfd_get_symcount (objfile->
obfd) == 0);
242 int elf_make_msymbol_special_p
245 for (i = 0; i < number_of_symbols; i++)
247 sym = symbol_table[i];
248 if (sym->name == NULL || *sym->name ==
'\0')
258 if (bfd_is_target_special_symbol (objfile->
obfd, sym))
268 && sym->section == bfd_und_section_ptr
269 && (sym->flags & BSF_FUNCTION))
272 bfd *abfd = objfile->
obfd;
283 symaddr = sym->value;
291 for (sect = abfd->sections; sect != NULL; sect = sect->next)
293 if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
296 if (symaddr >= bfd_get_section_vma (abfd, sect)
297 && symaddr < bfd_get_section_vma (abfd, sect)
298 + bfd_get_section_size (sect))
318 && bfd_get_section_by_name (abfd,
".plt") != NULL)
322 (sym->name, strlen (sym->name), copy_names,
327 if (elf_make_msymbol_special_p)
338 if (sym->flags & BSF_FILE)
340 filesymname =
bcache (sym->name, strlen (sym->name) + 1,
343 else if (sym->flags & BSF_SECTION_SYM)
345 else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK
354 symaddr = sym->value + sym->section->vma;
358 if (sym->section == bfd_abs_section_ptr)
367 ((elf_symbol_type *) sym)->internal_elf_sym.st_shndx;
377 case SHN_MIPS_ACOMMON:
388 if (sym->name[0] ==
'.')
392 else if (sym->section->flags & SEC_CODE)
394 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
396 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
404 else if ((sym->name[0] ==
'.' && sym->name[1] ==
'L'
405 && (sym->flags & BSF_SYNTHETIC) == 0)
406 || ((sym->flags & BSF_LOCAL)
407 && sym->name[0] ==
'$'
408 && sym->name[1] ==
'L'))
422 else if (sym->section->flags & SEC_ALLOC)
424 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
426 if (sym->section->flags & SEC_LOAD)
435 else if (sym->flags & BSF_LOCAL)
437 if (sym->section->flags & SEC_LOAD)
461 (sym->name, strlen (sym->name), copy_names, symaddr,
462 ms_type, sym->section, objfile);
471 elf_symbol_type *elf_sym = (elf_symbol_type *) sym;
476 if (elf_make_msymbol_special_p)
484 const char *atsign = strchr (sym->name,
'@');
486 if (atsign != NULL && atsign[1] ==
'@' && atsign > sym->name)
488 int len = atsign - sym->name;
491 ms_type, sym->section, objfile);
501 int len = strlen (sym->name);
503 if (len > 4 && strcmp (sym->name + len - 4,
"@plt") == 0)
510 sym->section, objfile);
516 if (elf_make_msymbol_special_p)
536 bfd *obfd = objfile->
obfd;
537 const struct elf_backend_data *bed = get_elf_backend_data (obfd);
538 asection *plt, *relplt, *got_plt;
540 bfd_size_type reloc_count, reloc;
541 char *string_buffer = NULL;
542 size_t string_buffer_size = 0;
551 plt = bfd_get_section_by_name (obfd,
".plt");
554 plt_elf_idx = elf_section_data (plt)->this_idx;
556 got_plt = bfd_get_section_by_name (obfd,
".got.plt");
560 got_plt = bfd_get_section_by_name (obfd,
".got");
566 for (relplt = obfd->sections; relplt != NULL; relplt = relplt->next)
567 if (elf_section_data (relplt)->this_hdr.sh_info == plt_elf_idx
568 && (elf_section_data (relplt)->this_hdr.sh_type == SHT_REL
569 || elf_section_data (relplt)->this_hdr.sh_type == SHT_RELA))
574 if (! bed->s->slurp_reloc_table (obfd, relplt, dyn_symbol_table, TRUE))
579 reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
580 for (reloc = 0; reloc < reloc_count; reloc++)
588 name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
589 name_len = strlen (name);
590 address = relplt->relocation[reloc].address;
593 if (!(bfd_get_section_vma (obfd, got_plt) <= address
594 && address < bfd_get_section_vma (obfd, got_plt)
595 + bfd_get_section_size (got_plt)))
602 if (string_buffer_size < name_len + got_suffix_len + 1)
604 string_buffer_size = 2 * (name_len + got_suffix_len);
605 string_buffer =
xrealloc (string_buffer, string_buffer_size);
607 memcpy (string_buffer, name, name_len);
642 return htab_hash_string (a->
name);
653 return strcmp (a->
name, b->
name) == 0;
686 if (strcmp (bfd_get_section_name (objfile->
obfd, sect),
".plt") == 0)
706 slot = htab_find_slot (htab, entry_p, INSERT);
712 if (entry_found_p->
addr != addr)
717 warning (
_(
"gnu-indirect-function \"%s\" has changed its resolved "
718 "function_address from %s to %s"),
752 entry_p = alloca (
sizeof (*entry_p) + strlen (name));
753 strcpy (entry_p->
name, name);
755 slot = htab_find_slot (htab, entry_p, NO_INSERT);
762 *addr_p = entry_p->
addr;
784 name_got_plt = alloca (strlen (name) + got_suffix_len + 1);
799 if (msym.minsym == NULL)
805 plt = bfd_get_section_by_name (obfd,
".plt");
854 const char *name_at_pc;
857 struct value *
function, *address_val;
862 && start_at_pc == pc)
908 if (b_return->
thread == thread_id
949 struct value *func_func;
970 _(
"handle_inferior_event: Invalid "
971 "gnu-indirect-function breakpoint type %d"),
1010 bfd *synth_abfd, *abfd = objfile->
obfd;
1012 long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
1013 asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
1020 "Reading minimal symbols of objfile %s ...\n",
1035 "... minimal symbols previously read\n");
1048 storage_needed = bfd_get_symtab_upper_bound (objfile->
obfd);
1049 if (storage_needed < 0)
1050 error (
_(
"Can't read symbols from %s: %s"),
1051 bfd_get_filename (objfile->
obfd),
1052 bfd_errmsg (bfd_get_error ()));
1054 if (storage_needed > 0)
1059 symbol_table = bfd_alloc (abfd, storage_needed);
1060 symcount = bfd_canonicalize_symtab (objfile->
obfd, symbol_table);
1063 error (
_(
"Can't read symbols from %s: %s"),
1064 bfd_get_filename (objfile->
obfd),
1065 bfd_errmsg (bfd_get_error ()));
1072 storage_needed = bfd_get_dynamic_symtab_upper_bound (objfile->
obfd);
1074 if (storage_needed > 0)
1083 dyn_symbol_table = bfd_alloc (abfd, storage_needed);
1084 dynsymcount = bfd_canonicalize_dynamic_symtab (objfile->
obfd,
1087 if (dynsymcount < 0)
1088 error (
_(
"Can't read symbols from %s: %s"),
1089 bfd_get_filename (objfile->
obfd),
1090 bfd_errmsg (bfd_get_error ()));
1116 synthcount = bfd_get_synthetic_symtab (synth_abfd, symcount, symbol_table,
1117 dynsymcount, dyn_symbol_table,
1121 asymbol **synth_symbol_table;
1125 synth_symbol_table =
xmalloc (
sizeof (asymbol *) * synthcount);
1126 for (i = 0; i < synthcount; i++)
1127 synth_symbol_table[i] = synthsyms + i;
1130 synth_symbol_table, 1);
1173 bfd *abfd = objfile->
obfd;
1176 memset ((
char *) &ei, 0,
sizeof (ei));
1195 const struct ecoff_debug_swap *swap;
1199 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1209 str_sect = bfd_get_section_by_name (abfd,
".stabstr");
1216 bfd_section_size (abfd, str_sect));
1257 if (debugfile == NULL)
1327 if (!probes_per_bfd)
1336 probe_ops->
get_probes (&probes_per_bfd, objfile);
1338 if (probes_per_bfd == NULL)
1347 return probes_per_bfd;
int frame_id_p(struct frame_id l)
const void * bcache(const void *addr, int length, struct bcache *cache)
struct value * call_function_by_hand(struct value *function, int nargs, struct value **args)
void stabsread_new_init(void)
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
int dwarf2_has_info(struct objfile *objfile, const struct dwarf2_debug_sections *names)
void objfile_set_sym_fns(struct objfile *objfile, const struct sym_fns *sf)
CORE_ADDR get_frame_pc(struct frame_info *frame)
struct frame_info * get_current_frame(void)
static struct symfile_segment_data * elf_symfile_segments(bfd *abfd)
char * find_separate_debug_file_by_buildid(struct objfile *objfile)
struct regcache * get_thread_regcache(ptid_t ptid)
int gdb_bfd_section_index(bfd *abfd, asection *section)
struct objfile * separate_debug_objfile_backlink
static void elf_symtab_read(struct objfile *objfile, int type, long number_of_symbols, asymbol **symbol_table, int copy_names)
void dummy_obstack_deallocate(void *object, void *data)
struct frame_info * get_prev_frame(struct frame_info *this_frame)
#define BMSYMBOL_VALUE_ADDRESS(symbol)
void warning(const char *fmt,...)
CORE_ADDR * segment_bases
static const struct bfd_data * probe_key
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
static int elf_gnu_ifunc_record_cache(const char *name, CORE_ADDR addr)
struct frame_id get_stack_frame_id(struct frame_info *next_frame)
static const struct sym_probe_fns elf_probe_fns
void internal_error(const char *file, int line, const char *fmt,...)
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *sf)
struct type * builtin_func_func
void init_sal(struct symtab_and_line *sal)
const struct gnu_ifunc_fns * gnu_ifunc_fns_p
static void probe_key_free(bfd *abfd, void *d)
static int elf_gnu_ifunc_resolve_by_cache(const char *name, CORE_ADDR *addr_p)
void(* get_probes)(VEC(probe_p)**probes, struct objfile *objfile)
#define SYMBOL_GOT_PLT_SUFFIX
void dwarf2_build_psymtabs(struct objfile *objfile)
struct obj_section * section
static const struct gnu_ifunc_fns elf_gnu_ifunc_fns
struct objfile_per_bfd_storage * per_bfd
struct value * allocate_value(struct type *type)
void gdbarch_elf_make_msymbol_special(struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static int elf_gnu_ifunc_cache_eq(const void *a_voidp, const void *b_voidp)
struct obj_section * find_pc_overlay(CORE_ADDR pc)
struct program_space * pspace
void set_value_address(struct value *value, CORE_ADDR addr)
#define MSYMBOL_OBJ_SECTION(objfile, symbol)
struct obstack objfile_obstack
static void elf_rel_plt_read(struct objfile *objfile, asymbol **dyn_symbol_table)
int frame_id_eq(struct frame_id l, struct frame_id r)
int objfile_has_partial_symbols(struct objfile *objfile)
static void elf_read_minimal_symbols(struct objfile *objfile, int symfile_flags, const struct elfinfo *ei)
#define VEC_iterate(T, V, I, P)
unsigned int created_by_gdb
bfd_byte * default_symfile_relocate(struct objfile *objfile, asection *sectp, bfd_byte *buf)
int gdbarch_record_special_symbol_p(struct gdbarch *gdbarch)
struct bp_location * next
int dwarf2_initialize_objfile(struct objfile *objfile)
static void read_psyms(struct objfile *objfile)
#define VEC_reserve(T, V, R)
static struct minimal_symbol * record_minimal_symbol(const char *name, int name_len, int copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, asection *bfd_section, struct objfile *objfile)
void dwarf2_free_objfile(struct objfile *objfile)
struct target_ops current_target
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
static void elf_symfile_finish(struct objfile *objfile)
void symbol_file_add_separate(bfd *bfd, const char *name, int symfile_flags, struct objfile *objfile)
struct program_space * pspace
static void elf_locate_sections(bfd *ignore_abfd, asection *sectp, void *eip)
static void elf_gnu_ifunc_resolver_stop(struct breakpoint *b)
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
void free_current_contents(void *ptr)
#define MSYMBOL_SIZE(msymbol)
static int elf_gnu_ifunc_resolve_name(const char *name, CORE_ADDR *addr_p)
void buildsym_new_init(void)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static void elf_gnu_ifunc_resolver_return_stop(struct breakpoint *b)
#define ANOFFSET(secoff, whichone)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
static void elf_symfile_init(struct objfile *objfile)
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
struct objfile * separate_debug_objfile
static const struct objfile_data * elf_objfile_gnu_ifunc_cache_data
enum return_value_convention gdbarch_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
char * find_separate_debug_file_by_debuglink(struct objfile *objfile)
void _initialize_elfread(void)
static int startswith(const char *string, const char *pattern)
struct cleanup * make_cleanup_discard_minimal_symbols(void)
static void elf_symfile_read(struct objfile *objfile, int symfile_flags)
#define SET_MSYMBOL_SIZE(msymbol, sz)
void elfmdebug_build_psymtabs(struct objfile *objfile, const struct ecoff_debug_swap *swap, asection *sec)
const char * objfile_name(const struct objfile *objfile)
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
CORE_ADDR requested_address
struct ui_file * gdb_stdlog
bfd * symfile_bfd_open(const char *name)
struct breakpoint * set_momentary_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line sal, struct frame_id frame_id, enum bptype type)
void init_minimal_symbol_collection(void)
void gdbarch_record_special_symbol(struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym)
struct bcache * filename_cache
void * hashtab_obstack_allocate(void *data, size_t size, size_t count)
PTR xrealloc(PTR ptr, size_t size)
unsigned int minsyms_read
#define MSYMBOL_TYPE(msymbol)
static CORE_ADDR elf_gnu_ifunc_resolve_addr(struct gdbarch *gdbarch, CORE_ADDR pc)
#define TYPE_TARGET_TYPE(thistype)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
#define DBX_SYMFILE_INFO(o)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
CORE_ADDR related_address
struct type * builtin_data_ptr
struct minimal_symbol * minsym
const struct quick_symbol_functions psym_functions
void update_breakpoint_locations(struct breakpoint *b, struct symtabs_and_lines sals, struct symtabs_and_lines sals_end)
struct program_space * pspace
const struct quick_symbol_functions dwarf2_gdb_index_functions
int gdbarch_elf_make_msymbol_special_p(struct gdbarch *gdbarch)
void default_symfile_offsets(struct objfile *objfile, const struct section_addr_info *addrs)
struct breakpoint * related_breakpoint
struct inferior * current_inferior(void)
static int elf_gnu_ifunc_resolve_by_got(const char *name, CORE_ADDR *addr_p)
const struct probe_ops * pops
struct program_space * current_program_space
unsigned int symtab_create_debug
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
int pid_to_thread_id(ptid_t ptid)
#define obstack_grow_str0(OBSTACK, STRING)
struct type * value_type(const struct value *value)
void elfstab_build_psymtabs(struct objfile *objfile, asection *stabsect, file_ptr stabstroffset, unsigned int stabstrsize)
const struct objfile_data * dbx_objfile_data_key
static void elf_new_init(struct objfile *ignore)
CORE_ADDR value_as_address(struct value *val)
struct symtab_and_line * sals
gdb_byte * value_contents_raw(struct value *value)
#define TYPE_LENGTH(thistype)
static hashval_t elf_gnu_ifunc_cache_hash(const void *a_voidp)
struct section_offsets * section_offsets
void install_minimal_symbols(struct objfile *objfile)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
struct minimal_symbol * prim_record_minimal_symbol_full(const char *name, int name_len, int copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section, struct objfile *objfile)
CORE_ADDR * segment_sizes
#define ALL_PSPACE_OBJFILES(ss, obj)
void delete_breakpoint(struct breakpoint *bpt)
void error(const char *fmt,...)
void(* destroy)(struct probe *probe)
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
void do_cleanups(struct cleanup *old_chain)
char * copy_name(struct stoken token)
const ULONGEST const LONGEST len