/* GDB routines for manipulating the minimal symbol tables.
- Copyright (C) 1992-2019 Free Software Foundation, Inc.
+ Copyright (C) 1992-2021 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
This file is part of GDB.
case mst_file_bss:
case mst_data_gnu_ifunc:
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ struct gdbarch *gdbarch = objfile->arch ();
CORE_ADDR pc
= gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr,
current_top_target ());
% MINIMAL_SYMBOL_HASH_SIZE);
symbol_name_matcher_ftype *match
- = get_symbol_name_matcher (language_def (lang),
- lookup_name);
+ = language_def (lang)->get_symbol_name_matcher
+ (lookup_name);
struct minimal_symbol **msymbol_demangled_hash
= objfile->per_bfd->msymbol_demangled_hash;
if (current_language->la_language == language_ada)
return lookup_name.ada ().lookup_name ().c_str ();
- return lookup_name.name ().c_str ();
+ return lookup_name.c_str ();
}
/* See minsyms.h. */
enum language lang = (enum language) liter;
const language_defn *lang_def = language_def (lang);
symbol_name_matcher_ftype *name_match
- = get_symbol_name_matcher (lang_def, lookup_name);
+ = lang_def->get_symbol_name_matcher (lookup_name);
unsigned int hash
= lookup_name.search_name_hash (lang) % MINIMAL_SYMBOL_HASH_SIZE;
gdb_assert_not_reached ("unhandled lookup_msym_prefer");
}
-/* Search through the minimal symbol table for each objfile and find
- the symbol whose address is the largest address that is still less
- than or equal to PC, and matches SECTION (which is not NULL).
- Returns a pointer to the minimal symbol if such a symbol is found,
- or NULL if PC is not in a suitable range.
+/* See minsyms.h.
+
Note that we need to look through ALL the minimal symbol tables
before deciding on the symbol that comes closest to the specified PC.
This is because objfiles can overlap, for example objfile A has .text
at 0x100 and .data at 0x40000 and objfile B has .text at 0x234 and
- .data at 0x40048.
-
- If WANT_TRAMPOLINE is set, prefer mst_solib_trampoline symbols when
- there are text and trampoline symbols at the same address.
- Otherwise prefer mst_text symbols. */
+ .data at 0x40048. */
bound_minimal_symbol
lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *section,
- lookup_msym_prefer prefer)
+ lookup_msym_prefer prefer,
+ bound_minimal_symbol *previous)
{
int lo;
int hi;
struct objfile *best_objfile = NULL;
struct bound_minimal_symbol result;
+ if (previous != nullptr)
+ {
+ previous->minsym = nullptr;
+ previous->objfile = nullptr;
+ }
+
if (section == NULL)
{
section = find_pc_section (pc_in);
CORE_ADDR pc = pc_in;
/* If this objfile has a minimal symbol table, go search it
- using a binary search. */
+ using a binary search. */
if (objfile->per_bfd->minimal_symbol_count > 0)
{
int best_zero_sized = -1;
- msymbol = objfile->per_bfd->msymbols.get ();
+ msymbol = objfile->per_bfd->msymbols.get ();
lo = 0;
hi = objfile->per_bfd->minimal_symbol_count - 1;
}
/* If we have multiple symbols at the same address, we want
- hi to point to the last one. That way we can find the
- right symbol if it has an index greater than hi. */
+ hi to point to the last one. That way we can find the
+ right symbol if it has an index greater than hi. */
while (hi < objfile->per_bfd->minimal_symbol_count - 1
&& (MSYMBOL_VALUE_RAW_ADDRESS (&msymbol[hi])
== MSYMBOL_VALUE_RAW_ADDRESS (&msymbol[hi + 1])))
/* Some types of debug info, such as COFF,
don't fill the bfd_section member, so don't
throw away symbols on those platforms. */
- && MSYMBOL_OBJ_SECTION (objfile, &msymbol[hi]) != NULL
+ && msymbol[hi].obj_section (objfile) != nullptr
&& (!matching_obj_sections
- (MSYMBOL_OBJ_SECTION (objfile, &msymbol[hi]),
+ (msymbol[hi].obj_section (objfile),
section)))
{
hi--;
== MSYMBOL_SIZE (&msymbol[hi - 1]))
&& (MSYMBOL_VALUE_RAW_ADDRESS (&msymbol[hi])
== MSYMBOL_VALUE_RAW_ADDRESS (&msymbol[hi - 1]))
- && (MSYMBOL_OBJ_SECTION (objfile, &msymbol[hi])
- == MSYMBOL_OBJ_SECTION (objfile, &msymbol[hi - 1])))
+ && (msymbol[hi].obj_section (objfile)
+ == msymbol[hi - 1].obj_section (objfile)))
{
hi--;
continue;
if (best_zero_sized != -1)
hi = best_zero_sized;
else
- /* Go on to the next object file. */
- continue;
+ {
+ /* If needed record this symbol as the closest
+ previous symbol. */
+ if (previous != nullptr)
+ {
+ if (previous->minsym == nullptr
+ || (MSYMBOL_VALUE_RAW_ADDRESS (&msymbol[hi])
+ > MSYMBOL_VALUE_RAW_ADDRESS
+ (previous->minsym)))
+ {
+ previous->minsym = &msymbol[hi];
+ previous->objfile = objfile;
+ }
+ }
+ /* Go on to the next object file. */
+ continue;
+ }
}
/* The minimal symbol indexed by hi now is the best one in this
- objfile's minimal symbol table. See if it is the best one
- overall. */
+ objfile's minimal symbol table. See if it is the best one
+ overall. */
if (hi >= 0
&& ((best_symbol == NULL) ||
{
if (abfd != NULL)
return bfd_get_symbol_leading_char (abfd);
- if (symfile_objfile != NULL && symfile_objfile->obfd != NULL)
- return bfd_get_symbol_leading_char (symfile_objfile->obfd);
+ if (current_program_space->symfile_object_file != NULL)
+ {
+ objfile *objf = current_program_space->symfile_object_file;
+ if (objf->obfd != NULL)
+ return bfd_get_symbol_leading_char (objf->obfd);
+ }
return 0;
}
if (symtab_create_debug >= 2)
printf_unfiltered ("Recording minsym: %-21s %18s %4d %.*s\n",
- mst_str (ms_type), hex_string (address), section,
+ mst_str (ms_type), hex_string (address), section,
(int) name.size (), name.data ());
if (m_msym_bunch_index == BUNCH_SIZE)
msymbol->m_name = name.data ();
SET_MSYMBOL_VALUE_ADDRESS (msymbol, address);
- MSYMBOL_SECTION (msymbol) = section;
+ msymbol->set_section_index (section);
MSYMBOL_TYPE (msymbol) = ms_type;
{
if (MSYMBOL_VALUE_RAW_ADDRESS (copyfrom)
== MSYMBOL_VALUE_RAW_ADDRESS ((copyfrom + 1))
- && MSYMBOL_SECTION (copyfrom) == MSYMBOL_SECTION (copyfrom + 1)
+ && (copyfrom->section_index ()
+ == (copyfrom + 1)->section_index ())
&& strcmp (copyfrom->linkage_name (),
(copyfrom + 1)->linkage_name ()) == 0)
{
}
/* Allocate enough space, into which we will gather the bunches
- of new and existing minimal symbols, sort them, and then
- compact out the duplicate entries. Once we have a final
- table, we will give back the excess space. */
+ of new and existing minimal symbols, sort them, and then
+ compact out the duplicate entries. Once we have a final
+ table, we will give back the excess space. */
alloc_count = m_msym_count + m_objfile->per_bfd->minimal_symbol_count;
gdb::unique_xmalloc_ptr<minimal_symbol>
* sizeof (struct minimal_symbol));
/* Walk through the list of minimal symbol bunches, adding each symbol
- to the new contiguous array of symbols. Note that we start with the
- current, possibly partially filled bunch (thus we use the current
- msym_bunch_index for the first bunch we copy over), and thereafter
- each bunch is full. */
+ to the new contiguous array of symbols. Note that we start with the
+ current, possibly partially filled bunch (thus we use the current
+ msym_bunch_index for the first bunch we copy over), and thereafter
+ each bunch is full. */
mcount = m_objfile->per_bfd->minimal_symbol_count;
std::sort (msymbols, msymbols + mcount, minimal_symbol_is_less_than);
/* Compact out any duplicates, and free up whatever space we are
- no longer using. */
+ no longer using. */
mcount = compact_minimal_symbols (msymbols, mcount, m_objfile);
msym_holder.reset (XRESIZEVEC (struct minimal_symbol,
mcount));
/* Attach the minimal symbol table to the specified objfile.
- The strings themselves are also located in the storage_obstack
- of this objfile. */
+ The strings themselves are also located in the storage_obstack
+ of this objfile. */
if (m_objfile->per_bfd->minimal_symbol_count != 0)
clear_minimal_symbol_hash_tables (m_objfile);
/* This will be freed later, by compute_and_set_names. */
char *demangled_name
= symbol_find_demangled_name (msym, msym->linkage_name ());
- symbol_set_demangled_name
- (msym, demangled_name,
- &m_objfile->per_bfd->storage_obstack);
+ msym->set_demangled_name
+ (demangled_name, &m_objfile->per_bfd->storage_obstack);
msym->name_set = 1;
}
/* This mangled_name_hash computation has to be outside of
}
{
/* To limit how long we hold the lock, we only acquire it here
- and not while we demangle the names above. */
+ and not while we demangle the names above. */
#if CXX_STD_THREAD
std::lock_guard<std::mutex> guard (demangled_mutex);
#endif
= (minsym.objfile->per_bfd->msymbols.get ()
+ minsym.objfile->per_bfd->minimal_symbol_count);
msymbol = minsym.minsym;
- section = MSYMBOL_SECTION (msymbol);
+ section = msymbol->section_index ();
for (iter = msymbol + 1; iter != past_the_end; ++iter)
{
if ((MSYMBOL_VALUE_RAW_ADDRESS (iter)
!= MSYMBOL_VALUE_RAW_ADDRESS (msymbol))
- && MSYMBOL_SECTION (iter) == section)
+ && iter->section_index () == section)
break;
}
- obj_section = MSYMBOL_OBJ_SECTION (minsym.objfile, minsym.minsym);
+ obj_section = minsym.obj_section ();
if (iter != past_the_end
&& (MSYMBOL_VALUE_ADDRESS (minsym.objfile, iter)
< obj_section_endaddr (obj_section)))