Convert quick_symbol_functions to use methods
authorTom Tromey <tom@tromey.com>
Sat, 20 Mar 2021 23:23:40 +0000 (17:23 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 20 Mar 2021 23:23:42 +0000 (17:23 -0600)
This changes quick_symbol_functions to be a base class with pure
virtual methods, rather than a struct holding function pointers.
Then, objfile is changed to hold a unique_ptr to an instance of this
class.

struct psymbol_functions is put into psympriv.h, and not psymtab.c,
because that is convenient later in the series.

gdb/ChangeLog
2021-03-20  Tom Tromey  <tom@tromey.com>

* psympriv.h (struct psymbol_functions): New.
* symfile.c (syms_from_objfile_1, reread_symbols): Update.
* symfile-debug.c (objfile::find_compunit_symtab_by_address)
(objfile::lookup_global_symbol_language): Update.
* quick-symbol.h (struct quick_symbol_functions): Convert function
pointers to methods.  Add virtual destructor.
(quick_symbol_functions_up): New typedef.
* psymtab.h (psym_functions, dwarf2_gdb_index_functions)
(dwarf2_debug_names_functions): Don't declare.
(make_psymbol_functions): Declare.
* psymtab.c (psymbol_functions::map_symtabs_matching_filename)
(psymbol_functions::find_pc_sect_compunit_symtab)
(psymbol_functions::lookup_symbol)
(psymbol_functions::lookup_global_symbol_language)
(psymbol_functions::find_last_source_symtab)
(psymbol_functions::forget_cached_source_info)
(psymbol_functions::print_stats, psymbol_functions::dump)
(psymbol_functions::expand_symtabs_for_function)
(psymbol_functions::expand_all_symtabs)
(psymbol_functions::expand_symtabs_with_fullname)
(psymbol_functions::map_symbol_filenames)
(psymbol_functions::map_matching_symbols)
(psymbol_functions::expand_symtabs_matching)
(psymbol_functions::has_symbols)
(psymbol_functions::find_compunit_symtab_by_address): Rename.
(psym_functions): Remove.
(make_psymbol_functions): New function.
* objfiles.h (struct objfile) <qf>: Change type.
* elfread.c (elf_symfile_read): Update.
* dwarf2/read.c (struct dwarf2_base_index_functions)
(struct dwarf2_gdb_index, struct dwarf2_debug_names_index): New.
(make_dwarf_gdb_index, make_dwarf_debug_names): New functions.
(dwarf2_base_index_functions::find_last_source_symtab)
(dwarf2_base_index_functions::forget_cached_source_info)
(dwarf2_base_index_functions::map_symtabs_matching_filename)
(dwarf2_gdb_index::lookup_symbol)
(dwarf2_base_index_functions::print_stats)
(dwarf2_gdb_index::dump)
(dwarf2_gdb_index::expand_symtabs_for_function)
(dwarf2_base_index_functions::expand_all_symtabs)
(dwarf2_base_index_functions::expand_symtabs_with_fullname):
Rename.
(dwarf2_gdb_index::map_matching_symbols): New method.
(dwarf2_gdb_index::expand_symtabs_matching): New method.
(dwarf2_base_index_functions::find_pc_sect_compunit_symtab)
(dwarf2_base_index_functions::map_symbol_filenames)
(dwarf2_base_index_functions::has_symbols): Rename.
(dwarf2_gdb_index_functions): Remove.
(dwarf2_debug_names_index::lookup_symbol)
(dwarf2_debug_names_index::dump)
(dwarf2_debug_names_index::expand_symtabs_for_function)
(dwarf2_debug_names_index::map_matching_symbols)
(dwarf2_debug_names_index::expand_symtabs_matching): Rename.
(dwarf2_debug_names_functions): Remove.
* dwarf2/public.h (make_dwarf_gdb_index, make_dwarf_debug_names):
Declare.

gdb/ChangeLog
gdb/dwarf2/public.h
gdb/dwarf2/read.c
gdb/elfread.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/psymtab.h
gdb/quick-symbol.h
gdb/symfile-debug.c
gdb/symfile.c

index 55487d416b6df691b62a4bdf8331dd1e9ef8c412..1ab402b60ea6eb724ebd736f96e6d488d72e3f02 100644 (file)
@@ -1,3 +1,62 @@
+2021-03-20  Tom Tromey  <tom@tromey.com>
+
+       * psympriv.h (struct psymbol_functions): New.
+       * symfile.c (syms_from_objfile_1, reread_symbols): Update.
+       * symfile-debug.c (objfile::find_compunit_symtab_by_address)
+       (objfile::lookup_global_symbol_language): Update.
+       * quick-symbol.h (struct quick_symbol_functions): Convert function
+       pointers to methods.  Add virtual destructor.
+       (quick_symbol_functions_up): New typedef.
+       * psymtab.h (psym_functions, dwarf2_gdb_index_functions)
+       (dwarf2_debug_names_functions): Don't declare.
+       (make_psymbol_functions): Declare.
+       * psymtab.c (psymbol_functions::map_symtabs_matching_filename)
+       (psymbol_functions::find_pc_sect_compunit_symtab)
+       (psymbol_functions::lookup_symbol)
+       (psymbol_functions::lookup_global_symbol_language)
+       (psymbol_functions::find_last_source_symtab)
+       (psymbol_functions::forget_cached_source_info)
+       (psymbol_functions::print_stats, psymbol_functions::dump)
+       (psymbol_functions::expand_symtabs_for_function)
+       (psymbol_functions::expand_all_symtabs)
+       (psymbol_functions::expand_symtabs_with_fullname)
+       (psymbol_functions::map_symbol_filenames)
+       (psymbol_functions::map_matching_symbols)
+       (psymbol_functions::expand_symtabs_matching)
+       (psymbol_functions::has_symbols)
+       (psymbol_functions::find_compunit_symtab_by_address): Rename.
+       (psym_functions): Remove.
+       (make_psymbol_functions): New function.
+       * objfiles.h (struct objfile) <qf>: Change type.
+       * elfread.c (elf_symfile_read): Update.
+       * dwarf2/read.c (struct dwarf2_base_index_functions)
+       (struct dwarf2_gdb_index, struct dwarf2_debug_names_index): New.
+       (make_dwarf_gdb_index, make_dwarf_debug_names): New functions.
+       (dwarf2_base_index_functions::find_last_source_symtab)
+       (dwarf2_base_index_functions::forget_cached_source_info)
+       (dwarf2_base_index_functions::map_symtabs_matching_filename)
+       (dwarf2_gdb_index::lookup_symbol)
+       (dwarf2_base_index_functions::print_stats)
+       (dwarf2_gdb_index::dump)
+       (dwarf2_gdb_index::expand_symtabs_for_function)
+       (dwarf2_base_index_functions::expand_all_symtabs)
+       (dwarf2_base_index_functions::expand_symtabs_with_fullname):
+       Rename.
+       (dwarf2_gdb_index::map_matching_symbols): New method.
+       (dwarf2_gdb_index::expand_symtabs_matching): New method.
+       (dwarf2_base_index_functions::find_pc_sect_compunit_symtab)
+       (dwarf2_base_index_functions::map_symbol_filenames)
+       (dwarf2_base_index_functions::has_symbols): Rename.
+       (dwarf2_gdb_index_functions): Remove.
+       (dwarf2_debug_names_index::lookup_symbol)
+       (dwarf2_debug_names_index::dump)
+       (dwarf2_debug_names_index::expand_symtabs_for_function)
+       (dwarf2_debug_names_index::map_matching_symbols)
+       (dwarf2_debug_names_index::expand_symtabs_matching): Rename.
+       (dwarf2_debug_names_functions): Remove.
+       * dwarf2/public.h (make_dwarf_gdb_index, make_dwarf_debug_names):
+       Declare.
+
 2021-03-20  Tom Tromey  <tom@tromey.com>
 
        * psymtab.c (require_partial_symbols): Check that 'sf' is not
index d0182d4e673bdd7e87e2ea45d6cadc143bf8f9d2..6b0fe0874b2b13ba524572d65d5198c3f1c5346e 100644 (file)
@@ -43,4 +43,7 @@ extern bool dwarf2_initialize_objfile (struct objfile *objfile,
 extern void dwarf2_build_psymtabs (struct objfile *);
 extern void dwarf2_build_frame_info (struct objfile *);
 
+extern quick_symbol_functions_up make_dwarf_gdb_index ();
+extern quick_symbol_functions_up make_dwarf_debug_names ();
+
 #endif /* DWARF2_PUBLIC_H */
index 744b6bca2488d30d8b2d5143634d2275e6810961..19e5cdb6d5abd377ce87658c20195fa32ae161cb 100644 (file)
@@ -2150,7 +2150,7 @@ dwarf2_get_section_info (struct objfile *objfile,
 }
 
 \f
-/* DWARF quick_symbols_functions support.  */
+/* DWARF quick_symbol_functions support.  */
 
 /* TUs can share .debug_line entries, and there can be a lot more TUs than
    unique line tables, so we maintain a separate table of all .debug_line
@@ -2193,6 +2193,119 @@ struct dwarf2_per_cu_quick_data
   unsigned int no_file_data : 1;
 };
 
+struct dwarf2_base_index_functions : public quick_symbol_functions
+{
+  bool has_symbols (struct objfile *objfile) override;
+
+  struct symtab *find_last_source_symtab (struct objfile *objfile) override;
+
+  void forget_cached_source_info (struct objfile *objfile) override;
+
+  bool map_symtabs_matching_filename
+    (struct objfile *objfile, const char *name, const char *real_path,
+     gdb::function_view<bool (symtab *)> callback) override;
+
+  enum language lookup_global_symbol_language (struct objfile *objfile,
+                                              const char *name,
+                                              domain_enum domain,
+                                              bool *symbol_found_p) override
+  {
+    *symbol_found_p = false;
+    return language_unknown;
+  }
+
+  void print_stats (struct objfile *objfile) override;
+
+  void expand_all_symtabs (struct objfile *objfile) override;
+
+  void expand_symtabs_with_fullname (struct objfile *objfile,
+                                    const char *fullname) override;
+
+  struct compunit_symtab *find_pc_sect_compunit_symtab
+    (struct objfile *objfile, struct bound_minimal_symbol msymbol,
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override;
+
+  struct compunit_symtab *find_compunit_symtab_by_address
+    (struct objfile *objfile, CORE_ADDR address) override
+  {
+    return nullptr;
+  }
+
+  void map_symbol_filenames (struct objfile *objfile,
+                            symbol_filename_ftype *fun, void *data,
+                            int need_fullname) override;
+};
+
+struct dwarf2_gdb_index : public dwarf2_base_index_functions
+{
+  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+                                        block_enum block_index,
+                                        const char *name,
+                                        domain_enum domain) override;
+
+  void dump (struct objfile *objfile) override;
+
+  void expand_symtabs_for_function (struct objfile *objfile,
+                                   const char *func_name) override;
+
+  void map_matching_symbols
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare) override;
+
+  void expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind) override;
+};
+
+struct dwarf2_debug_names_index : public dwarf2_base_index_functions
+{
+  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+                                        block_enum block_index,
+                                        const char *name,
+                                        domain_enum domain) override;
+
+  void dump (struct objfile *objfile) override;
+
+  void expand_symtabs_for_function (struct objfile *objfile,
+                                   const char *func_name) override;
+
+  void map_matching_symbols
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare) override;
+
+  void expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind) override;
+};
+
+quick_symbol_functions_up
+make_dwarf_gdb_index ()
+{
+  return quick_symbol_functions_up (new dwarf2_gdb_index);
+}
+
+quick_symbol_functions_up
+make_dwarf_debug_names ()
+{
+  return quick_symbol_functions_up (new dwarf2_debug_names_index);
+}
+
 /* Utility hash function for a stmt_list_hash.  */
 
 static hashval_t
@@ -3206,8 +3319,8 @@ dw2_get_real_path (dwarf2_per_objfile *per_objfile,
   return qfn->real_names[index];
 }
 
-static struct symtab *
-dw2_find_last_source_symtab (struct objfile *objfile)
+struct symtab *
+dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   dwarf2_per_cu_data *dwarf_cu = per_objfile->per_bfd->all_comp_units.back ();
@@ -3240,8 +3353,9 @@ dw2_free_cached_file_names (void **slot, void *info)
   return 1;
 }
 
-static void
-dw2_forget_cached_source_info (struct objfile *objfile)
+void
+dwarf2_base_index_functions::forget_cached_source_info
+     (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3275,8 +3389,8 @@ dw2_map_expand_apply (struct objfile *objfile,
 
 /* Implementation of the map_symtabs_matching_filename method.  */
 
-static bool
-dw2_map_symtabs_matching_filename
+bool
+dwarf2_base_index_functions::map_symtabs_matching_filename
   (struct objfile *objfile, const char *name, const char *real_path,
    gdb::function_view<bool (symtab *)> callback)
 {
@@ -3525,9 +3639,10 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
   return NULL;
 }
 
-static struct compunit_symtab *
-dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
-                  const char *name, domain_enum domain)
+struct compunit_symtab *
+dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
+                                block_enum block_index,
+                                const char *name, domain_enum domain)
 {
   struct compunit_symtab *stab_best = NULL;
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -3568,8 +3683,8 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index,
   return stab_best;
 }
 
-static void
-dw2_print_stats (struct objfile *objfile)
+void
+dwarf2_base_index_functions::print_stats (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total = (per_objfile->per_bfd->all_comp_units.size ()
@@ -3592,8 +3707,8 @@ dw2_print_stats (struct objfile *objfile)
    One use is to verify .gdb_index has been loaded by the
    gdb.dwarf2/gdb-index.exp testcase.  */
 
-static void
-dw2_dump (struct objfile *objfile)
+void
+dwarf2_gdb_index::dump (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3609,9 +3724,9 @@ dw2_dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-static void
-dw2_expand_symtabs_for_function (struct objfile *objfile,
-                                const char *func_name)
+void
+dwarf2_gdb_index::expand_symtabs_for_function (struct objfile *objfile,
+                                              const char *func_name)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3625,8 +3740,8 @@ dw2_expand_symtabs_for_function (struct objfile *objfile,
 
 }
 
-static void
-dw2_expand_all_symtabs (struct objfile *objfile)
+void
+dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   int total_units = (per_objfile->per_bfd->all_comp_units.size ()
@@ -3645,9 +3760,9 @@ dw2_expand_all_symtabs (struct objfile *objfile)
     }
 }
 
-static void
-dw2_expand_symtabs_with_fullname (struct objfile *objfile,
-                                 const char *fullname)
+void
+dwarf2_base_index_functions::expand_symtabs_with_fullname
+     (struct objfile *objfile, const char *fullname)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -3753,6 +3868,18 @@ dw2_map_matching_symbols
     }
 }
 
+void
+dwarf2_gdb_index::map_matching_symbols
+  (struct objfile *objfile,
+   const lookup_name_info &name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_compare_ftype *ordered_compare)
+{
+  dw2_map_matching_symbols (objfile, name, domain, global, callback,
+                           ordered_compare);
+}
+
 /* Starting from a search name, return the string that finds the upper
    bound of all strings that start with SEARCH_NAME in a sorted name
    list.  Returns the empty string to indicate that the upper bound is
@@ -4746,6 +4873,19 @@ dw2_expand_symtabs_matching
     }, per_objfile);
 }
 
+void
+dwarf2_gdb_index::expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind)
+{
+  dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
+                              symbol_matcher, expansion_notify, kind);
+}
+
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
    symtab.  */
 
@@ -4774,12 +4914,13 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
   return NULL;
 }
 
-static struct compunit_symtab *
-dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
-                                 struct bound_minimal_symbol msymbol,
-                                 CORE_ADDR pc,
-                                 struct obj_section *section,
-                                 int warn_if_readin)
+struct compunit_symtab *
+dwarf2_base_index_functions::find_pc_sect_compunit_symtab
+     (struct objfile *objfile,
+      struct bound_minimal_symbol msymbol,
+      CORE_ADDR pc,
+      struct obj_section *section,
+      int warn_if_readin)
 {
   struct dwarf2_per_cu_data *data;
   struct compunit_symtab *result;
@@ -4805,9 +4946,11 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
   return result;
 }
 
-static void
-dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
-                         void *data, int need_fullname)
+void
+dwarf2_base_index_functions::map_symbol_filenames (struct objfile *objfile,
+                                                  symbol_filename_ftype *fun,
+                                                  void *data,
+                                                  int need_fullname)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -4872,32 +5015,12 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
     });
 }
 
-static bool
-dw2_has_symbols (struct objfile *objfile)
+bool
+dwarf2_base_index_functions::has_symbols (struct objfile *objfile)
 {
   return true;
 }
 
-const struct quick_symbol_functions dwarf2_gdb_index_functions =
-{
-  dw2_has_symbols,
-  dw2_find_last_source_symtab,
-  dw2_forget_cached_source_info,
-  dw2_map_symtabs_matching_filename,
-  dw2_lookup_symbol,
-  NULL,
-  dw2_print_stats,
-  dw2_dump,
-  dw2_expand_symtabs_for_function,
-  dw2_expand_all_symtabs,
-  dw2_expand_symtabs_with_fullname,
-  dw2_map_matching_symbols,
-  dw2_expand_symtabs_matching,
-  dw2_find_pc_sect_compunit_symtab,
-  NULL,
-  dw2_map_symbol_filenames
-};
-
 /* DWARF-5 debug_names reader.  */
 
 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension.  */
@@ -5632,9 +5755,10 @@ dw2_debug_names_iterator::next ()
   return per_cu;
 }
 
-static struct compunit_symtab *
-dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
-                              const char *name, domain_enum domain)
+struct compunit_symtab *
+dwarf2_debug_names_index::lookup_symbol
+     (struct objfile *objfile, block_enum block_index,
+      const char *name, domain_enum domain)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5683,8 +5807,8 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index,
    via "mt print objfiles".  The gdb.dwarf2/gdb-index.exp testcase
    uses this to verify that .debug_names has been loaded.  */
 
-static void
-dw2_debug_names_dump (struct objfile *objfile)
+void
+dwarf2_debug_names_index::dump (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5697,9 +5821,9 @@ dw2_debug_names_dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-static void
-dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
-                                            const char *func_name)
+void
+dwarf2_debug_names_index::expand_symtabs_for_function
+     (struct objfile *objfile, const char *func_name)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
@@ -5717,8 +5841,8 @@ dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
     }
 }
 
-static void
-dw2_debug_names_map_matching_symbols
+void
+dwarf2_debug_names_index::map_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
@@ -5775,8 +5899,8 @@ dw2_debug_names_map_matching_symbols
     }
 }
 
-static void
-dw2_debug_names_expand_symtabs_matching
+void
+dwarf2_debug_names_index::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
@@ -5822,26 +5946,6 @@ dw2_debug_names_expand_symtabs_matching
     }, per_objfile);
 }
 
-const struct quick_symbol_functions dwarf2_debug_names_functions =
-{
-  dw2_has_symbols,
-  dw2_find_last_source_symtab,
-  dw2_forget_cached_source_info,
-  dw2_map_symtabs_matching_filename,
-  dw2_debug_names_lookup_symbol,
-  NULL,
-  dw2_print_stats,
-  dw2_debug_names_dump,
-  dw2_debug_names_expand_symtabs_for_function,
-  dw2_expand_all_symtabs,
-  dw2_expand_symtabs_with_fullname,
-  dw2_debug_names_map_matching_symbols,
-  dw2_debug_names_expand_symtabs_matching,
-  dw2_find_pc_sect_compunit_symtab,
-  NULL,
-  dw2_map_symbol_filenames
-};
-
 /* Get the content of the .gdb_index section of OBJ.  SECTION_OWNER should point
    to either a dwarf2_per_bfd or dwz_file object.  */
 
index 3ba7221bfc9548f10fe50f549fa6cd8432da7d87..4ca1f4d5284c59d32d2359b32aea568837c18277 100644 (file)
@@ -1270,10 +1270,10 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
          switch (index_kind)
            {
            case dw_index_kind::GDB_INDEX:
-             objfile->qf = &dwarf2_gdb_index_functions;
+             objfile->qf = make_dwarf_gdb_index ();
              break;
            case dw_index_kind::DEBUG_NAMES:
-             objfile->qf = &dwarf2_debug_names_functions;
+             objfile->qf = make_dwarf_debug_names ();
              break;
            }
        }
index 8d4a23ae0447e9a441184a11925d26af2b4a621d..7235713cbdf2cab133d7ce5c8c3c1b206a07c4ea 100644 (file)
@@ -37,6 +37,7 @@
 #include "gdbarch.h"
 #include "gdbsupport/refcounted-object.h"
 #include "jit.h"
+#include "quick-symbol.h"
 
 struct htab;
 struct objfile_data;
@@ -679,7 +680,7 @@ public:
 
   /* The "quick" (aka partial) symbol functions for this symbol
      reader.  */
-  const struct quick_symbol_functions *qf = nullptr;
+  quick_symbol_functions_up qf;
 
   /* Per objfile data-pointers required by other GDB modules.  */
 
index 1f35ef2a44b9b1bcef30511665fe5c15c2f0d48a..6b9ee184e9c2aa2a9b333731b45a46940bb82a4f 100644 (file)
@@ -473,4 +473,68 @@ class psymtab_discarder
   struct partial_symtab *m_psymtab;
 };
 
+/* An implementation of quick_symbol_functions, specialized for
+   partial symbols.  */
+struct psymbol_functions : public quick_symbol_functions
+{
+  bool has_symbols (struct objfile *objfile) override;
+
+  struct symtab *find_last_source_symtab (struct objfile *objfile) override;
+
+  void forget_cached_source_info (struct objfile *objfile) override;
+
+  bool map_symtabs_matching_filename
+    (struct objfile *objfile, const char *name, const char *real_path,
+     gdb::function_view<bool (symtab *)> callback) override;
+
+  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+                                        block_enum block_index,
+                                        const char *name,
+                                        domain_enum domain) override;
+
+  enum language lookup_global_symbol_language (struct objfile *objfile,
+                                              const char *name,
+                                              domain_enum domain,
+                                              bool *symbol_found_p) override;
+
+  void print_stats (struct objfile *objfile) override;
+
+  void dump (struct objfile *objfile) override;
+
+  void expand_symtabs_for_function (struct objfile *objfile,
+                                   const char *func_name) override;
+
+  void expand_all_symtabs (struct objfile *objfile) override;
+
+  void expand_symtabs_with_fullname (struct objfile *objfile,
+                                    const char *fullname) override;
+
+  void map_matching_symbols
+    (struct objfile *,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_compare_ftype *ordered_compare) override;
+
+  void expand_symtabs_matching
+    (struct objfile *objfile,
+     gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
+     const lookup_name_info *lookup_name,
+     gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
+     gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     enum search_domain kind) override;
+
+  struct compunit_symtab *find_pc_sect_compunit_symtab
+    (struct objfile *objfile, struct bound_minimal_symbol msymbol,
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override;
+
+  struct compunit_symtab *find_compunit_symtab_by_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;
+};
+
 #endif /* PSYMPRIV_H */
index 8c02fa253dcabd5a190642a75f17de7cc5607674..c022daa7894255d3ec47255bf181b5bceb18e756 100644 (file)
@@ -132,8 +132,8 @@ partial_map_expand_apply (struct objfile *objfile,
 /*  Psymtab version of map_symtabs_matching_filename.  See its definition in
     the definition of quick_symbol_functions in symfile.h.  */
 
-static bool
-psym_map_symtabs_matching_filename
+bool
+psymbol_functions::map_symtabs_matching_filename
   (struct objfile *objfile,
    const char *name,
    const char *real_path,
@@ -359,12 +359,13 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 /* Psymtab version of find_pc_sect_compunit_symtab.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static struct compunit_symtab *
-psym_find_pc_sect_compunit_symtab (struct objfile *objfile,
-                                  struct bound_minimal_symbol msymbol,
-                                  CORE_ADDR pc,
-                                  struct obj_section *section,
-                                  int warn_if_readin)
+struct compunit_symtab *
+psymbol_functions::find_pc_sect_compunit_symtab
+     (struct objfile *objfile,
+      struct bound_minimal_symbol msymbol,
+      CORE_ADDR pc,
+      struct obj_section *section,
+      int warn_if_readin)
 {
   struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
                                                    msymbol);
@@ -449,10 +450,10 @@ find_pc_sect_psymbol (struct objfile *objfile,
 /* Psymtab version of lookup_symbol.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static struct compunit_symtab *
-psym_lookup_symbol (struct objfile *objfile,
-                   block_enum block_index, const char *name,
-                   const domain_enum domain)
+struct compunit_symtab *
+psymbol_functions::lookup_symbol (struct objfile *objfile,
+                                 block_enum block_index, const char *name,
+                                 const domain_enum domain)
 {
   const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
   struct compunit_symtab *stab_best = NULL;
@@ -500,9 +501,11 @@ psym_lookup_symbol (struct objfile *objfile,
 /* Psymtab version of lookup_global_symbol_language.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static enum language
-psym_lookup_global_symbol_language (struct objfile *objfile, const char *name,
-                                   domain_enum domain, bool *symbol_found_p)
+enum language
+psymbol_functions::lookup_global_symbol_language (struct objfile *objfile,
+                                                 const char *name,
+                                                 domain_enum domain,
+                                                 bool *symbol_found_p)
 {
   *symbol_found_p = false;
   if (objfile->sf == NULL)
@@ -754,8 +757,8 @@ psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
 /* Psymtab version of find_last_source_symtab.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static struct symtab *
-psym_find_last_source_symtab (struct objfile *ofp)
+struct symtab *
+psymbol_functions::find_last_source_symtab (struct objfile *ofp)
 {
   struct partial_symtab *cs_pst = NULL;
 
@@ -792,8 +795,8 @@ psym_find_last_source_symtab (struct objfile *ofp)
 /* Psymtab version of forget_cached_source_info.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_forget_cached_source_info (struct objfile *objfile)
+void
+psymbol_functions::forget_cached_source_info (struct objfile *objfile)
 {
   for (partial_symtab *pst : require_partial_symbols (objfile, true))
     {
@@ -975,8 +978,8 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
 /* Psymtab version of print_stats.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_print_stats (struct objfile *objfile)
+void
+psymbol_functions::print_stats (struct objfile *objfile)
 {
   int i;
 
@@ -992,8 +995,8 @@ psym_print_stats (struct objfile *objfile)
 /* Psymtab version of dump.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_dump (struct objfile *objfile)
+void
+psymbol_functions::dump (struct objfile *objfile)
 {
   struct partial_symtab *psymtab;
 
@@ -1017,9 +1020,9 @@ psym_dump (struct objfile *objfile)
 /* Psymtab version of expand_symtabs_for_function.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_symtabs_for_function (struct objfile *objfile,
-                                 const char *func_name)
+void
+psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
+                                               const char *func_name)
 {
   lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
   lookup_name_info lookup_name = base_lookup.make_ignore_params ();
@@ -1040,8 +1043,8 @@ psym_expand_symtabs_for_function (struct objfile *objfile,
 /* Psymtab version of expand_all_symtabs.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_all_symtabs (struct objfile *objfile)
+void
+psymbol_functions::expand_all_symtabs (struct objfile *objfile)
 {
   for (partial_symtab *psymtab : require_partial_symbols (objfile, true))
     psymtab_to_symtab (objfile, psymtab);
@@ -1050,9 +1053,9 @@ psym_expand_all_symtabs (struct objfile *objfile)
 /* Psymtab version of expand_symtabs_with_fullname.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_symtabs_with_fullname (struct objfile *objfile,
-                                  const char *fullname)
+void
+psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile,
+                                                const char *fullname)
 {
   for (partial_symtab *p : require_partial_symbols (objfile, true))
     {
@@ -1072,10 +1075,11 @@ psym_expand_symtabs_with_fullname (struct objfile *objfile,
 /* Psymtab version of map_symbol_filenames.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_map_symbol_filenames (struct objfile *objfile,
-                          symbol_filename_ftype *fun, void *data,
-                          int need_fullname)
+void
+psymbol_functions::map_symbol_filenames (struct objfile *objfile,
+                                        symbol_filename_ftype *fun,
+                                        void *data,
+                                        int need_fullname)
 {
   for (partial_symtab *ps : require_partial_symbols (objfile, true))
     {
@@ -1148,8 +1152,8 @@ psymtab_to_fullname (struct partial_symtab *ps)
 /* Psymtab version of map_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_map_matching_symbols
+void
+psymbol_functions::map_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
@@ -1273,8 +1277,8 @@ recursively_search_psymtabs
 /* Psymtab version of expand_symtabs_matching.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static void
-psym_expand_symtabs_matching
+void
+psymbol_functions::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
@@ -1335,8 +1339,8 @@ psym_expand_symtabs_matching
 /* Psymtab version of has_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-static bool
-psym_has_symbols (struct objfile *objfile)
+bool
+psymbol_functions::has_symbols (struct objfile *objfile)
 {
   return objfile->partial_symtabs->psymtabs != NULL;
 }
@@ -1367,9 +1371,9 @@ psym_fill_psymbol_map (struct objfile *objfile,
 /* See find_compunit_symtab_by_address in quick_symbol_functions, in
    symfile.h.  */
 
-static compunit_symtab *
-psym_find_compunit_symtab_by_address (struct objfile *objfile,
-                                     CORE_ADDR address)
+compunit_symtab *
+psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile,
+                                                   CORE_ADDR address)
 {
   if (objfile->psymbol_map.empty ())
     {
@@ -1409,25 +1413,11 @@ psym_find_compunit_symtab_by_address (struct objfile *objfile,
   return psymtab_to_symtab (objfile, iter->second);
 }
 
-const struct quick_symbol_functions psym_functions =
+quick_symbol_functions_up
+make_psymbol_functions ()
 {
-  psym_has_symbols,
-  psym_find_last_source_symtab,
-  psym_forget_cached_source_info,
-  psym_map_symtabs_matching_filename,
-  psym_lookup_symbol,
-  psym_lookup_global_symbol_language,
-  psym_print_stats,
-  psym_dump,
-  psym_expand_symtabs_for_function,
-  psym_expand_all_symtabs,
-  psym_expand_symtabs_with_fullname,
-  psym_map_matching_symbols,
-  psym_expand_symtabs_matching,
-  psym_find_pc_sect_compunit_symtab,
-  psym_find_compunit_symtab_by_address,
-  psym_map_symbol_filenames
-};
+  return quick_symbol_functions_up (new psymbol_functions);
+}
 
 \f
 
index dbff302b1d1854cfe27dc9b17d02e4bcfad0df2e..45eaf0b9013950f48686481fbb12ad8138b2f1c3 100644 (file)
@@ -146,11 +146,6 @@ private:
 };
 
 
-extern const struct quick_symbol_functions psym_functions;
-
-extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
-extern const struct quick_symbol_functions dwarf2_debug_names_functions;
-
 /* Ensure that the partial symbols for OBJFILE have been loaded.  If
    VERBOSE is true, then this will print a message when symbols
    are loaded.  This function returns a range adapter suitable for
@@ -159,4 +154,6 @@ extern const struct quick_symbol_functions dwarf2_debug_names_functions;
 extern psymtab_storage::partial_symtab_range require_partial_symbols
     (struct objfile *objfile, bool verbose);
 
+extern quick_symbol_functions_up make_psymbol_functions ();
+
 #endif /* PSYMTAB_H */
index fa5f5012211989d2e2101751049037a83b8ed2a6..85e7a32eacd9441b9c2ed2e28eccb3439318fe3e 100644 (file)
@@ -66,16 +66,20 @@ typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
 
 struct quick_symbol_functions
 {
+  virtual ~quick_symbol_functions ()
+  {
+  }
+
   /* Return true if this objfile has any "partial" symbols
      available.  */
-  bool (*has_symbols) (struct objfile *objfile);
+  virtual bool has_symbols (struct objfile *objfile) = 0;
 
   /* Return the symbol table for the "last" file appearing in
      OBJFILE.  */
-  struct symtab *(*find_last_source_symtab) (struct objfile *objfile);
+  virtual struct symtab *find_last_source_symtab (struct objfile *objfile) = 0;
 
   /* Forget all cached full file names for OBJFILE.  */
-  void (*forget_cached_source_info) (struct objfile *objfile);
+  virtual void forget_cached_source_info (struct objfile *objfile) = 0;
 
   /* Expand and iterate over each "partial" symbol table in OBJFILE
      where the source file is named NAME.
@@ -89,9 +93,9 @@ struct quick_symbol_functions
      Then, this calls iterate_over_some_symtabs (or equivalent) over
      all newly-created symbol tables, passing CALLBACK to it.
      The result of this call is returned.  */
-  bool (*map_symtabs_matching_filename)
+  virtual bool map_symtabs_matching_filename
     (struct objfile *objfile, const char *name, const char *real_path,
-     gdb::function_view<bool (symtab *)> callback);
+     gdb::function_view<bool (symtab *)> callback) = 0;
 
   /* Check to see if the symbol is defined in a "partial" symbol table
      of OBJFILE.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
@@ -103,10 +107,10 @@ struct quick_symbol_functions
      defined, or NULL if no such symbol table exists.  If OBJFILE
      contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
      only TYPE_OPAQUE symbol(s), return at least that compunit.  */
-  struct compunit_symtab *(*lookup_symbol) (struct objfile *objfile,
-                                           block_enum block_index,
-                                           const char *name,
-                                           domain_enum domain);
+  virtual struct compunit_symtab *lookup_symbol (struct objfile *objfile,
+                                                block_enum block_index,
+                                                const char *name,
+                                                domain_enum domain) = 0;
 
   /* Check to see if the global symbol is defined in a "partial" symbol table
      of OBJFILE. NAME is the name of the symbol to look for.  DOMAIN
@@ -114,35 +118,36 @@ struct quick_symbol_functions
 
      If found, sets *symbol_found_p to true and returns the symbol language.
      defined, or NULL if no such symbol table exists.  */
-  enum language (*lookup_global_symbol_language) (struct objfile *objfile,
-                                                 const char *name,
-                                                 domain_enum domain,
-                                                 bool *symbol_found_p);
+  virtual enum language lookup_global_symbol_language
+       (struct objfile *objfile,
+       const char *name,
+       domain_enum domain,
+       bool *symbol_found_p) = 0;
 
   /* Print statistics about any indices loaded for OBJFILE.  The
      statistics should be printed to gdb_stdout.  This is used for
      "maint print statistics".  */
-  void (*print_stats) (struct objfile *objfile);
+  virtual void print_stats (struct objfile *objfile) = 0;
 
   /* Dump any indices loaded for OBJFILE.  The dump should go to
      gdb_stdout.  This is used for "maint print objfiles".  */
-  void (*dump) (struct objfile *objfile);
+  virtual void dump (struct objfile *objfile) = 0;
 
   /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
      the corresponding symbol tables are loaded.  */
-  void (*expand_symtabs_for_function) (struct objfile *objfile,
-                                      const char *func_name);
+  virtual void expand_symtabs_for_function (struct objfile *objfile,
+                                           const char *func_name) = 0;
 
   /* Read all symbol tables associated with OBJFILE.  */
-  void (*expand_all_symtabs) (struct objfile *objfile);
+  virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
   /* Read all symbol tables associated with OBJFILE which have
      symtab_to_fullname equal to FULLNAME.
      This is for the purposes of examining code only, e.g., expand_line_sal.
      The routine may ignore debug info that is known to not be useful with
      code, e.g., DW_TAG_type_unit for dwarf debug info.  */
-  void (*expand_symtabs_with_fullname) (struct objfile *objfile,
-                                       const char *fullname);
+  virtual void expand_symtabs_with_fullname (struct objfile *objfile,
+                                            const char *fullname) = 0;
 
   /* Find global or static symbols in all tables that are in DOMAIN
      and for which MATCH (symbol name, NAME) == 0, passing each to 
@@ -161,13 +166,13 @@ struct quick_symbol_functions
      CALLBACK returns true to indicate that the scan should continue, or
      false to indicate that the scan should be terminated.  */
 
-  void (*map_matching_symbols)
+  virtual void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
      gdb::function_view<symbol_found_callback_ftype> callback,
-     symbol_compare_ftype *ordered_compare);
+     symbol_compare_ftype *ordered_compare) = 0;
 
   /* Expand all symbol tables in OBJFILE matching some criteria.
 
@@ -190,13 +195,13 @@ struct quick_symbol_functions
      If SYMBOL_MATCHER returns false, then the symbol is skipped.
 
      Otherwise, the symbol's symbol table is expanded.  */
-  void (*expand_symtabs_matching)
+  virtual void expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
-     enum search_domain kind);
+     enum search_domain kind) = 0;
 
   /* Return the comp unit from OBJFILE that contains PC and
      SECTION.  Return NULL if there is no such compunit.  This
@@ -204,25 +209,27 @@ struct quick_symbol_functions
      address exactly matches PC, or, if there is no exact match, the
      compunit that contains a symbol whose address is closest to
      PC.  */
-  struct compunit_symtab *(*find_pc_sect_compunit_symtab)
+  virtual struct compunit_symtab *find_pc_sect_compunit_symtab
     (struct objfile *objfile, struct bound_minimal_symbol msymbol,
-     CORE_ADDR pc, struct obj_section *section, int warn_if_readin);
+     CORE_ADDR pc, struct obj_section *section, int warn_if_readin) = 0;
 
   /* Return the comp unit from OBJFILE that contains a symbol at
      ADDRESS.  Return NULL if there is no such comp unit.  Unlike
      find_pc_sect_compunit_symtab, any sort of symbol (not just text
      symbols) can be considered, and only exact address matches are
-     considered.  This pointer may be NULL.  */
-  struct compunit_symtab *(*find_compunit_symtab_by_address)
-    (struct objfile *objfile, CORE_ADDR address);
+     considered.  */
+  virtual struct compunit_symtab *find_compunit_symtab_by_address
+    (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.  */
-  void (*map_symbol_filenames) (struct objfile *objfile,
-                               symbol_filename_ftype *fun, void *data,
-                               int need_fullname);
+  virtual void map_symbol_filenames (struct objfile *objfile,
+                                    symbol_filename_ftype *fun, void *data,
+                                    int need_fullname) = 0;
 };
 
+typedef std::unique_ptr<quick_symbol_functions> quick_symbol_functions_up;
+
 #endif /* GDB_QUICK_SYMBOL_H */
index da3439d79280e82919a76ee5e445a869be17a577..55865ab03b0ebce6bd791e6b0f0e070fd3e0ac4f 100644 (file)
@@ -328,7 +328,7 @@ objfile::find_compunit_symtab_by_address (CORE_ADDR address)
                      hex_string (address));
 
   struct compunit_symtab *result = NULL;
-  if (qf != nullptr && qf->find_compunit_symtab_by_address != NULL)
+  if (qf != nullptr)
     result = qf->find_compunit_symtab_by_address (this, address);
 
   if (debug_symfile)
@@ -348,7 +348,7 @@ objfile::lookup_global_symbol_language (const char *name,
 {
   enum language result = language_unknown;
 
-  if (qf != nullptr && qf->lookup_global_symbol_language != nullptr)
+  if (qf != nullptr)
     result = qf->lookup_global_symbol_language (this, name, domain,
                                                symbol_found_p);
   else
index d56d623c588078ecf51508e3c51ecc43abdc1f3e..d0b9da2138b9393f00d68d2480bf21497ec1aea5 100644 (file)
@@ -904,7 +904,7 @@ syms_from_objfile_1 (struct objfile *objfile,
   const int mainline = add_flags & SYMFILE_MAINLINE;
 
   objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
-  objfile->qf = &psym_functions;
+  objfile->qf = make_psymbol_functions ();
 
   if (objfile->sf == NULL)
     {
@@ -2555,7 +2555,7 @@ reread_symbols (void)
             based on whether .gdb_index is present, and we need it to
             start over.  PR symtab/15885  */
          objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
-         objfile->qf = &psym_functions;
+         objfile->qf = make_psymbol_functions ();
 
          build_objfile_section_table (objfile);