return symbol_read_needs (sym) == SYMBOL_NEEDS_FRAME;
}
-/* Private data to be used with minsym_lookup_iterator_cb. */
-
-struct minsym_lookup_data
-{
- /* The name of the minimal symbol we are searching for. */
- const char *name = nullptr;
-
- /* The field where the callback should store the minimal symbol
- if found. It should be initialized to NULL before the search
- is started. */
- struct bound_minimal_symbol result;
-};
-
-/* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
- It searches by name for a minimal symbol within the given OBJFILE.
- The arguments are passed via CB_DATA, which in reality is a pointer
- to struct minsym_lookup_data. */
-
-static int
-minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data)
-{
- struct minsym_lookup_data *data = (struct minsym_lookup_data *) cb_data;
-
- gdb_assert (data->result.minsym == NULL);
-
- data->result = lookup_minimal_symbol (data->name, NULL, objfile);
-
- /* The iterator should stop iff a match was found. */
- return (data->result.minsym != NULL);
-}
-
/* Given static link expression and the frame it lives in, look for the frame
the static links points to and return it. Return NULL if we could not find
such a frame. */
case LOC_UNRESOLVED:
{
- struct minsym_lookup_data lookup_data;
- struct minimal_symbol *msym;
struct obj_section *obj_section;
-
- lookup_data.name = var->linkage_name ();
+ bound_minimal_symbol bmsym;
gdbarch_iterate_over_objfiles_in_search_order
(var->arch (),
- minsym_lookup_iterator_cb, &lookup_data,
+ [var, &bmsym] (objfile *objfile)
+ {
+ bmsym = lookup_minimal_symbol (var->linkage_name (), nullptr,
+ objfile);
+
+ /* Stop if a match is found. */
+ return bmsym.minsym != nullptr;
+ },
var->objfile ());
- msym = lookup_data.result.minsym;
/* If we can't find the minsym there's a problem in the symbol info.
The symbol exists in the debug info, but it's missing in the minsym
table. */
- if (msym == NULL)
+ if (bmsym.minsym == nullptr)
{
const char *flavour_name
= objfile_flavour_name (var->objfile ());
error (_("Missing %s symbol \"%s\"."),
flavour_name, var->linkage_name ());
}
- obj_section = msym->obj_section (lookup_data.result.objfile);
+
+ obj_section = bmsym.minsym->obj_section (bmsym.objfile);
/* Relocate address, unless there is no section or the variable is
a TLS variable. */
if (obj_section == NULL
|| (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
- addr = msym->value_raw_address ();
+ addr = bmsym.minsym->value_raw_address ();
else
- addr = lookup_data.result.value_address ();
+ addr = bmsym.value_address ();
if (overlay_debugging)
addr = symbol_overlayed_address (addr, obj_section);
/* Determine address of TLS variable. */
Iterate over all objfiles in the order that makes the most sense
for the architecture to make global symbol searches.
-CB is a callback function where OBJFILE is the objfile to be searched,
-and CB_DATA a pointer to user-defined data (the same data that is passed
-when calling this gdbarch method). The iteration stops if this function
-returns nonzero.
-
-CB_DATA is a pointer to some user-defined data to be passed to
-the callback.
+CB is a callback function passed an objfile to be searched. The iteration stops
+if this function returns nonzero.
If not NULL, CURRENT_OBJFILE corresponds to the objfile being
inspected when the symbol search was requested.
type="void",
name="iterate_over_objfiles_in_search_order",
params=[
- ("iterate_over_objfiles_in_search_order_cb_ftype *", "cb"),
- ("void *", "cb_data"),
+ ("iterate_over_objfiles_in_search_order_cb_ftype", "cb"),
("struct objfile *", "current_objfile"),
],
predefault="default_iterate_over_objfiles_in_search_order",
/* Iterate over all objfiles in the order that makes the most sense
for the architecture to make global symbol searches.
- CB is a callback function where OBJFILE is the objfile to be searched,
- and CB_DATA a pointer to user-defined data (the same data that is passed
- when calling this gdbarch method). The iteration stops if this function
- returns nonzero.
-
- CB_DATA is a pointer to some user-defined data to be passed to
- the callback.
+ CB is a callback function passed an objfile to be searched. The iteration stops
+ if this function returns nonzero.
If not NULL, CURRENT_OBJFILE corresponds to the objfile being
inspected when the symbol search was requested. */
-typedef void (gdbarch_iterate_over_objfiles_in_search_order_ftype) (struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb, void *cb_data, struct objfile *current_objfile);
-extern void gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb, void *cb_data, struct objfile *current_objfile);
+typedef void (gdbarch_iterate_over_objfiles_in_search_order_ftype) (struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struct objfile *current_objfile);
+extern void gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struct objfile *current_objfile);
extern void set_gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, gdbarch_iterate_over_objfiles_in_search_order_ftype *iterate_over_objfiles_in_search_order);
/* Ravenscar arch-dependent ops. */
}
void
-gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb, void *cb_data, struct objfile *current_objfile)
+gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struct objfile *current_objfile)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->iterate_over_objfiles_in_search_order != NULL);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_iterate_over_objfiles_in_search_order called\n");
- gdbarch->iterate_over_objfiles_in_search_order (gdbarch, cb, cb_data, current_objfile);
+ gdbarch->iterate_over_objfiles_in_search_order (gdbarch, cb, current_objfile);
}
void
/* Callback type for the 'iterate_over_objfiles_in_search_order'
gdbarch method. */
-typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
- (struct objfile *objfile, void *cb_data);
+using iterate_over_objfiles_in_search_order_cb_ftype
+ = gdb::function_view<bool(objfile *)>;
/* Callback type for regset section iterators. The callback usually
invokes the REGSET's supply or collect method, to which it must
void
default_iterate_over_objfiles_in_search_order
- (struct gdbarch *gdbarch,
- iterate_over_objfiles_in_search_order_cb_ftype *cb,
- void *cb_data, struct objfile *current_objfile)
+ (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb,
+ objfile *current_objfile)
{
- int stop = 0;
-
for (objfile *objfile : current_program_space->objfiles ())
- {
- stop = cb (objfile, cb_data);
- if (stop)
- return;
- }
+ if (cb (objfile))
+ return;
}
/* See objfiles.h. */
(struct program_space *pspace);
extern void default_iterate_over_objfiles_in_search_order
- (struct gdbarch *gdbarch,
- iterate_over_objfiles_in_search_order_cb_ftype *cb,
- void *cb_data, struct objfile *current_objfile);
+ (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb,
+ objfile *current_objfile);
/* Reset the per-BFD storage area on OBJ. */
static void svr4_relocate_main_executable (void);
static void svr4_free_library_list (void *p_list);
static void probes_table_remove_objfile_probes (struct objfile *objfile);
-static void svr4_iterate_over_objfiles_in_search_order (
- struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype *cb,
- void *cb_data, struct objfile *objfile);
+static void svr4_iterate_over_objfiles_in_search_order
+ (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb,
+ objfile *current_objfile);
/* On SVR4 systems, a list of symbols in the dynamic linker where
static void
svr4_iterate_over_objfiles_in_search_order
- (struct gdbarch *gdbarch,
- iterate_over_objfiles_in_search_order_cb_ftype *cb,
- void *cb_data, struct objfile *current_objfile)
+ (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb,
+ objfile *current_objfile)
{
bool checked_current_objfile = false;
if (current_objfile != nullptr)
&& gdb_bfd_scan_elf_dyntag (DT_SYMBOLIC, abfd, nullptr, nullptr) == 1)
{
checked_current_objfile = true;
- if (cb (current_objfile, cb_data) != 0)
+ if (cb (current_objfile))
return;
}
}
{
if (checked_current_objfile && objfile == current_objfile)
continue;
- if (cb (objfile, cb_data) != 0)
+ if (cb (objfile))
return;
}
}
return language_unknown;
}
-/* Private data to be used with lookup_symbol_global_iterator_cb. */
-
-struct global_or_static_sym_lookup_data
-{
- /* The name of the symbol we are searching for. */
- const char *name;
-
- /* The domain to use for our search. */
- domain_enum domain;
-
- /* The block index in which to search. */
- enum block_enum block_index;
-
- /* The field where the callback should store the symbol if found.
- It should be initialized to {NULL, NULL} before the search is started. */
- struct block_symbol result;
-};
-
-/* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
- It searches by name for a symbol in the block given by BLOCK_INDEX of the
- given OBJFILE. The arguments for the search are passed via CB_DATA, which
- in reality is a pointer to struct global_or_static_sym_lookup_data. */
-
-static int
-lookup_symbol_global_or_static_iterator_cb (struct objfile *objfile,
- void *cb_data)
-{
- struct global_or_static_sym_lookup_data *data =
- (struct global_or_static_sym_lookup_data *) cb_data;
-
- gdb_assert (data->result.symbol == NULL
- && data->result.block == NULL);
-
- data->result = lookup_symbol_in_objfile (objfile, data->block_index,
- data->name, data->domain);
-
- /* If we found a match, tell the iterator to stop. Otherwise,
- keep going. */
- return (data->result.symbol != NULL);
-}
-
/* This function contains the common code of lookup_{global,static}_symbol.
OBJFILE is only used if BLOCK_INDEX is GLOBAL_SCOPE, in which case it is
the objfile to start the lookup in. */
{
struct symbol_cache *cache = get_symbol_cache (current_program_space);
struct block_symbol result;
- struct global_or_static_sym_lookup_data lookup_data;
struct block_symbol_cache *bsc;
struct symbol_cache_slot *slot;
/* Do a global search (of global blocks, heh). */
if (result.symbol == NULL)
- {
- memset (&lookup_data, 0, sizeof (lookup_data));
- lookup_data.name = name;
- lookup_data.block_index = block_index;
- lookup_data.domain = domain;
- gdbarch_iterate_over_objfiles_in_search_order
- (objfile != NULL ? objfile->arch () : target_gdbarch (),
- lookup_symbol_global_or_static_iterator_cb, &lookup_data, objfile);
- result = lookup_data.result;
- }
+ gdbarch_iterate_over_objfiles_in_search_order
+ (objfile != NULL ? objfile->arch () : target_gdbarch (),
+ [&result, block_index, name, domain] (struct objfile *objfile_iter)
+ {
+ result = lookup_symbol_in_objfile (objfile_iter, block_index,
+ name, domain);
+ return result.symbol != nullptr;
+ },
+ objfile);
if (result.symbol != NULL)
symbol_cache_mark_found (bsc, slot, objfile, result.symbol, result.block);
static void
windows_iterate_over_objfiles_in_search_order
- (struct gdbarch *gdbarch,
- iterate_over_objfiles_in_search_order_cb_ftype *cb,
- void *cb_data, struct objfile *current_objfile)
+ (gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb,
+ objfile *current_objfile)
{
- int stop;
-
if (current_objfile)
{
- stop = cb (current_objfile, cb_data);
- if (stop)
+ if (cb (current_objfile))
return;
}
for (objfile *objfile : current_program_space->objfiles ())
- {
- if (objfile != current_objfile)
- {
- stop = cb (objfile, cb_data);
- if (stop)
- return;
- }
- }
+ if (objfile != current_objfile)
+ {
+ if (cb (objfile))
+ return;
+ }
}
static void