From 199b4314efbd419d6957e366e13a14cd87cea5e4 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 12 Jul 2019 10:45:34 -0600 Subject: [PATCH] Change map_matching_symbols to take a symbol_found_callback_ftype This changes map_matching_symbols to take a symbol_found_callback_ftype, rather than separate callback and data parameters. This enables a future patch to clean up some existing code so that it can more readily be shared. gdb/ChangeLog 2019-09-10 Tom Tromey * ada-lang.c (aux_add_nonlocal_symbols): Change type. (add_nonlocal_symbols): Update. * dwarf2read.c (dw2_map_matching_symbols): Change type. * psymtab.c (map_block, psym_map_matching_symbols): Change type. * symfile-debug.c (debug_qf_map_matching_symbols): Change type. * symfile.h (struct quick_symbol_functions) : Change type of "callback". Remove "data". --- gdb/ChangeLog | 10 ++++++++++ gdb/ada-lang.c | 34 ++++++++++++++++++---------------- gdb/dwarf2read.c | 14 +++++++------- gdb/psymtab.c | 38 +++++++++++++++++++------------------- gdb/symfile-debug.c | 21 +++++++++------------ gdb/symfile.h | 23 +++++++++++------------ 6 files changed, 74 insertions(+), 66 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9ad7227e0b..1865eeddbb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2019-09-10 Tom Tromey + + * ada-lang.c (aux_add_nonlocal_symbols): Change type. + (add_nonlocal_symbols): Update. + * dwarf2read.c (dw2_map_matching_symbols): Change type. + * psymtab.c (map_block, psym_map_matching_symbols): Change type. + * symfile-debug.c (debug_qf_map_matching_symbols): Change type. + * symfile.h (struct quick_symbol_functions) : + Change type of "callback". Remove "data". + 2019-09-09 Ali Tamur diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 347c67f95c..d677acdb60 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5331,8 +5331,8 @@ struct match_data int found_sym; }; -/* A callback for add_nonlocal_symbols that adds SYM, found in BLOCK, - to a list of symbols. DATA0 is a pointer to a struct match_data * +/* A callback for add_nonlocal_symbols that adds symbol, found in BSYM, + to a list of symbols. DATA is a pointer to a struct match_data * containing the obstack that collects the symbol list, the file that SYM must come from, a flag indicating whether a non-argument symbol has been found in the current block, and the last argument symbol @@ -5340,12 +5340,13 @@ struct match_data marking the end of a block, the argument symbol is added if no other has been found. */ -static int -aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym, - void *data0) +static bool +aux_add_nonlocal_symbols (struct block_symbol *bsym, + struct match_data *data) { - struct match_data *data = (struct match_data *) data0; - + const struct block *block = bsym->block; + struct symbol *sym = bsym->symbol; + if (sym == NULL) { if (!data->found_sym && data->arg_sym != NULL) @@ -5358,7 +5359,7 @@ aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym, else { if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED) - return 0; + return true; else if (SYMBOL_IS_ARGUMENT (sym)) data->arg_sym = sym; else @@ -5369,7 +5370,7 @@ aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym, block); } } - return 0; + return true; } /* Helper for add_nonlocal_symbols. Find symbols in DOMAIN which are @@ -5540,20 +5541,23 @@ add_nonlocal_symbols (struct obstack *obstackp, bool is_wild_match = lookup_name.ada ().wild_match_p (); + auto callback = [&] (struct block_symbol *bsym) + { + return aux_add_nonlocal_symbols (bsym, &data); + }; + for (objfile *objfile : current_program_space->objfiles ()) { data.objfile = objfile; if (is_wild_match) objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (), - domain, global, - aux_add_nonlocal_symbols, &data, + domain, global, callback, symbol_name_match_type::WILD, NULL); else objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (), - domain, global, - aux_add_nonlocal_symbols, &data, + domain, global, callback, symbol_name_match_type::FULL, compare_names); @@ -5577,9 +5581,7 @@ add_nonlocal_symbols (struct obstack *obstackp, { data.objfile = objfile; objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (), - domain, global, - aux_add_nonlocal_symbols, - &data, + domain, global, callback, symbol_name_match_type::FULL, compare_names); } diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a75941867a..cccc493b29 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -4184,13 +4184,13 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile, } static void -dw2_map_matching_symbols (struct objfile *objfile, - const char * name, domain_enum domain, - int global, - int (*callback) (const struct block *, - struct symbol *, void *), - void *data, symbol_name_match_type match, - symbol_compare_ftype *ordered_compare) +dw2_map_matching_symbols + (struct objfile *objfile, + const char * name, domain_enum domain, + int global, + gdb::function_view callback, + symbol_name_match_type match, + symbol_compare_ftype *ordered_compare) { /* Currently unimplemented; used for Ada. The function can be called if the current language is Ada for a non-Ada objfile using GNU index. As Ada diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 70d04f8605..cd577bc4c5 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1170,14 +1170,14 @@ psymtab_to_fullname (struct partial_symtab *ps) /* For all symbols, s, in BLOCK that are in DOMAIN and match NAME according to the function MATCH, call CALLBACK(BLOCK, s, DATA). - BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK - ever returns non-zero, and otherwise returns 0. */ + BLOCK is assumed to come from OBJFILE. Returns false iff CALLBACK + ever returns false, and otherwise returns true. */ -static int +static bool map_block (const char *name, domain_enum domain, struct objfile *objfile, const struct block *block, - int (*callback) (const struct block *, struct symbol *, void *), - void *data, symbol_name_match_type match) + gdb::function_view callback, + symbol_name_match_type match) { struct block_iterator iter; struct symbol *sym; @@ -1191,26 +1191,26 @@ map_block (const char *name, domain_enum domain, struct objfile *objfile, if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain)) { - if (callback (block, sym, data)) - return 1; + struct block_symbol block_sym = {sym, block}; + if (!callback (&block_sym)) + return false; } } - return 0; + return true; } /* Psymtab version of map_matching_symbols. See its definition in the definition of quick_symbol_functions in symfile.h. */ static void -psym_map_matching_symbols (struct objfile *objfile, - const char *name, domain_enum domain, - int global, - int (*callback) (const struct block *, - struct symbol *, void *), - void *data, - symbol_name_match_type match, - symbol_compare_ftype *ordered_compare) +psym_map_matching_symbols + (struct objfile *objfile, + const char *name, domain_enum domain, + int global, + gdb::function_view callback, + symbol_name_match_type match, + symbol_compare_ftype *ordered_compare) { const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; @@ -1227,10 +1227,10 @@ psym_map_matching_symbols (struct objfile *objfile, if (cust == NULL) continue; block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind); - if (map_block (name, domain, objfile, block, - callback, data, match)) + if (!map_block (name, domain, objfile, block, callback, match)) return; - if (callback (block, NULL, data)) + struct block_symbol block_sym = {nullptr, block}; + if (!callback (&block_sym)) return; } } diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index c5b565fc51..d36c192ccc 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -228,30 +228,27 @@ debug_qf_expand_symtabs_with_fullname (struct objfile *objfile, } static void -debug_qf_map_matching_symbols (struct objfile *objfile, - const char *name, domain_enum domain, - int global, - int (*callback) (const struct block *, - struct symbol *, void *), - void *data, - symbol_name_match_type match, - symbol_compare_ftype *ordered_compare) +debug_qf_map_matching_symbols + (struct objfile *objfile, + const char *name, domain_enum domain, + int global, + gdb::function_view callback, + symbol_name_match_type match, + symbol_compare_ftype *ordered_compare) { const struct debug_sym_fns_data *debug_data = symfile_debug_objfile_data_key.get (objfile); fprintf_filtered (gdb_stdlog, - "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n", + "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s)\n", objfile_debug_name (objfile), name, domain_name (domain), global, - host_address_to_string (callback), - host_address_to_string (data), plongest ((LONGEST) match), host_address_to_string (ordered_compare)); debug_data->real_sf->qf->map_matching_symbols (objfile, name, domain, global, - callback, data, + callback, match, ordered_compare); } diff --git a/gdb/symfile.h b/gdb/symfile.h index 5e4d2f5b53..cf9488881a 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -212,7 +212,7 @@ struct quick_symbol_functions and for which MATCH (symbol name, NAME) == 0, passing each to CALLBACK, reading in partial symbol tables as needed. Look through global symbols if GLOBAL and otherwise static symbols. - Passes NAME, NAMESPACE, and DATA to CALLBACK with each symbol + Passes NAME and NAMESPACE to CALLBACK with each symbol found. After each block is processed, passes NULL to CALLBACK. MATCH must be weaker than strcmp_iw_ordered in the sense that strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0. ORDERED_COMPARE, @@ -222,17 +222,16 @@ struct quick_symbol_functions and strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0 (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0). - CALLBACK returns 0 to indicate that the scan should continue, or - non-zero to indicate that the scan should be terminated. */ - - void (*map_matching_symbols) (struct objfile *, - const char *name, domain_enum domain, - int global, - int (*callback) (const struct block *, - struct symbol *, void *), - void *data, - symbol_name_match_type match, - symbol_compare_ftype *ordered_compare); + CALLBACK returns true to indicate that the scan should continue, or + false to indicate that the scan should be terminated. */ + + void (*map_matching_symbols) + (struct objfile *, + const char *name, domain_enum domain, + int global, + gdb::function_view callback, + symbol_name_match_type match, + symbol_compare_ftype *ordered_compare); /* Expand all symbol tables in OBJFILE matching some criteria. -- 2.34.1