aboutsummaryrefslogtreecommitdiff
path: root/gdb/addrmap.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-06-25 08:40:37 -0600
committerTom Tromey <tom@tromey.com>2021-06-25 08:40:37 -0600
commit50a6759f0f541ea965c7330bfbfe335cb8d66af8 (patch)
tree5f7add1207929170a7fcc2effc07c3e25335065d /gdb/addrmap.c
parent67470e9d8be180344494635dcef34e054938bfb8 (diff)
downloadgdb-50a6759f0f541ea965c7330bfbfe335cb8d66af8.zip
gdb-50a6759f0f541ea965c7330bfbfe335cb8d66af8.tar.gz
gdb-50a6759f0f541ea965c7330bfbfe335cb8d66af8.tar.bz2
Use gdb::function_view in addrmap_foreach
While working on the DWARF psymtab replacement, I needed addrmap_foreach to accept a gdb::function_view. This seemed like a worthwhile change on its own, so I've written it separately for submission. Regression tested on x86-64 Fedora 32. gdb/ChangeLog 2021-06-25 Tom Tromey <tom@tromey.com> * dwarf2/index-write.c (struct addrmap_index_data): Add initializers. <operator()>: Declare. (addrmap_index_data::operator()): Rename from add_address_entry_worker. Remove 'datap' parameter. (write_address_map): Update. * psymtab.c (struct dump_psymtab_addrmap_data): Remove (dump_psymtab_addrmap_1): Remove 'data' parameter, add other parameters. (dump_psymtab_addrmap): Update. * addrmap.c (struct addrmap_funcs) <foreach>: Remove 'data' parameter. (addrmap_foreach, addrmap_fixed_foreach): Likewise. (struct mutable_foreach_data): Remove. (addrmap_mutable_foreach_worker): Update. (addrmap_mutable_foreach): Remove 'data' parameter. * addrmap.h (addrmap_foreach_fn): Use gdb::function_view. (addrmap_foreach): Remove 'data' parameter.
Diffstat (limited to 'gdb/addrmap.c')
-rw-r--r--gdb/addrmap.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index f735123..9bd924e 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -41,7 +41,7 @@ struct addrmap_funcs
struct addrmap *(*create_fixed) (struct addrmap *self,
struct obstack *obstack);
void (*relocate) (struct addrmap *self, CORE_ADDR offset);
- int (*foreach) (struct addrmap *self, addrmap_foreach_fn fn, void *data);
+ int (*foreach) (struct addrmap *self, addrmap_foreach_fn fn);
};
@@ -84,9 +84,9 @@ addrmap_relocate (struct addrmap *map, CORE_ADDR offset)
int
-addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn, void *data)
+addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn)
{
- return map->funcs->foreach (map, fn, data);
+ return map->funcs->foreach (map, fn);
}
/* Fixed address maps. */
@@ -182,15 +182,14 @@ addrmap_fixed_relocate (struct addrmap *self, CORE_ADDR offset)
static int
-addrmap_fixed_foreach (struct addrmap *self, addrmap_foreach_fn fn,
- void *data)
+addrmap_fixed_foreach (struct addrmap *self, addrmap_foreach_fn fn)
{
struct addrmap_fixed *map = (struct addrmap_fixed *) self;
size_t i;
for (i = 0; i < map->num_transitions; i++)
{
- int res = fn (data, map->transitions[i].addr, map->transitions[i].value);
+ int res = fn (map->transitions[i].addr, map->transitions[i].value);
if (res != 0)
return res;
@@ -471,39 +470,24 @@ addrmap_mutable_relocate (struct addrmap *self, CORE_ADDR offset)
}
-/* Struct to map addrmap's foreach function to splay_tree's version. */
-struct mutable_foreach_data
-{
- addrmap_foreach_fn fn;
- void *data;
-};
-
-
/* This is a splay_tree_foreach_fn. */
static int
addrmap_mutable_foreach_worker (splay_tree_node node, void *data)
{
- struct mutable_foreach_data *foreach_data
- = (struct mutable_foreach_data *) data;
+ addrmap_foreach_fn *fn = (addrmap_foreach_fn *) data;
- return foreach_data->fn (foreach_data->data,
- addrmap_node_key (node),
- addrmap_node_value (node));
+ return (*fn) (addrmap_node_key (node), addrmap_node_value (node));
}
static int
-addrmap_mutable_foreach (struct addrmap *self, addrmap_foreach_fn fn,
- void *data)
+addrmap_mutable_foreach (struct addrmap *self, addrmap_foreach_fn fn)
{
struct addrmap_mutable *mutable_obj = (struct addrmap_mutable *) self;
- struct mutable_foreach_data foreach_data;
- foreach_data.fn = fn;
- foreach_data.data = data;
return splay_tree_foreach (mutable_obj->tree, addrmap_mutable_foreach_worker,
- &foreach_data);
+ &fn);
}