set_current_program_space (pspace);
for (objfile &objfile : pspace->objfiles ())
- {
- iterate_over_minimal_symbols (&objfile, name,
- [&] (struct minimal_symbol *msym)
- {
- add_minsym (msym, &objfile, nullptr,
- info->state->list_mode,
- &minsyms);
- return false;
- });
- }
+ for_each_minimal_symbol (&objfile, name,
+ [&] (minimal_symbol *msym)
+ {
+ add_minsym (msym, &objfile, nullptr,
+ info->state->list_mode,
+ &minsyms);
+ });
}
}
else
{
- program_space *pspace = symtab->compunit ()->objfile ()->pspace ();
+ objfile &objfile = *symtab->compunit ()->objfile ();
+ program_space *pspace = objfile.pspace ();
if (search_pspace == NULL || pspace == search_pspace)
{
set_current_program_space (pspace);
- iterate_over_minimal_symbols
- (symtab->compunit ()->objfile (), name,
- [&] (struct minimal_symbol *msym)
- {
- add_minsym (msym, symtab->compunit ()->objfile (), symtab,
- info->state->list_mode, &minsyms);
- return false;
- });
+ for_each_minimal_symbol (&objfile, name,
+ [&] (minimal_symbol *msym)
+ {
+ add_minsym (msym, &objfile, symtab,
+ info->state->list_mode,
+ &minsyms);
+ });
}
}
/* See minsyms.h. */
void
-iterate_over_minimal_symbols
- (struct objfile *objf, const lookup_name_info &lookup_name,
- gdb::function_view<bool (struct minimal_symbol *)> callback)
+for_each_minimal_symbol (struct objfile *objf, const lookup_name_info &name,
+ for_each_minimal_symbol_callback_ftype callback)
+{
+ find_minimal_symbol (objf, name,
+ [&] (struct minimal_symbol *msym)
+ {
+ callback (msym);
+ return false;
+ });
+}
+
+/* See minsyms.h. */
+
+minimal_symbol *
+find_minimal_symbol (struct objfile *objf, const lookup_name_info &lookup_name,
+ find_minimal_symbol_callback_ftype callback)
{
/* The first pass is over the ordinary hash table. */
{
{
if (mangled_cmp (iter->linkage_name (), name) == 0)
if (callback (iter))
- return;
+ return iter;
}
}
iter = iter->demangled_hash_next)
if (name_match (iter->search_name (), lookup_name, NULL))
if (callback (iter))
- return;
+ return iter;
}
+
+ return nullptr;
}
/* See minsyms.h. */
#ifndef GDB_MINSYMS_H
#define GDB_MINSYMS_H
+#include "gdbsupport/function-view.h"
#include <deque>
struct program_space;
bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);
-/* Iterate over all the minimal symbols in the objfile OBJF which
- match NAME. Both the ordinary and demangled names of each symbol
- are considered. The caller is responsible for canonicalizing NAME,
- should that need to be done.
+/* Callback type for function for_each_minimal_symbol. */
- For each matching symbol, CALLBACK is called with the symbol. */
+using for_each_minimal_symbol_callback_ftype
+ = gdb::function_view<void (struct minimal_symbol *)>;
-void iterate_over_minimal_symbols
- (struct objfile *objf, const lookup_name_info &name,
- gdb::function_view<bool (struct minimal_symbol *)> callback);
+/* Call CALLBACK for all minimal symbols in objfile OBJF which match NAME.
+
+ Both the ordinary and demangled names of each symbol are considered. The
+ caller is responsible for canonicalizing NAME, should that need to be
+ done. */
+
+void for_each_minimal_symbol (struct objfile *objf,
+ const lookup_name_info &name,
+ for_each_minimal_symbol_callback_ftype callback);
+
+/* Callback type for function find_minimal_symbol. */
+
+using find_minimal_symbol_callback_ftype
+ = gdb::function_view<bool (struct minimal_symbol *)>;
+
+/* Find the first minimal symbol for objfile OBJF which matches NAME and for
+ which CALLBACK returns true.
+
+ Both the ordinary and demangled names of each symbol are considered. The
+ caller is responsible for canonicalizing NAME, should that need to be
+ done. */
+
+minimal_symbol *find_minimal_symbol
+ (struct objfile *objf, const lookup_name_info &name,
+ find_minimal_symbol_callback_ftype callback);
/* Compute the upper bound of MINSYM. The upper bound is the last
address thought to be part of the symbol. If the symbol has a
struct objfile *objfile = sym->objfile ();
CORE_ADDR address = sym->value_block ()->entry_pc ();
- minimal_symbol *ifunc = NULL;
-
- iterate_over_minimal_symbols (objfile, lookup_name,
- [&] (minimal_symbol *minsym)
+ minimal_symbol *ifunc
+ = find_minimal_symbol (objfile, lookup_name,
+ [&] (minimal_symbol *minsym)
{
if (minsym->type () == mst_text_gnu_ifunc
|| minsym->type () == mst_data_gnu_ifunc)
{
CORE_ADDR msym_addr = minsym->value_address (objfile);
+
if (minsym->type () == mst_data_gnu_ifunc)
{
struct gdbarch *gdbarch = objfile->arch ();
msym_addr = gdbarch_convert_from_func_ptr_addr
(gdbarch, msym_addr, current_inferior ()->top_target ());
}
+
if (msym_addr == address)
- {
- ifunc = minsym;
- return true;
- }
+ return true;
}
+
return false;
});
- if (ifunc != NULL)
+ if (ifunc != nullptr)
return {ifunc, objfile};
+
return {};
}