aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-05-04 08:14:22 -0400
committerSimon Marchi <simon.marchi@efficios.com>2022-05-05 15:27:26 -0400
commit6e9cd73eb553c372153d6e9ba4934119623fdad3 (patch)
tree1eb62a3689f410c6554d8d94bff6502d1a9a6849 /gdb
parent1653ae5b8440e2182ac86974b99b603bc15aa163 (diff)
downloadgdb-6e9cd73eb553c372153d6e9ba4934119623fdad3.zip
gdb-6e9cd73eb553c372153d6e9ba4934119623fdad3.tar.gz
gdb-6e9cd73eb553c372153d6e9ba4934119623fdad3.tar.bz2
gdb: use gdb::function_view for gdbarch_iterate_over_objfiles_in_search_order callback
A rather straightforward patch to change an instance of callback + void pointer to gdb::function_view, allowing pasing lambdas that capture, and eliminating the need for the untyped pointer. Change-Id: I73ed644e7849945265a2c763f79f5456695b0037
Diffstat (limited to 'gdb')
-rw-r--r--gdb/findvar.c55
-rw-r--r--gdb/gdbarch-components.py12
-rw-r--r--gdb/gdbarch-gen.h13
-rw-r--r--gdb/gdbarch.c4
-rw-r--r--gdb/gdbarch.h4
-rw-r--r--gdb/objfiles.c14
-rw-r--r--gdb/objfiles.h5
-rw-r--r--gdb/solib-svr4.c15
-rw-r--r--gdb/symtab.c61
-rw-r--r--gdb/windows-tdep.c23
10 files changed, 55 insertions, 151 deletions
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 1f03175..36c0945 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -399,37 +399,6 @@ symbol_read_needs_frame (struct symbol *sym)
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. */
@@ -746,22 +715,25 @@ language_defn::read_var_value (struct symbol *var,
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 ());
@@ -772,14 +744,15 @@ language_defn::read_var_value (struct symbol *var,
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. */
diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py
index e8f20c8..fc10e86 100644
--- a/gdb/gdbarch-components.py
+++ b/gdb/gdbarch-components.py
@@ -2362,13 +2362,8 @@ Method(
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.
@@ -2376,8 +2371,7 @@ 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",
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 882b905..ddcb4c5 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1461,19 +1461,14 @@ extern void set_gdbarch_core_info_proc (struct gdbarch *gdbarch, gdbarch_core_in
/* 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. */
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index a588bde..68ef048 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -4928,13 +4928,13 @@ set_gdbarch_core_info_proc (struct gdbarch *gdbarch,
}
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
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 6404dc1..3a7b7f9 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -78,8 +78,8 @@ extern struct gdbarch *target_gdbarch (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
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 3f18e98..80f68fd 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1315,18 +1315,12 @@ shared_objfile_contains_address_p (struct program_space *pspace,
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. */
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 8bd7670..cb7a135 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -903,9 +903,8 @@ extern scoped_restore_tmpl<int> inhibit_section_map_updates
(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. */
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 2f3e79d..5c046d3 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -51,9 +51,9 @@ static int svr4_have_link_map_offsets (void);
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
@@ -3135,9 +3135,8 @@ struct target_so_ops svr4_so_ops;
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)
@@ -3156,7 +3155,7 @@ svr4_iterate_over_objfiles_in_search_order
&& 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;
}
}
@@ -3165,7 +3164,7 @@ svr4_iterate_over_objfiles_in_search_order
{
if (checked_current_objfile && objfile == current_objfile)
continue;
- if (cb (objfile, cb_data) != 0)
+ if (cb (objfile))
return;
}
}
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 4b33d6c..8564986 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2627,47 +2627,6 @@ find_quick_global_symbol_language (const char *name, const domain_enum domain)
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. */
@@ -2680,7 +2639,6 @@ lookup_global_or_static_symbol (const char *name,
{
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;
@@ -2700,16 +2658,15 @@ lookup_global_or_static_symbol (const char *name,
/* 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);
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 9049f1e..2516e4e 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -573,28 +573,21 @@ windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
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