diff options
author | Keith Seitz <keiths@redhat.com> | 2018-08-29 15:12:23 -0700 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2018-08-29 15:12:23 -0700 |
commit | fcaad03cc027ec2cdf7f2cff70d792867d43c57f (patch) | |
tree | 3e83fdb3af1743ba9b29fac1c0618aef012c3856 /gdb/linespec.c | |
parent | 7e41c8db84bc6f74843dda40ae443d41977c0d20 (diff) | |
download | gdb-fcaad03cc027ec2cdf7f2cff70d792867d43c57f.zip gdb-fcaad03cc027ec2cdf7f2cff70d792867d43c57f.tar.gz gdb-fcaad03cc027ec2cdf7f2cff70d792867d43c57f.tar.bz2 |
Add new search_symbols_multiple API
This patch adds a new symbol searching API based on linespec.c's parser
implementation. This allows users to find "all* matching symbols instead
of the first found match (a la lookup_symbol).
gdb/ChangeLog:
* 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.
Diffstat (limited to 'gdb/linespec.c')
-rw-r--r-- | gdb/linespec.c | 47 |
1 files changed, 46 insertions, 1 deletions
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. */ |