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 <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.
This commit is contained in:
parent
2315bb2d57
commit
f4655dee77
11 changed files with 100 additions and 81 deletions
|
@ -1,3 +1,32 @@
|
|||
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().
|
||||
|
|
|
@ -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<symbol_filename_ftype> 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<symbol_filename_ftype> 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 ());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<symbol_filename_ftype> fun,
|
||||
bool need_fullname);
|
||||
|
||||
/* See quick_symbol_functions. */
|
||||
struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address);
|
||||
|
|
|
@ -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<symbol_filename_ftype> fun,
|
||||
bool need_fullname) override;
|
||||
|
||||
void relocated () override
|
||||
{
|
||||
|
|
|
@ -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<symbol_filename_ftype> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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. */
|
||||
|
|
|
@ -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<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 *
|
||||
|
|
|
@ -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<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
|
||||
|
|
|
@ -328,8 +328,8 @@ void expand_symtabs_matching
|
|||
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.
|
||||
|
||||
|
|
79
gdb/symtab.c
79
gdb/symtab.c
|
@ -4227,15 +4227,21 @@ struct output_source_filename_data
|
|||
|
||||
/* Flag of whether we're printing the first one. */
|
||||
int first;
|
||||
|
||||
/* Worker for sources_info. Force line breaks at ,'s.
|
||||
NAME is the name to print. */
|
||||
void output (const char *name);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
};
|
||||
|
||||
/* 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. */
|
||||
|
||||
static void
|
||||
output_source_filename (const char *name,
|
||||
struct output_source_filename_data *data)
|
||||
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<filename_partial_match_opts>;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue