From patchwork Fri Aug 10 23:25:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 28860 Received: (qmail 61620 invoked by alias); 10 Aug 2018 23:34:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 61606 invoked by uid 89); 10 Aug 2018 23:34:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=199, 7, Search, DOMAIN X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Aug 2018 23:34:07 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9594AC057F81 for ; Fri, 10 Aug 2018 23:25:37 +0000 (UTC) Received: from theo.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6320752FD4 for ; Fri, 10 Aug 2018 23:25:37 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH 8/9] Add new search_symbols_multiple API Date: Fri, 10 Aug 2018 16:25:33 -0700 Message-Id: <20180810232534.481-9-keiths@redhat.com> In-Reply-To: <20180810232534.481-1-keiths@redhat.com> References: <20180810232534.481-1-keiths@redhat.com> X-IsSubscribed: yes 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. --- gdb/ChangeLog | 7 +++++++ gdb/linespec.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- gdb/symtab.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6fc1ce5262..e12c54983c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ YYYY-MM-DD Keith Seitz + * 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. + +YYYY-MM-DD Keith Seitz + * linespec.c (struct linespec) : Change to vector of block_symbol. Update all users. (struct collect_info) : Likewise. diff --git a/gdb/linespec.c b/gdb/linespec.c index ef4556d8ea..73825f2cc7 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 @@ -3885,6 +3900,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 *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 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 da498cdb95..fe0962c7eb 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2134,4 +2134,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 & + matching_symbols () const + { + return m_symbols; + } + + /* Returns the minimal symbols found for the search. */ + const std::vector & + 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 *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 m_symbols; + + /* Matching non-debug symbols. */ + std::vector m_minimal_symbols; +}; + #endif /* !defined(SYMTAB_H) */