diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2022-05-04 08:14:22 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2022-05-05 15:27:26 -0400 |
commit | 6e9cd73eb553c372153d6e9ba4934119623fdad3 (patch) | |
tree | 1eb62a3689f410c6554d8d94bff6502d1a9a6849 /gdb/symtab.c | |
parent | 1653ae5b8440e2182ac86974b99b603bc15aa163 (diff) | |
download | binutils-6e9cd73eb553c372153d6e9ba4934119623fdad3.zip binutils-6e9cd73eb553c372153d6e9ba4934119623fdad3.tar.gz binutils-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/symtab.c')
-rw-r--r-- | gdb/symtab.c | 61 |
1 files changed, 9 insertions, 52 deletions
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); |