From: Tom Tromey Date: Fri, 26 Mar 2021 19:44:24 +0000 (-0600) Subject: Use function view in quick_symbol_functions::map_symbol_filenames X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f4655dee7749516dd9f4867a58e2910a7c9610c8;p=binutils-gdb.git Use function view in quick_symbol_functions::map_symbol_filenames This changes quick_symbol_functions::map_symbol_filenames to use a function_view, and updates all the uses. It also changes the final parameter to 'bool'. A couple of spots are further updated to use operator() rather than a lambda. gdb/ChangeLog 2021-03-26 Tom Tromey * symtab.c (struct output_source_filename_data): Add 'output' method and operator(). (output_source_filename_data::output): Rename from output_source_filename. (output_partial_symbol_filename): Remove. (info_sources_command): Update. (struct add_partial_filename_data): Add operator(). (add_partial_filename_data::operator()): Rename from maybe_add_partial_symtab_filename. (make_source_files_completion_list): Update. * symfile.c (quick_symbol_functions): Update. * symfile-debug.c (objfile::map_symbol_filenames): Update. * quick-symbol.h (symbol_filename_ftype): Change type of 'fun' and 'need_fullname'. Remove 'data' parameter. (struct quick_symbol_functions) : Likewise. * psymtab.c (psymbol_functions::map_symbol_filenames): Update. * psympriv.h (struct psymbol_functions) : Change type of 'fun' and 'need_fullname'. Remove 'data' parameter. * objfiles.h (struct objfile) : Change type of 'fun' and 'need_fullname'. Remove 'data' parameter. * mi/mi-cmd-file.c (print_partial_file_name): Remove 'ignore' parameter. (mi_cmd_file_list_exec_source_files): Update. * dwarf2/read.c (dwarf2_base_index_functions::map_symbol_filenames): Update. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 89b3cf00bcc..f62af51671e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,32 @@ +2021-03-26 Tom Tromey + + * symtab.c (struct output_source_filename_data): Add 'output' + method and operator(). + (output_source_filename_data::output): Rename from + output_source_filename. + (output_partial_symbol_filename): Remove. + (info_sources_command): Update. + (struct add_partial_filename_data): Add operator(). + (add_partial_filename_data::operator()): Rename from + maybe_add_partial_symtab_filename. + (make_source_files_completion_list): Update. + * symfile.c (quick_symbol_functions): Update. + * symfile-debug.c (objfile::map_symbol_filenames): Update. + * quick-symbol.h (symbol_filename_ftype): Change type of 'fun' and + 'need_fullname'. Remove 'data' parameter. + (struct quick_symbol_functions) : Likewise. + * psymtab.c (psymbol_functions::map_symbol_filenames): Update. + * psympriv.h (struct psymbol_functions) : + Change type of 'fun' and 'need_fullname'. Remove 'data' + parameter. + * objfiles.h (struct objfile) : Change type + of 'fun' and 'need_fullname'. Remove 'data' parameter. + * mi/mi-cmd-file.c (print_partial_file_name): Remove 'ignore' + parameter. + (mi_cmd_file_list_exec_source_files): Update. + * dwarf2/read.c + (dwarf2_base_index_functions::map_symbol_filenames): Update. + 2021-03-26 Tom Tromey * ada-lang.c (struct match_data): Add operator(). diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2f4b54b1aa3..b324541ee9f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2230,8 +2230,8 @@ struct dwarf2_base_index_functions : public quick_symbol_functions } void map_symbol_filenames (struct objfile *objfile, - symbol_filename_ftype *fun, void *data, - int need_fullname) override; + gdb::function_view fun, + bool need_fullname) override; }; struct dwarf2_gdb_index : public dwarf2_base_index_functions @@ -4945,10 +4945,10 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab } void -dwarf2_base_index_functions::map_symbol_filenames (struct objfile *objfile, - symbol_filename_ftype *fun, - void *data, - int need_fullname) +dwarf2_base_index_functions::map_symbol_filenames + (struct objfile *objfile, + gdb::function_view fun, + bool need_fullname) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -5009,7 +5009,7 @@ dwarf2_base_index_functions::map_symbol_filenames (struct objfile *objfile, if (need_fullname) this_real_name = gdb_realpath (filename); - (*fun) (filename, this_real_name.get (), data); + fun (filename, this_real_name.get ()); }); } diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c index 55fd94fb9a7..430449c919e 100644 --- a/gdb/mi/mi-cmd-file.c +++ b/gdb/mi/mi-cmd-file.c @@ -65,8 +65,7 @@ mi_cmd_file_list_exec_source_file (const char *command, char **argv, int argc) /* A callback for map_partial_symbol_filenames. */ static void -print_partial_file_name (const char *filename, const char *fullname, - void *ignore) +print_partial_file_name (const char *filename, const char *fullname) { struct ui_out *uiout = current_uiout; @@ -108,8 +107,7 @@ mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc) } } - map_symbol_filenames (print_partial_file_name, NULL, - 1 /*need_fullname*/); + map_symbol_filenames (print_partial_file_name, true /*need_fullname*/); uiout->end (ui_out_type_list); } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 41f8fc913d8..4cd392bd7f0 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -590,8 +590,8 @@ public: int warn_if_readin); /* See quick_symbol_functions. */ - void map_symbol_filenames (symbol_filename_ftype *fun, void *data, - int need_fullname); + void map_symbol_filenames (gdb::function_view fun, + bool need_fullname); /* See quick_symbol_functions. */ struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address); diff --git a/gdb/psympriv.h b/gdb/psympriv.h index bbae2fc90e4..193d64fbcf2 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -556,8 +556,8 @@ struct psymbol_functions : public quick_symbol_functions (struct objfile *objfile, CORE_ADDR address) override; void map_symbol_filenames (struct objfile *objfile, - symbol_filename_ftype *fun, void *data, - int need_fullname) override; + gdb::function_view fun, + bool need_fullname) override; void relocated () override { diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 1ea7376a8c8..b51881d3bd6 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1092,10 +1092,10 @@ psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile, the definition of quick_symbol_functions in symfile.h. */ void -psymbol_functions::map_symbol_filenames (struct objfile *objfile, - symbol_filename_ftype *fun, - void *data, - int need_fullname) +psymbol_functions::map_symbol_filenames + (struct objfile *objfile, + gdb::function_view fun, + bool need_fullname) { for (partial_symtab *ps : require_partial_symbols (objfile)) { @@ -1118,7 +1118,7 @@ psymbol_functions::map_symbol_filenames (struct objfile *objfile, fullname = psymtab_to_fullname (ps); else fullname = NULL; - (*fun) (ps->filename, fullname, data); + fun (ps->filename, fullname); } } diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index dd2b896fd5f..d907b1df488 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -28,7 +28,7 @@ typedef int (symbol_compare_ftype) (const char *string1, /* Callback for quick_symbol_functions->map_symbol_filenames. */ typedef void (symbol_filename_ftype) (const char *filename, - const char *fullname, void *data); + const char *fullname); /* Callback for quick_symbol_functions->expand_symtabs_matching to match a file name. */ @@ -224,12 +224,13 @@ struct quick_symbol_functions (struct objfile *objfile, CORE_ADDR address) = 0; /* Call a callback for every file defined in OBJFILE whose symtab is - not already read in. FUN is the callback. It is passed the file's - FILENAME, the file's FULLNAME (if need_fullname is non-zero), and - the DATA passed to this function. */ - virtual void map_symbol_filenames (struct objfile *objfile, - symbol_filename_ftype *fun, void *data, - int need_fullname) = 0; + not already read in. FUN is the callback. It is passed the + file's FILENAME and the file's FULLNAME (if need_fullname is + non-zero). */ + virtual void map_symbol_filenames + (struct objfile *objfile, + gdb::function_view fun, + bool need_fullname) = 0; /* This is called when the objfile is relocated. It can be used to clean up any internal caches. */ diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 3daede88292..d811809514b 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -323,19 +323,17 @@ objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol, } void -objfile::map_symbol_filenames (symbol_filename_ftype *fun, void *data, - int need_fullname) +objfile::map_symbol_filenames (gdb::function_view fun, + bool need_fullname) { if (debug_symfile) fprintf_filtered (gdb_stdlog, - "qf->map_symbol_filenames (%s, %s, %s, %d)\n", + "qf->map_symbol_filenames (%s, ..., %d)\n", objfile_debug_name (this), - host_address_to_string (fun), - host_address_to_string (data), need_fullname); for (const auto &iter : qf) - iter->map_symbol_filenames (this, fun, data, need_fullname); + iter->map_symbol_filenames (this, fun, need_fullname); } struct compunit_symtab * diff --git a/gdb/symfile.c b/gdb/symfile.c index e417878031d..b71eb1915d2 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3737,11 +3737,11 @@ expand_symtabs_matching See quick_symbol_functions.map_symbol_filenames for details. */ void -map_symbol_filenames (symbol_filename_ftype *fun, void *data, - int need_fullname) +map_symbol_filenames (gdb::function_view fun, + bool need_fullname) { for (objfile *objfile : current_program_space->objfiles ()) - objfile->map_symbol_filenames (fun, data, need_fullname); + objfile->map_symbol_filenames (fun, need_fullname); } #if GDB_SELF_TEST diff --git a/gdb/symfile.h b/gdb/symfile.h index bae2a798703..bda1c578773 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -328,8 +328,8 @@ void expand_symtabs_matching gdb::function_view expansion_notify, enum search_domain kind); -void map_symbol_filenames (symbol_filename_ftype *fun, void *data, - int need_fullname); +void map_symbol_filenames (gdb::function_view fun, + bool need_fullname); /* Target-agnostic function to load the sections of an executable into memory. diff --git a/gdb/symtab.c b/gdb/symtab.c index 122fdf0b1d3..9615216d6df 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4227,15 +4227,21 @@ struct output_source_filename_data /* Flag of whether we're printing the first one. */ int first; -}; -/* Slave routine for sources_info. Force line breaks at ,'s. - NAME is the name to print. - DATA contains the state for printing and watching for duplicates. */ + /* Worker for sources_info. Force line breaks at ,'s. + NAME is the name to print. */ + void output (const char *name); -static void -output_source_filename (const char *name, - struct output_source_filename_data *data) + /* An overload suitable for use as a callback to + quick_symbol_functions::map_symbol_filenames. */ + void operator() (const char *filename, const char *fullname) + { + output (fullname != nullptr ? fullname : filename); + } +}; + +void +output_source_filename_data::output (const char *name) { /* Since a single source file can result in several partial symbol tables, we need to avoid printing it more than once. Note: if @@ -4247,51 +4253,41 @@ output_source_filename (const char *name, symtabs; it doesn't hurt to check. */ /* Was NAME already seen? */ - if (data->filename_seen_cache->seen (name)) + if (filename_seen_cache->seen (name)) { /* Yes; don't print it again. */ return; } - /* Does it match data->regexp? */ - if (data->c_regexp.has_value ()) + /* Does it match regexp? */ + if (c_regexp.has_value ()) { const char *to_match; std::string dirname; - if (data->partial_match.dirname) + if (partial_match.dirname) { dirname = ldirname (name); to_match = dirname.c_str (); } - else if (data->partial_match.basename) + else if (partial_match.basename) to_match = lbasename (name); else to_match = name; - if (data->c_regexp->exec (to_match, 0, NULL, 0) != 0) + if (c_regexp->exec (to_match, 0, NULL, 0) != 0) return; } /* Print it and reset *FIRST. */ - if (! data->first) + if (! first) printf_filtered (", "); - data->first = 0; + first = 0; wrap_here (""); fputs_styled (name, file_name_style.style (), gdb_stdout); } -/* A callback for map_partial_symbol_filenames. */ - -static void -output_partial_symbol_filename (const char *filename, const char *fullname, - void *data) -{ - output_source_filename (fullname ? fullname : filename, - (struct output_source_filename_data *) data); -} - using isrc_flag_option_def = gdb::option::flag_option_def; @@ -4410,7 +4406,7 @@ info_sources_command (const char *args, int from_tty) { const char *fullname = symtab_to_fullname (s); - output_source_filename (fullname, &data); + data.output (fullname); } } } @@ -4421,8 +4417,7 @@ info_sources_command (const char *args, int from_tty) filenames_seen.clear (); data.first = 1; - map_symbol_filenames (output_partial_symbol_filename, &data, - 1 /*need_fullname*/); + map_symbol_filenames (data, true /*need_fullname*/); printf_filtered ("\n"); } @@ -5957,7 +5952,7 @@ not_interesting_fname (const char *fname) return 0; } -/* An object of this type is passed as the user_data argument to +/* An object of this type is passed as the callback argument to map_partial_symbol_filenames. */ struct add_partial_filename_data { @@ -5966,34 +5961,33 @@ struct add_partial_filename_data const char *word; int text_len; completion_list *list; + + void operator() (const char *filename, const char *fullname); }; /* A callback for map_partial_symbol_filenames. */ -static void -maybe_add_partial_symtab_filename (const char *filename, const char *fullname, - void *user_data) +void +add_partial_filename_data::operator() (const char *filename, + const char *fullname) { - struct add_partial_filename_data *data - = (struct add_partial_filename_data *) user_data; - if (not_interesting_fname (filename)) return; - if (!data->filename_seen_cache->seen (filename) - && filename_ncmp (filename, data->text, data->text_len) == 0) + if (!filename_seen_cache->seen (filename) + && filename_ncmp (filename, text, text_len) == 0) { /* This file matches for a completion; add it to the current list of matches. */ - add_filename_to_list (filename, data->text, data->word, data->list); + add_filename_to_list (filename, text, word, list); } else { const char *base_name = lbasename (filename); if (base_name != filename - && !data->filename_seen_cache->seen (base_name) - && filename_ncmp (base_name, data->text, data->text_len) == 0) - add_filename_to_list (base_name, data->text, data->word, data->list); + && !filename_seen_cache->seen (base_name) + && filename_ncmp (base_name, text, text_len) == 0) + add_filename_to_list (base_name, text, word, list); } } @@ -6050,8 +6044,7 @@ make_source_files_completion_list (const char *text, const char *word) datum.word = word; datum.text_len = text_len; datum.list = &list; - map_symbol_filenames (maybe_add_partial_symtab_filename, &datum, - 0 /*need_fullname*/); + map_symbol_filenames (datum, false /*need_fullname*/); return list; }