diff options
author | Tom Tromey <tom@tromey.com> | 2021-06-25 08:40:37 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-06-25 08:40:37 -0600 |
commit | 50a6759f0f541ea965c7330bfbfe335cb8d66af8 (patch) | |
tree | 5f7add1207929170a7fcc2effc07c3e25335065d /gdb/psymtab.c | |
parent | 67470e9d8be180344494635dcef34e054938bfb8 (diff) | |
download | fsf-binutils-gdb-50a6759f0f541ea965c7330bfbfe335cb8d66af8.zip fsf-binutils-gdb-50a6759f0f541ea965c7330bfbfe335cb8d66af8.tar.gz fsf-binutils-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/psymtab.c')
-rw-r--r-- | gdb/psymtab.c | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/gdb/psymtab.c b/gdb/psymtab.c index fe32486..cbd21b3 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1465,52 +1465,39 @@ psymtab_storage::discard_psymtab (struct partial_symtab *pst) -/* We need to pass a couple of items to the addrmap_foreach function, - so use a struct. */ - -struct dump_psymtab_addrmap_data -{ - struct objfile *objfile; - struct partial_symtab *psymtab; - struct ui_file *outfile; - - /* Non-zero if the previously printed addrmap entry was for PSYMTAB. - If so, we want to print the next one as well (since the next addrmap - entry defines the end of the range). */ - int previous_matched; -}; - /* Helper function for dump_psymtab_addrmap to print an addrmap entry. */ static int -dump_psymtab_addrmap_1 (void *datap, CORE_ADDR start_addr, void *obj) +dump_psymtab_addrmap_1 (struct objfile *objfile, + struct partial_symtab *psymtab, + struct ui_file *outfile, + int *previous_matched, + CORE_ADDR start_addr, + void *obj) { - struct dump_psymtab_addrmap_data *data - = (struct dump_psymtab_addrmap_data *) datap; - struct gdbarch *gdbarch = data->objfile->arch (); + struct gdbarch *gdbarch = objfile->arch (); struct partial_symtab *addrmap_psymtab = (struct partial_symtab *) obj; const char *psymtab_address_or_end = NULL; QUIT; - if (data->psymtab == NULL - || data->psymtab == addrmap_psymtab) + if (psymtab == NULL + || psymtab == addrmap_psymtab) psymtab_address_or_end = host_address_to_string (addrmap_psymtab); - else if (data->previous_matched) + else if (*previous_matched) psymtab_address_or_end = "<ends here>"; - if (data->psymtab == NULL - || data->psymtab == addrmap_psymtab - || data->previous_matched) + if (psymtab == NULL + || psymtab == addrmap_psymtab + || *previous_matched) { - fprintf_filtered (data->outfile, " %s%s %s\n", - data->psymtab != NULL ? " " : "", + fprintf_filtered (outfile, " %s%s %s\n", + psymtab != NULL ? " " : "", paddress (gdbarch, start_addr), psymtab_address_or_end); } - data->previous_matched = (data->psymtab == NULL - || data->psymtab == addrmap_psymtab); + *previous_matched = psymtab == NULL || psymtab == addrmap_psymtab; return 0; } @@ -1524,20 +1511,24 @@ dump_psymtab_addrmap (struct objfile *objfile, struct partial_symtab *psymtab, struct ui_file *outfile) { - struct dump_psymtab_addrmap_data addrmap_dump_data; - if ((psymtab == NULL || psymtab->psymtabs_addrmap_supported) && partial_symtabs->psymtabs_addrmap != NULL) { - addrmap_dump_data.objfile = objfile; - addrmap_dump_data.psymtab = psymtab; - addrmap_dump_data.outfile = outfile; - addrmap_dump_data.previous_matched = 0; + /* Non-zero if the previously printed addrmap entry was for + PSYMTAB. If so, we want to print the next one as well (since + the next addrmap entry defines the end of the range). */ + int previous_matched = 0; + + auto callback = [&] (CORE_ADDR start_addr, void *obj) + { + return dump_psymtab_addrmap_1 (objfile, psymtab, outfile, + &previous_matched, start_addr, obj); + }; + fprintf_filtered (outfile, "%sddress map:\n", psymtab == NULL ? "Entire a" : " A"); - addrmap_foreach (partial_symtabs->psymtabs_addrmap, - dump_psymtab_addrmap_1, &addrmap_dump_data); + addrmap_foreach (partial_symtabs->psymtabs_addrmap, callback); } } |