Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 8/9] Add new search_symbols_multiple API
Date: Fri, 10 Aug 2018 23:34:00 -0000	[thread overview]
Message-ID: <20180810232534.481-9-keiths@redhat.com> (raw)
In-Reply-To: <20180810232534.481-1-keiths@redhat.com>

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  <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.
+
+YYYY-MM-DD  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 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<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 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<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) */
-- 
2.13.6


  parent reply	other threads:[~2018-08-10 23:34 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 23:25 [PATCH 0/9] C++ Support for Compile Keith Seitz
2018-08-10 23:25 ` [PATCH 1/9] Change `file_symtabs' to std::vector Keith Seitz
2018-08-11 14:47   ` Tom Tromey
2018-08-17 17:56     ` Keith Seitz
2018-08-28 17:30       ` Tom Tromey
2018-08-10 23:25 ` [PATCH 3/9] Change `label_symbols' to std::vector in linespec.c structures Keith Seitz
2018-08-11 14:50   ` Tom Tromey
2018-08-10 23:25 ` [PATCH 2/9] Change `function_symbols' to std::vector Keith Seitz
2018-08-11 14:49   ` Tom Tromey
2018-08-17 17:59     ` Keith Seitz
2018-08-28 17:43       ` Tom Tromey
2018-08-10 23:31 ` [PATCH 6/9] Remove VEC definitions from linespec.c Keith Seitz
2018-08-11 15:03   ` Tom Tromey
2018-08-10 23:31 ` [PATCH 7/9] Use block_symbol_d in linespec APIs Keith Seitz
2018-08-11 15:05   ` Tom Tromey
2018-08-17 18:04     ` Keith Seitz
2018-08-10 23:32 ` [PATCH 4/9] Change `minimal_symbols' to std::vector in linespec.c structures Keith Seitz
2018-08-11 15:01   ` Tom Tromey
2018-08-17 18:00     ` Keith Seitz
2018-08-28 17:44       ` Tom Tromey
2018-08-10 23:32 ` [PATCH 5/9] Change decode_compound_collector to use std::vector Keith Seitz
2018-08-11 15:02   ` Tom Tromey
2018-08-17 18:04     ` Keith Seitz
2018-08-20  1:20       ` Simon Marchi
2018-08-20 13:28         ` Tom Tromey
2018-08-20 14:03           ` Simon Marchi
2018-08-28 17:46       ` Tom Tromey
2018-08-10 23:32 ` [PATCH 9/9] C++ compile support Keith Seitz
2018-08-11  7:22   ` Eli Zaretskii
2018-08-17 17:51     ` Keith Seitz
2018-08-17 18:57       ` Eli Zaretskii
2018-08-20 17:02         ` Keith Seitz
2018-08-12  0:17   ` Tom Tromey
2018-08-17 18:26     ` Keith Seitz
2018-08-28 17:52       ` Tom Tromey
2018-08-29 22:32         ` Keith Seitz
2021-03-24  1:04   ` Simon Marchi via Gdb-patches
2021-03-24 14:51     ` Keith Seitz via Gdb-patches
2021-03-24 15:06       ` Simon Marchi via Gdb-patches
2021-03-24 20:49         ` Keith Seitz via Gdb-patches
2021-04-01 18:03     ` Tom Tromey
2021-04-01 18:07       ` Luis Machado via Gdb-patches
2021-04-01 19:36       ` Keith Seitz via Gdb-patches
2018-08-10 23:34 ` Keith Seitz [this message]
2018-08-11 20:49   ` [PATCH 8/9] Add new search_symbols_multiple API Tom Tromey

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=20180810232534.481-9-keiths@redhat.com \
    --to=keiths@redhat.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