/* GDB routines for manipulating the minimal symbol tables.
- Copyright (C) 1992-2018 Free Software Foundation, Inc.
+ Copyright (C) 1992-2019 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
This file is part of GDB.
#include "cp-support.h"
#include "language.h"
#include "cli/cli-utils.h"
-#include "symbol.h"
+#include "common/symbol.h"
#include <algorithm>
#include "safe-ctype.h"
return 0;
}
+/* Helper for lookup_minimal_symbol_by_pc_section. Convert a
+ lookup_msym_prefer to a minimal_symbol_type. */
+
+static minimal_symbol_type
+msym_prefer_to_msym_type (lookup_msym_prefer prefer)
+{
+ switch (prefer)
+ {
+ case lookup_msym_prefer::TEXT:
+ return mst_text;
+ case lookup_msym_prefer::TRAMPOLINE:
+ return mst_solib_trampoline;
+ case lookup_msym_prefer::GNU_IFUNC:
+ return mst_text_gnu_ifunc;
+ }
+
+ /* Assert here instead of in a default switch case above so that
+ -Wswitch warns if a new enumerator is added. */
+ 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).
struct minimal_symbol *best_symbol = NULL;
struct objfile *best_objfile = NULL;
struct bound_minimal_symbol result;
- enum minimal_symbol_type want_type;
if (section == NULL)
{
return {};
}
- switch (prefer)
- {
- case lookup_msym_prefer::TEXT:
- want_type = mst_text;
- break;
- case lookup_msym_prefer::TRAMPOLINE:
- want_type = mst_solib_trampoline;
- break;
- case lookup_msym_prefer::GNU_IFUNC:
- want_type = mst_text_gnu_ifunc;
- break;
- }
+ minimal_symbol_type want_type = msym_prefer_to_msym_type (prefer);
/* We can not require the symbol found to be in section, because
e.g. IRIX 6.5 mdebug relies on this code returning an absolute
record_with_info (name, address, ms_type, section);
}
+/* Convert an enumerator of type minimal_symbol_type to its string
+ representation. */
+
+static const char *
+mst_str (minimal_symbol_type t)
+{
+#define MST_TO_STR(x) case x: return #x;
+ switch (t)
+ {
+ MST_TO_STR (mst_unknown);
+ MST_TO_STR (mst_text);
+ MST_TO_STR (mst_text_gnu_ifunc);
+ MST_TO_STR (mst_slot_got_plt);
+ MST_TO_STR (mst_data);
+ MST_TO_STR (mst_bss);
+ MST_TO_STR (mst_abs);
+ MST_TO_STR (mst_solib_trampoline);
+ MST_TO_STR (mst_file_text);
+ MST_TO_STR (mst_file_data);
+ MST_TO_STR (mst_file_bss);
+
+ default:
+ return "mst_???";
+ }
+#undef MST_TO_STR
+}
+
/* See minsyms.h. */
struct minimal_symbol *
if (ms_type == mst_file_text && startswith (name, "__gnu_compiled"))
return (NULL);
+ if (symtab_create_debug >= 2)
+ printf_unfiltered ("Recording minsym: %-21s %18s %4d %s\n",
+ mst_str (ms_type), hex_string (address), section, name);
+
if (m_msym_bunch_index == BUNCH_SIZE)
{
newobj = XCNEW (struct msym_bunch);
mcount = compact_minimal_symbols (msymbols, mcount, m_objfile);
- obstack_blank_fast (&m_objfile->per_bfd->storage_obstack,
- (mcount + 1 - alloc_count) * sizeof (struct minimal_symbol));
+ ssize_t shrink_bytes
+ = (mcount + 1 - alloc_count) * sizeof (struct minimal_symbol);
+ obstack_blank_fast (&m_objfile->per_bfd->storage_obstack, shrink_bytes);
msymbols = (struct minimal_symbol *)
obstack_finish (&m_objfile->per_bfd->storage_obstack);
CORE_ADDR
find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
{
- struct objfile *objfile;
- struct minimal_symbol *msymbol;
struct minimal_symbol *tsymbol = lookup_solib_trampoline_symbol_by_pc (pc);
if (tsymbol != NULL)
{
- ALL_MSYMBOLS (objfile, msymbol)
- {
- /* Also handle minimal symbols pointing to function descriptors. */
- if ((MSYMBOL_TYPE (msymbol) == mst_text
- || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
- || MSYMBOL_TYPE (msymbol) == mst_data
- || MSYMBOL_TYPE (msymbol) == mst_data_gnu_ifunc)
- && strcmp (MSYMBOL_LINKAGE_NAME (msymbol),
- MSYMBOL_LINKAGE_NAME (tsymbol)) == 0)
- {
- CORE_ADDR func;
+ for (objfile *objfile : current_program_space->objfiles ())
+ {
+ for (minimal_symbol *msymbol : objfile->msymbols ())
+ {
+ /* Also handle minimal symbols pointing to function
+ descriptors. */
+ if ((MSYMBOL_TYPE (msymbol) == mst_text
+ || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
+ || MSYMBOL_TYPE (msymbol) == mst_data
+ || MSYMBOL_TYPE (msymbol) == mst_data_gnu_ifunc)
+ && strcmp (MSYMBOL_LINKAGE_NAME (msymbol),
+ MSYMBOL_LINKAGE_NAME (tsymbol)) == 0)
+ {
+ CORE_ADDR func;
- /* Ignore data symbols that are not function
- descriptors. */
- if (msymbol_is_function (objfile, msymbol, &func))
- return func;
- }
- }
+ /* Ignore data symbols that are not function
+ descriptors. */
+ if (msymbol_is_function (objfile, msymbol, &func))
+ return func;
+ }
+ }
+ }
}
return 0;
}