aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/linespec.c47
-rw-r--r--gdb/symtab.h43
3 files changed, 96 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 830f429..d82257e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2018-08-29 Keith Seitz <keiths@redhat.com>
+ * linespec.c (collect_info::add_symbol): Make virtual.
+ (struct symbol_searcher_collect_info): New struct.
+ (symbol_searcher::find_all_symbols): New method.
+ * symtab.h (class symbol_searcher): New class.
+
+2018-08-29 Keith Seitz <keiths@redhat.com>
+
* linespec.c (struct linespec) <function_symbols, label_symbols>:
Change to vector of block_symbol. Update all users.
(struct collect_info) <symbols>: Likewise.
diff --git a/gdb/linespec.c b/gdb/linespec.c
index ea0d829..84258ad 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -199,7 +199,7 @@ struct collect_info
} result;
/* Possibly add a symbol to the results. */
- bool add_symbol (block_symbol *bsym);
+ virtual bool add_symbol (block_symbol *bsym);
};
bool
@@ -214,6 +214,21 @@ collect_info::add_symbol (block_symbol *bsym)
return true;
}
+/* Custom collect_info for symbol_searcher. */
+
+struct symbol_searcher_collect_info
+ : collect_info
+{
+ bool add_symbol (block_symbol *bsym) override
+ {
+ /* Add everything. */
+ this->result.symbols->push_back (*bsym);
+
+ /* Continue iterating. */
+ return true;
+ }
+};
+
/* Token types */
enum ls_token_type
@@ -3876,6 +3891,36 @@ symtabs_from_filename (const char *filename,
return result;
}
+/* See symtab.h. */
+
+void
+symbol_searcher::find_all_symbols (const std::string &name,
+ const struct language_defn *language,
+ enum search_domain search_domain,
+ std::vector<symtab *> *search_symtabs,
+ struct program_space *search_pspace)
+{
+ symbol_searcher_collect_info info;
+ struct linespec_state state;
+
+ memset (&state, 0, sizeof (state));
+ state.language = language;
+ info.state = &state;
+
+ info.result.symbols = &m_symbols;
+ info.result.minimal_symbols = &m_minimal_symbols;
+ std::vector<symtab *> all_symtabs;
+ if (search_symtabs == nullptr)
+ {
+ all_symtabs.push_back (nullptr);
+ search_symtabs = &all_symtabs;
+ }
+ info.file_symtabs = search_symtabs;
+
+ add_matching_symbols_to_info (name.c_str (), symbol_name_match_type::WILD,
+ search_domain, &info, search_pspace);
+}
+
/* Look up a function symbol named NAME in symtabs FILE_SYMTABS. Matching
debug symbols are returned in SYMBOLS. Matching minimal symbols are
returned in MINSYMS. */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 1dc9a09..e0fe17a 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2185,4 +2185,47 @@ void completion_list_add_name (completion_tracker &tracker,
const lookup_name_info &lookup_name,
const char *text, const char *word);
+/* A simple symbol searching class. */
+
+class symbol_searcher
+{
+public:
+ /* Returns the symbols found for the search. */
+ const std::vector<block_symbol> &
+ matching_symbols () const
+ {
+ return m_symbols;
+ }
+
+ /* Returns the minimal symbols found for the search. */
+ const std::vector<bound_minimal_symbol> &
+ matching_msymbols () const
+ {
+ return m_minimal_symbols;
+ }
+
+ /* Search for all symbols named NAME in LANGUAGE with DOMAIN, restricting
+ search to FILE_SYMTABS and SEARCH_PSPACE, both of which may be NULL
+ to search all symtabs and program spaces. */
+ void find_all_symbols (const std::string &name,
+ const struct language_defn *language,
+ enum search_domain search_domain,
+ std::vector<symtab *> *search_symtabs,
+ struct program_space *search_pspace);
+
+ /* Reset this object to perform another search. */
+ void reset ()
+ {
+ m_symbols.clear ();
+ m_minimal_symbols.clear ();
+ }
+
+private:
+ /* Matching debug symbols. */
+ std::vector<block_symbol> m_symbols;
+
+ /* Matching non-debug symbols. */
+ std::vector<bound_minimal_symbol> m_minimal_symbols;
+};
+
#endif /* !defined(SYMTAB_H) */