aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-26 13:44:24 -0600
committerTom Tromey <tom@tromey.com>2021-03-26 13:44:24 -0600
commitf4655dee7749516dd9f4867a58e2910a7c9610c8 (patch)
tree5c267433b9ccefa9c425905f28469604bafd9462 /gdb/symtab.c
parent2315bb2d5764527617aef124cbcd52a13395e245 (diff)
downloadgdb-f4655dee7749516dd9f4867a58e2910a7c9610c8.zip
gdb-f4655dee7749516dd9f4867a58e2910a7c9610c8.tar.gz
gdb-f4655dee7749516dd9f4867a58e2910a7c9610c8.tar.bz2
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.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c79
1 files changed, 36 insertions, 43 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 122fdf0..9615216 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<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;
}