+2021-03-26 Tom Tromey <tom@tromey.com>
+
+ * 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) <map_symbol_filenames>: Likewise.
+ * psymtab.c (psymbol_functions::map_symbol_filenames): Update.
+ * psympriv.h (struct psymbol_functions) <map_symbol_filenames>:
+ Change type of 'fun' and 'need_fullname'. Remove 'data'
+ parameter.
+ * objfiles.h (struct objfile) <map_symbol_filenames>: 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 <tom@tromey.com>
* ada-lang.c (struct match_data): Add operator().
}
void map_symbol_filenames (struct objfile *objfile,
- symbol_filename_ftype *fun, void *data,
- int need_fullname) override;
+ gdb::function_view<symbol_filename_ftype> fun,
+ bool need_fullname) override;
};
struct dwarf2_gdb_index : public dwarf2_base_index_functions
}
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<symbol_filename_ftype> fun,
+ bool need_fullname)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
if (need_fullname)
this_real_name = gdb_realpath (filename);
- (*fun) (filename, this_real_name.get (), data);
+ fun (filename, this_real_name.get ());
});
}
/* 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;
}
}
- 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);
}
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<symbol_filename_ftype> fun,
+ bool need_fullname);
/* See quick_symbol_functions. */
struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address);
(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<symbol_filename_ftype> fun,
+ bool need_fullname) override;
void relocated () override
{
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<symbol_filename_ftype> fun,
+ bool need_fullname)
{
for (partial_symtab *ps : require_partial_symbols (objfile))
{
fullname = psymtab_to_fullname (ps);
else
fullname = NULL;
- (*fun) (ps->filename, fullname, data);
+ fun (ps->filename, fullname);
}
}
/* 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. */
(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<symbol_filename_ftype> fun,
+ bool need_fullname) = 0;
/* This is called when the objfile is relocated. It can be used to
clean up any internal caches. */
}
void
-objfile::map_symbol_filenames (symbol_filename_ftype *fun, void *data,
- int need_fullname)
+objfile::map_symbol_filenames (gdb::function_view<symbol_filename_ftype> 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 *
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<symbol_filename_ftype> 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
gdb::function_view<expand_symtabs_exp_notify_ftype> 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<symbol_filename_ftype> fun,
+ bool need_fullname);
/* Target-agnostic function to load the sections of an executable into memory.
/* 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
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<filename_partial_match_opts>;
{
const char *fullname = symtab_to_fullname (s);
- output_source_filename (fullname, &data);
+ data.output (fullname);
}
}
}
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");
}
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
{
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);
}
}
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;
}