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 3/9] Change `label_symbols' to std::vector in linespec.c structures
Date: Fri, 10 Aug 2018 23:25:00 -0000	[thread overview]
Message-ID: <20180810232534.481-4-keiths@redhat.com> (raw)
In-Reply-To: <20180810232534.481-1-keiths@redhat.com>

This patch converts linespec.c's linespec.label_symbols member from a
VEC to a std::vector.

gdb/ChangeLog:

	* linespec.c (struct linespec) <label_symbols>: Change type to
	std::vector.  Update all users.
	(find_label_symbols_in_block): Change `result' parameter to
	std::vector.  Update all callers.
	(find_label_symbols): Return std::vector.  Update all callers.
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/linespec.c | 54 +++++++++++++++++++++++++++---------------------------
 2 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5a71381262..b3f5a5d039 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
 
+	* linespec.c (struct linespec) <label_symbols>: Change type to
+	std::vector.  Update all users.
+	(find_label_symbols_in_block): Change `result' parameter to
+	std::vector.  Update all callers.
+	(find_label_symbols): Return std::vector.  Update all callers.
+
+YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
+
 	* linespec.c (struct linespec) <function_symbols>: Change type to
 	std::vector.  Update all users.
 	(struct collect_info) <function_symbols>: Likewise.
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 8070db68ec..4e7f9b08b0 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -123,7 +123,7 @@ struct linespec
      or both must be non-NULL.  */
   struct
   {
-    VEC (symbolp) *label_symbols;
+    std::vector<symbol *> *label_symbols;
     std::vector<symbol *> *function_symbols;
   } labels;
 };
@@ -352,7 +352,7 @@ static std::vector<symtab_and_line> decode_objc (struct linespec_state *self,
 static std::vector<symtab *> *symtabs_from_filename
   (const char *, struct program_space *pspace);
 
-static VEC (symbolp) *find_label_symbols
+static std::vector<symbol *> *find_label_symbols
   (struct linespec_state *self, std::vector<symbol *> *function_symbols,
    std::vector<symbol *> *label_funcs_ret, const char *name,
    bool completion_mode = false);
@@ -1767,7 +1767,7 @@ linespec_parse_basic (linespec_parser *parser)
   gdb::unique_xmalloc_ptr<char> name;
   linespec_token token;
   std::vector<symbol *> symbols;
-  VEC (symbolp) *labels;
+  std::vector<symbol *> *labels;
   VEC (bound_minimal_symbol_d) *minimal_symbols;
 
   /* Get the next token.  */
@@ -2241,12 +2241,9 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
   if (ls->labels.label_symbols != NULL)
     {
       /* We have just a bunch of functions/methods or labels.  */
-      int i;
-      struct symtab_and_line sal;
-      struct symbol *sym;
-
-      for (i = 0; VEC_iterate (symbolp, ls->labels.label_symbols, i, sym); ++i)
+      for (const auto &sym : *ls->labels.label_symbols)
 	{
+	  struct symtab_and_line sal;
 	  struct program_space *pspace = SYMTAB_PSPACE (symbol_symtab (sym));
 
 	  if (symbol_to_sal (&sal, state->funfirstline, sym)
@@ -2388,7 +2385,7 @@ convert_explicit_location_to_linespec (struct linespec_state *self,
 				       struct line_offset line_offset)
 {
   std::vector<symbol *> symbols;
-  VEC (symbolp) *labels;
+  std::vector<symbol *> *labels;
   VEC (bound_minimal_symbol_d) *minimal_symbols;
 
   result->explicit_loc.func_name_match_type = fname_match_type;
@@ -2780,9 +2777,7 @@ linespec_parser_delete (void *arg)
   if (PARSER_RESULT (parser)->minimal_symbols != NULL)
     VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols);
 
-  if (PARSER_RESULT (parser)->labels.label_symbols != NULL)
-    VEC_free (symbolp, PARSER_RESULT (parser)->labels.label_symbols);
-
+  delete PARSER_RESULT (parser)->labels.label_symbols;
   delete PARSER_RESULT (parser)->labels.function_symbols;
 
   linespec_state_destructor (PARSER_STATE (parser));
@@ -2917,20 +2912,21 @@ complete_label (completion_tracker &tracker,
 		const char *label_name)
 {
   std::vector<symbol *> label_function_symbols;
-  VEC (symbolp) *labels
+  std::vector<symbol *> *labels
     = find_label_symbols (PARSER_STATE (parser),
 			  PARSER_RESULT (parser)->function_symbols,
 			  &label_function_symbols,
 			  label_name, true);
 
-  symbol *label;
-  for (int ix = 0;
-       VEC_iterate (symbolp, labels, ix, label); ++ix)
+  if (labels != nullptr)
     {
-      char *match = xstrdup (SYMBOL_SEARCH_NAME (label));
-      tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
+      for (const auto &label : *labels)
+	{
+	  char *match = xstrdup (SYMBOL_SEARCH_NAME (label));
+	  tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
+	}
+      delete labels;
     }
-  VEC_free (symbolp, labels);
 }
 
 /* See linespec.h.  */
@@ -4045,7 +4041,7 @@ static void
 find_label_symbols_in_block (const struct block *block,
 			     const char *name, struct symbol *fn_sym,
 			     bool completion_mode,
-			     VEC (symbolp) **result,
+			     std::vector<symbol *> *result,
 			     std::vector<symbol *> *label_funcs_ret)
 {
   if (completion_mode)
@@ -4063,7 +4059,7 @@ find_label_symbols_in_block (const struct block *block,
 				     SYMBOL_DOMAIN (sym), LABEL_DOMAIN)
 	      && cmp (SYMBOL_SEARCH_NAME (sym), name, name_len) == 0)
 	    {
-	      VEC_safe_push (symbolp, *result, sym);
+	      result->push_back (sym);
 	      label_funcs_ret->push_back (fn_sym);
 	    }
 	}
@@ -4074,19 +4070,21 @@ find_label_symbols_in_block (const struct block *block,
 
       if (sym != NULL)
 	{
-	  VEC_safe_push (symbolp, *result, sym);
+	  result->push_back (sym);
 	  label_funcs_ret->push_back (fn_sym);
 	}
     }
 }
 
-/* Return all labels that match name NAME in FUNCTION_SYMBOLS.  Return
-   the actual function symbol in which the label was found in
+/* Return all labels that match name NAME in FUNCTION_SYMBOLS or NULL
+   if no matches were found.
+
+   Return the actual function symbol in which the label was found in
    LABEL_FUNC_RET.  If COMPLETION_MODE is true, then NAME is
    interpreted as a label name prefix.  Otherwise, only labels named
    exactly NAME match.  */
 
-static VEC (symbolp) *
+static std::vector<symbol *> *
 find_label_symbols (struct linespec_state *self,
 		    std::vector<symbol *> *function_symbols,
 		    std::vector<symbol *> *label_funcs_ret, const char *name,
@@ -4094,7 +4092,7 @@ find_label_symbols (struct linespec_state *self,
 {
   const struct block *block;
   struct symbol *fn_sym;
-  VEC (symbolp) *result = NULL;
+  std::vector<symbol *> result;
 
   if (function_symbols == NULL)
     {
@@ -4124,7 +4122,9 @@ find_label_symbols (struct linespec_state *self,
 	}
     }
 
-  return result;
+  if (!result.empty ())
+    return new std::vector<symbol *> (std::move (result));
+  return nullptr;
 }
 
 \f
-- 
2.13.6


  parent reply	other threads:[~2018-08-10 23:25 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 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:25 ` Keith Seitz [this message]
2018-08-11 14:50   ` [PATCH 3/9] Change `label_symbols' to std::vector in linespec.c structures Tom Tromey
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: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:31 ` [PATCH 6/9] Remove VEC definitions from linespec.c Keith Seitz
2018-08-11 15:03   ` 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: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:34 ` [PATCH 8/9] Add new search_symbols_multiple API Keith Seitz
2018-08-11 20:49   ` 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-4-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