From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 08/26] Convert quick_symbol_functions to use methods
Date: Sun, 28 Feb 2021 13:37:45 -0700 [thread overview]
Message-ID: <20210228203803.1693413-9-tom@tromey.com> (raw)
In-Reply-To: <20210228203803.1693413-1-tom@tromey.com>
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-02-28 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 | 59 ++++++++++
gdb/dwarf2/public.h | 3 +
gdb/dwarf2/read.c | 274 ++++++++++++++++++++++++++++++--------------
gdb/elfread.c | 4 +-
gdb/objfiles.h | 3 +-
gdb/psympriv.h | 64 +++++++++++
gdb/psymtab.c | 114 +++++++++---------
gdb/psymtab.h | 7 +-
gdb/quick-symbol.h | 71 ++++++------
gdb/symfile-debug.c | 4 +-
gdb/symfile.c | 4 +-
11 files changed, 416 insertions(+), 191 deletions(-)
diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h
index d0182d4e673..6b0fe0874b2 100644
--- a/gdb/dwarf2/public.h
+++ b/gdb/dwarf2/public.h
@@ -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 */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7e55a0ec486..a24ead568ee 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2392,7 +2392,7 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
return per_bfd->dwz_file.get ();
}
\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
@@ -2435,6 +2435,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
@@ -3449,8 +3562,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 ();
@@ -3483,8 +3596,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);
@@ -3518,8 +3632,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)
{
@@ -3768,9 +3882,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);
@@ -3811,8 +3926,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 ()
@@ -3835,8 +3950,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);
@@ -3852,9 +3967,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);
@@ -3868,8 +3983,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 ()
@@ -3888,9 +4003,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);
@@ -3996,6 +4111,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
@@ -4989,6 +5116,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. */
@@ -5017,12 +5157,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;
@@ -5048,9 +5189,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);
@@ -5115,32 +5258,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. */
@@ -5875,9 +5998,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);
@@ -5926,8 +6050,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);
@@ -5940,9 +6064,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);
@@ -5960,8 +6084,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,
@@ -6018,8 +6142,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,
@@ -6065,26 +6189,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. */
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 3ba7221bfc9..4ca1f4d5284 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -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;
}
}
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 8d4a23ae044..7235713cbdf 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -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 @@ struct objfile
/* 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. */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 1f35ef2a44b..6b9ee184e9c 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -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 */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 8c02fa253dc..c022daa7894 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -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
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index dbff302b1d1..45eaf0b9013 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -146,11 +146,6 @@ class psymtab_storage
};
-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 */
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index fa5f5012211..85e7a32eacd 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -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 */
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index da3439d7928..55865ab03b0 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -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
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d56d623c588..d0b9da2138b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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);
--
2.26.2
next prev parent reply other threads:[~2021-02-28 20:38 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-28 20:37 [PATCH 00/26] Allow multiple "partial" symtab readers per objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 01/26] Move some DWARF code out of symfile.h Tom Tromey
2021-02-28 20:37 ` [PATCH 02/26] Introduce dwarf2/public.h Tom Tromey
2021-02-28 20:37 ` [PATCH 03/26] Change objfile_has_partial_symbols to a method Tom Tromey
2021-02-28 20:37 ` [PATCH 04/26] Change objfile::has_partial_symbols to return bool Tom Tromey
2021-02-28 20:37 ` [PATCH 05/26] Introduce method wrappers for quick_symbol_functions Tom Tromey
2021-03-22 13:52 ` Simon Marchi
2021-02-28 20:37 ` [PATCH 06/26] Move quick_symbol_functions to a new header Tom Tromey
2021-02-28 20:37 ` [PATCH 07/26] Move sym_fns::qf to objfile Tom Tromey
2021-02-28 20:37 ` Tom Tromey [this message]
2021-02-28 20:37 ` [PATCH 09/26] Move psymbol_map out of objfile Tom Tromey
2021-02-28 20:37 ` [PATCH 10/26] Change how some psymbol readers access the psymtab storage Tom Tromey
2021-02-28 20:37 ` [PATCH 11/26] Do not pass objfile to psymtab_discarder Tom Tromey
2021-02-28 20:37 ` [PATCH 12/26] Set per_bfd->partial_symtabs earlier Tom Tromey
2021-02-28 20:37 ` [PATCH 13/26] Change how DWARF indices use addrmap Tom Tromey
2021-02-28 20:37 ` [PATCH 14/26] Move psymtab statistics printing to psymtab.c Tom Tromey
2021-02-28 20:37 ` [PATCH 15/26] Change how DWARF index writer finds address map Tom Tromey
2021-02-28 20:37 ` [PATCH 16/26] Reference psymtabs via per_bfd in DWARF reader Tom Tromey
2021-02-28 20:37 ` [PATCH 17/26] Attach partial symtab storage to psymbol_functions Tom Tromey
2021-02-28 20:37 ` [PATCH 18/26] Rearrange psymtab_storage construction Tom Tromey
2021-02-28 20:37 ` [PATCH 19/26] Remove sym_fns::sym_read_psymbols Tom Tromey
2021-02-28 20:37 ` [PATCH 20/26] Introduce objfile::require_partial_symbols Tom Tromey
2021-02-28 20:37 ` [PATCH 21/26] Add partial_symtabs parameter to psymtab construction functions Tom Tromey
2021-02-28 20:37 ` [PATCH 22/26] Remove last objfile partial_symtab references from psymtab.c Tom Tromey
2021-02-28 20:38 ` [PATCH 23/26] Change count_psyms to be a method on psymbol_functions Tom Tromey
2021-02-28 20:38 ` [PATCH 24/26] Remove objfile::psymtabs Tom Tromey
2021-02-28 20:38 ` [PATCH 25/26] Switch objfile to hold a list of psymbol readers Tom Tromey
2021-02-28 20:38 ` [PATCH 26/26] Allow multiple partial symbol readers per objfile Tom Tromey
2021-03-20 23:33 ` [PATCH 00/26] Allow multiple "partial" symtab " Tom Tromey
2021-03-22 14:13 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210228203803.1693413-9-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).