Use function view in quick_symbol_functions::map_symbol_filenames
authorTom Tromey <tom@tromey.com>
Fri, 26 Mar 2021 19:44:24 +0000 (13:44 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 26 Mar 2021 19:44:24 +0000 (13:44 -0600)
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.

gdb/ChangeLog
gdb/dwarf2/read.c
gdb/mi/mi-cmd-file.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/quick-symbol.h
gdb/symfile-debug.c
gdb/symfile.c
gdb/symfile.h
gdb/symtab.c

index 89b3cf00bccbf6b670ce5786c95b93865d655822..f62af51671e0b76f9a0a373f364128c819346ae2 100644 (file)
@@ -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().
index 2f4b54b1aa3a39f710eb05094de1bfefef3c7f75..b324541ee9f0551127dd73d62d78ac34b3d0581d 100644 (file)
@@ -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 ());
     });
 }
 
index 55fd94fb9a7c47f8ee33d82350019592ea7de46b..430449c919e1d251f23bb38f59189b413dff4cab 100644 (file)
@@ -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);
 }
index 41f8fc913d852e911dfc36d9f42e82c4cf70f623..4cd392bd7f022e71571346a0e850395c5f27002a 100644 (file)
@@ -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);
index bbae2fc90e4e68fdfbb8ee74c2dc96d1efa97e86..193d64fbcf2ff88c967254e67394185806cf1307 100644 (file)
@@ -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
   {
index 1ea7376a8c863c5608c00f92696dca30da1d3696..b51881d3bd6fdac2134553b3179a86d0408f0056 100644 (file)
@@ -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);
     }
 }
 
index dd2b896fd5f5e5fb5b0fbf7a808a48f31cb1cbe6..d907b1df488d38693390849c22b4076de051f9ba 100644 (file)
@@ -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.  */
index 3daede88292164515ec5ffaa7f9c420781ea0847..d811809514b0e7cfd8f658b72066be8f691d6ea3 100644 (file)
@@ -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 *
index e417878031db8b7bb8cc52463475ed83b0632408..b71eb1915d287db0914dea15d7b6717f79aeed9b 100644 (file)
@@ -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
index bae2a798703ecbad0552c84e0577807d747578fe..bda1c578773b75df6aa52c84fddb13865a9d543c 100644 (file)
@@ -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.
 
index 122fdf0b1d3ea908c47069fc60b20dcbf2508a8c..9615216d6dfde31599f23113a9c43ecf3cd7bc21 100644 (file)
@@ -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;
 }