53#include "gdbsupport/symbol.h"
55#include "safe-ctype.h"
56#include "gdbsupport/parallel-for.h"
75 size_t name_len = strlen (
name);
79 const char *last = &
name[name_len - 1];
83 const char *suffix =
" [clone .cold";
84 size_t suffix_len = strlen (suffix);
85 const char *found = strstr (
name, suffix);
89 const char *start = &found[suffix_len];
97 for (p = start + 1; p <= last; ++p)
99 if (*p >=
'0' && *p <=
'9')
114 CORE_ADDR *func_address_p)
118 switch (minsym->
type ())
133 if (func_address_p != NULL)
134 *func_address_p = pc;
145 if (func_address_p != NULL)
146 *func_address_p = msym_addr;
154#define BUNCH_SIZE 127
167 unsigned int hash = 0;
169 while (*
string && *
string !=
'(')
171 string = skip_spaces (
string);
172 if (*
string && *
string !=
'(')
186 unsigned int hash = 0;
188 for (; *string; ++string)
197 unsigned int hash_value)
213 unsigned int hash_value)
223 table[hash_index] = sym;
256 switch (msymbol->
type ())
262 || filename_cmp (msymbol->
filename, sfile) == 0)
303 int (*namecmp) (
const char *,
const char *),
310 const char *symbol_name = msymbol->linkage_name ();
312 if (namecmp (symbol_name, lookup_name) == 0
334 const char *symbol_name = msymbol->search_name ();
336 if (matcher (symbol_name, lookup_name, NULL)
376 sfile = lbasename (sfile);
385 if (objf == NULL || objf ==
objfile
389 name, sfile != NULL ? sfile :
"NULL",
396 mangled_hash, mangled_cmp, found);
420 msymbol_demangled_hash,
438 (
"lookup_minimal_symbol (...) = %s (external)",
439 host_address_to_string (minsym));
452 (
"lookup_minimal_symbol (...) = %s (file-local)",
453 host_address_to_string (minsym));
466 (
"lookup_minimal_symbol (...) = %s (trampoline)",
467 host_address_to_string (minsym));
498 return sym.
minsym == NULL;
517 return lookup_name.
c_str ();
538 iter = iter->hash_next)
540 if (mangled_cmp (iter->linkage_name (),
name) == 0)
563 iter = iter->demangled_hash_next)
564 if (name_match (iter->search_name (), lookup_name, NULL))
581 msymbol = msymbol->hash_next)
583 if (strcmp (msymbol->linkage_name (),
name) == 0
585 || msymbol->type () ==
mst_bss))
606 if (found_symbol.
minsym != NULL)
609 if (objf == NULL || objf ==
objfile
613 msymbol != NULL && found_symbol.
minsym == NULL;
621 switch (msymbol->
type ())
624 found_file_symbol.
minsym = msymbol;
628 found_symbol.
minsym = msymbol;
641 return found_file_symbol;
656 if (objf == NULL || objf ==
objfile
685 if (*pc >= iter->
addr () && *pc < iter->
endaddr ())
713 gdb_assert_not_reached (
"unhandled lookup_msym_prefer");
734 struct objfile *best_objfile = NULL;
737 if (previous !=
nullptr)
739 previous->
minsym =
nullptr;
761 gdb_assert (section != NULL);
765 CORE_ADDR pc = pc_in;
772 int best_zero_sized = -1;
803 newobj = (lo + hi) / 2;
818 while (hi < objfile->per_bfd->minimal_symbol_count - 1
864 && msymbol[hi].
type () != want_type
865 && msymbol[hi - 1].
type () == want_type
866 && (msymbol[hi].
size () == msymbol[hi - 1].
size ())
882 if (msymbol[hi].
size () == 0)
884 if (best_zero_sized == -1)
885 best_zero_sized = hi;
896 && msymbol[hi].
size () != 0
898 + msymbol[hi].
size ())
900 + msymbol[hi - 1].
size ()))
916 if (best_zero_sized != -1
917 && (hi < 0 || msymbol[hi].
size () == 0))
918 hi = best_zero_sized;
928 && msymbol[hi].
size () != 0
930 + msymbol[hi].
size ()))
932 if (best_zero_sized != -1)
933 hi = best_zero_sized;
938 if (previous !=
nullptr)
940 if (previous->
minsym ==
nullptr
944 previous->
minsym = &msymbol[hi];
998 error (_(
"GDB cannot resolve STT_GNU_IFUNC symbol at address %s without "
999 "the ELF support compiled in."),
1007 CORE_ADDR *function_address_p)
1009 error (_(
"GDB cannot resolve STT_GNU_IFUNC symbol \"%s\" without "
1010 "the ELF support compiled in."),
1019 internal_error (_(
"elf_gnu_ifunc_resolver_stop cannot be reached."));
1027 internal_error (_(
"elf_gnu_ifunc_resolver_return_stop cannot be reached."));
1053 return bfd_get_symbol_leading_char (abfd);
1057 if (objf->
obfd != NULL)
1058 return bfd_get_symbol_leading_char (objf->
obfd.get ());
1067 m_msym_bunch (NULL),
1130#define MST_TO_STR(x) case x: return #x;
1181 mst_str (ms_type), hex_string (address), section,
1240 return strcmp (name1, name2) < 0;
1286 copyfrom = copyto = msymbol;
1287 while (copyfrom < msymbol + mcount - 1)
1290 == (copyfrom + 1)->value_raw_address ()
1292 == (copyfrom + 1)->section_index ())
1294 (copyfrom + 1)->linkage_name ()) == 0)
1302 *copyto++ = *copyfrom++;
1304 *copyto++ = *copyfrom++;
1305 mcount = copyto - msymbol;
1341 const std::vector<computed_hash_values>& hash_values)
1355 hash_values[i].minsym_hash);
1360 (msym,
objfile, hash_values[i].minsym_demangled_hash);
1392 gdb::unique_xmalloc_ptr<minimal_symbol>
1394 msymbols = msym_holder.get ();
1413 memcpy (&msymbols[mcount], &bunch->
contents[0],
1428 msym_holder.release (),
1444 std::mutex demangled_mutex;
1447 std::vector<computed_hash_values> hash_values (mcount);
1451 gdb::parallel_for_each (10, &msymbols[0], &msymbols[mcount],
1456 size_t idx = msym - msymbols;
1457 hash_values[idx].name_length = strlen (msym->linkage_name ());
1458 if (!msym->name_set)
1461 gdb::unique_xmalloc_ptr<char> demangled_name
1463 msym->set_demangled_name
1464 (demangled_name.release (),
1471 hash_values[idx].mangled_name_hash
1473 hash_values[idx].name_length);
1474 hash_values[idx].minsym_hash
1479 if (msym->search_name () != msym->linkage_name ())
1480 hash_values[idx].minsym_demangled_hash
1487 std::lock_guard<std::mutex> guard (demangled_mutex);
1491 size_t idx = msym - msymbols;
1493 (gdb::string_view (msym->linkage_name (),
1494 hash_values[idx].name_length),
1497 hash_values[idx].mangled_name_hash);
1517 if (msymbol.
minsym != NULL
1538 if (tsymbol != NULL)
1550 && strcmp (msymbol->linkage_name (),
1576 gdb_assert (minsym.
minsym != NULL);
1594 for (iter = msymbol + 1; iter != past_the_end; ++iter)
1603 if (iter != past_the_end
bool best_symbol(struct symbol *a, const domain_enum domain)
const std::string & lookup_name() const
unsigned int search_name_hash(language lang) const
const char * c_str() const
const ada_lookup_name_info & ada() const
struct msym_bunch * m_msym_bunch
struct objfile * m_objfile
minimal_symbol_reader(struct objfile *)
struct minimal_symbol * record_full(gdb::string_view name, bool copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
void record_with_info(const char *name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
void record(const char *name, CORE_ADDR address, enum minimal_symbol_type ms_type)
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
struct inferior * current_inferior(void)
const struct language_defn * language_def(enum language lang)
const struct language_defn * current_language
bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR pc_in, struct obj_section *section, lookup_msym_prefer prefer, bound_minimal_symbol *previous)
static void add_minsym_to_demangled_hash_table(struct minimal_symbol *sym, struct objfile *objfile, unsigned int hash_value)
CORE_ADDR minimal_symbol_upper_bound(struct bound_minimal_symbol minsym)
static void build_minimal_symbol_hash_tables(struct objfile *objfile, const std::vector< computed_hash_values > &hash_values)
static bool minimal_symbol_is_less_than(const minimal_symbol &fn1, const minimal_symbol &fn2)
static const char * mst_str(minimal_symbol_type t)
bound_minimal_symbol lookup_minimal_symbol_linkage(const char *name, struct objfile *objf)
static bool stub_gnu_ifunc_resolve_name(const char *function_name, CORE_ADDR *function_address_p)
static const char * linkage_name_str(const lookup_name_info &lookup_name)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
static struct minimal_symbol * lookup_solib_trampoline_symbol_by_pc(CORE_ADDR pc)
static int get_symbol_leading_char(bfd *abfd)
static void stub_gnu_ifunc_resolver_return_stop(code_breakpoint *b)
static void clear_minimal_symbol_hash_tables(struct objfile *objfile)
CORE_ADDR find_solib_trampoline_target(frame_info_ptr frame, CORE_ADDR pc)
struct bound_minimal_symbol lookup_bound_minimal_symbol(const char *name)
unsigned int msymbol_hash_iw(const char *string)
const struct gnu_ifunc_fns * gnu_ifunc_fns_p
int find_minimal_symbol_address(const char *name, CORE_ADDR *addr, struct objfile *objfile)
static bool msymbol_is_cold_clone(minimal_symbol *minsym)
static CORE_ADDR stub_gnu_ifunc_resolve_addr(struct gdbarch *gdbarch, CORE_ADDR pc)
static int compact_minimal_symbols(struct minimal_symbol *msymbol, int mcount, struct objfile *objfile)
static void stub_gnu_ifunc_resolver_stop(code_breakpoint *b)
static void add_minsym_to_hash_table(struct minimal_symbol *sym, struct minimal_symbol **table, unsigned int hash_value)
unsigned int msymbol_hash(const char *string)
void iterate_over_minimal_symbols(struct objfile *objf, const lookup_name_info &lookup_name, gdb::function_view< bool(struct minimal_symbol *)> callback)
static int frob_address(struct objfile *objfile, CORE_ADDR *pc)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
struct minimal_symbol * lookup_minimal_symbol_by_pc_name(CORE_ADDR pc, const char *name, struct objfile *objf)
struct bound_minimal_symbol lookup_minimal_symbol_text(const char *name, struct objfile *objf)
bool in_gnu_ifunc_stub(CORE_ADDR pc)
static void lookup_minimal_symbol_mangled(const char *lookup_name, const char *sfile, struct objfile *objfile, struct minimal_symbol **table, unsigned int hash, int(*namecmp)(const char *, const char *), found_minimal_symbols &found)
static minimal_symbol_type msym_prefer_to_msym_type(lookup_msym_prefer prefer)
bool msymbol_is_function(struct objfile *objfile, minimal_symbol *minsym, CORE_ADDR *func_address_p)
static const struct gnu_ifunc_fns stub_gnu_ifunc_fns
static void lookup_minimal_symbol_demangled(const lookup_name_info &lookup_name, const char *sfile, struct objfile *objfile, struct minimal_symbol **table, unsigned int hash, symbol_name_matcher_ftype *matcher, found_minimal_symbols &found)
unsigned int msymbol_hash(const char *)
#define SYMBOL_HASH_NEXT(hash, c)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR pc_in, struct obj_section *section, lookup_msym_prefer prefer=lookup_msym_prefer::TEXT, bound_minimal_symbol *previous=nullptr)
const char * objfile_debug_name(const struct objfile *objfile)
struct obj_section * find_pc_section(CORE_ADDR pc)
const char * objfile_name(const struct objfile *objfile)
#define MINIMAL_SYMBOL_HASH_SIZE
#define SECT_OFF_BSS(objfile)
#define SECT_OFF_DATA(objfile)
#define SECT_OFF_TEXT(objfile)
#define ALL_OBJFILE_OSECTIONS(objfile, osect)
std::string copy_name(struct stoken token)
struct program_space * current_program_space
static void set_type(type_object *obj, struct type *type)
void(* func)(remote_target *remote, char *)
CORE_ADDR value_address() const
struct minimal_symbol * minsym
struct obj_section * obj_section() const
unsigned int minsym_demangled_hash
hashval_t mangled_name_hash
bound_minimal_symbol file_symbol
bound_minimal_symbol external_symbol
bool maybe_collect(const char *sfile, objfile *objf, minimal_symbol *msymbol)
bound_minimal_symbol trampoline_symbol
void set_section_index(short idx)
const char * natural_name() const
void set_value_address(CORE_ADDR address)
void compute_and_set_names(gdb::string_view linkage_name, bool copy_name, struct objfile_per_bfd_storage *per_bfd, gdb::optional< hashval_t > hash=gdb::optional< hashval_t >())
const char * search_name() const
enum language language() const
void set_language(enum language language, struct obstack *obstack)
short section_index() const
struct obj_section * obj_section(const struct objfile *objfile) const
const char * linkage_name() const
enum language la_language
symbol_name_matcher_ftype * get_symbol_name_matcher(const lookup_name_info &lookup_name) const
void set_type(minimal_symbol_type type)
struct minimal_symbol * hash_next
struct minimal_symbol * demangled_hash_next
unsigned long size() const
CORE_ADDR value_raw_address() const
minimal_symbol_type type() const
CORE_ADDR value_address(objfile *objfile) const
struct minimal_symbol contents[BUNCH_SIZE]
CORE_ADDR endaddr() const
minimal_symbol * msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE]
auto_obstack storage_obstack
minimal_symbol * msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE]
std::bitset< nr_languages > demangled_hash_languages
gdb::unique_xmalloc_ptr< minimal_symbol > msymbols
struct objfile * separate_debug_objfile_backlink
struct gdbarch * arch() const
struct objfile_per_bfd_storage * per_bfd
separate_debug_range separate_debug_objfiles()
msymbols_range msymbols()
objfiles_range objfiles()
struct objfile * symfile_object_file
gdb::unique_xmalloc_ptr< char > symbol_find_demangled_name(struct general_symbol_info *gsymbol, const char *mangled)
bool matching_obj_sections(struct obj_section *obj_first, struct obj_section *obj_second)
unsigned int symbol_lookup_debug
unsigned int search_name_hash(enum language language, const char *search_name)
#define GCC_COMPILED_FLAG_SYMBOL
bool() symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
#define GCC2_COMPILED_FLAG_SYMBOL
#define symbol_lookup_debug_printf(fmt,...)
#define symtab_create_debug_printf_v(fmt,...)
#define symtab_create_debug_printf(fmt,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static unsigned int fast_hash(const void *ptr, size_t len, unsigned int start_value=0)
CORE_ADDR value_raw_address(const struct value *value)