[4/9] Change `minimal_symbols' to std::vector in linespec.c structures

Message ID 20180810232534.481-5-keiths@redhat.com
State New, archived
Headers

Commit Message

Keith Seitz Aug. 10, 2018, 11:25 p.m. UTC
  This patch converts linespec.c's linespec.label_symbols member from a
VEC to a std::vector.

gdb/ChangeLog:

	* linespec.c (struct linespec) <minimal_symbols>: Change type to
	std::vector.  Update all users.
	(struct collect_info) <minimal_symbols>: Likewise.
	(find_method, find_function_symbols, find_linespec_symbols): Change
	`minsyms' parameter to std::vector.  Update all callers.
---
 gdb/ChangeLog  |   8 +++++
 gdb/linespec.c | 104 +++++++++++++++++++++++----------------------------------
 2 files changed, 49 insertions(+), 63 deletions(-)
  

Comments

Tom Tromey Aug. 11, 2018, 3 p.m. UTC | #1
>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:

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

Keith> gdb/ChangeLog:

Keith> 	* linespec.c (struct linespec) <minimal_symbols>: Change type to
Keith> 	std::vector.  Update all users.
Keith> 	(struct collect_info) <minimal_symbols>: Likewise.
Keith> 	(find_method, find_function_symbols, find_linespec_symbols): Change
Keith> 	`minsyms' parameter to std::vector.  Update all callers.

Thank you.

Keith> +	  qsort (ls->minimal_symbols->data (), ls->minimal_symbols->size (),
Keith> +		 sizeof (bound_minimal_symbol), compare_msymbols);

I think this should be changed to use std::sort.
If I'm reading correctly, this is the only caller of compare_msymbols,
so this transform shouldn't be too hard to do.

Tom
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b3f5a5d039..f762196cbc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@ 
 YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
 
+	* linespec.c (struct linespec) <minimal_symbols>: Change type to
+	std::vector.  Update all users.
+	(struct collect_info) <minimal_symbols>: Likewise.
+	(find_method, find_function_symbols, find_linespec_symbols): Change
+	`minsyms' parameter to std::vector.  Update all callers.
+
+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
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4e7f9b08b0..bc20001df9 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -116,7 +116,7 @@  struct linespec
   /* A list of matching function symbols and minimal symbols.  Both lists
      may be NULL (or empty) if no matching symbols were found.  */
   std::vector<symbol *> *function_symbols;
-  VEC (bound_minimal_symbol_d) *minimal_symbols;
+  std::vector<bound_minimal_symbol> *minimal_symbols;
 
   /* A structure of matching label symbols and the corresponding
      function symbol in which the label was found.  Both may be NULL
@@ -202,7 +202,7 @@  struct collect_info
   struct
   {
     std::vector<symbol *> *symbols;
-    VEC (bound_minimal_symbol_d) *minimal_symbols;
+    std::vector<bound_minimal_symbol> *minimal_symbols;
   } result;
 
   /* Possibly add a symbol to the results.  */
@@ -362,7 +362,7 @@  static void find_linespec_symbols (struct linespec_state *self,
 				   const char *name,
 				   symbol_name_match_type name_match_type,
 				   std::vector<symbol *> *symbols,
-				   VEC (bound_minimal_symbol_d) **minsyms);
+				   std::vector<bound_minimal_symbol> *minsyms);
 
 static struct line_offset
      linespec_parse_variable (struct linespec_state *self,
@@ -1768,7 +1768,7 @@  linespec_parse_basic (linespec_parser *parser)
   linespec_token token;
   std::vector<symbol *> symbols;
   std::vector<symbol *> *labels;
-  VEC (bound_minimal_symbol_d) *minimal_symbols;
+  std::vector<bound_minimal_symbol> minimal_symbols;
 
   /* Get the next token.  */
   token = linespec_lexer_lex_one (parser);
@@ -1871,11 +1871,13 @@  linespec_parse_basic (linespec_parser *parser)
 			     PARSER_EXPLICIT (parser)->func_name_match_type,
 			     &symbols, &minimal_symbols);
 
-      if (!symbols.empty () || minimal_symbols != NULL)
+      if (!symbols.empty () || !minimal_symbols.empty ())
 	{
 	  PARSER_RESULT (parser)->function_symbols
 	    = new std::vector<symbol *> (std::move (symbols));
-	  PARSER_RESULT (parser)->minimal_symbols = minimal_symbols;
+	  PARSER_RESULT (parser)->minimal_symbols
+	    = new std::vector<bound_minimal_symbol>
+	        (std::move (minimal_symbols));
 	  PARSER_EXPLICIT (parser)->function_name = name.release ();
 	}
       else
@@ -2280,20 +2282,16 @@  convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
 		  const CORE_ADDR addr
 		    = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
 
-		  bound_minimal_symbol_d *elem;
-		  for (int m = 0;
-		       VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols,
-				    m, elem);
-		       ++m)
+		  for (const auto &elem : *ls->minimal_symbols)
 		    {
-		      if (MSYMBOL_TYPE (elem->minsym) == mst_text_gnu_ifunc
-			  || MSYMBOL_TYPE (elem->minsym) == mst_data_gnu_ifunc)
+		      if (MSYMBOL_TYPE (elem.minsym) == mst_text_gnu_ifunc
+			  || MSYMBOL_TYPE (elem.minsym) == mst_data_gnu_ifunc)
 			{
-			  CORE_ADDR msym_addr = BMSYMBOL_VALUE_ADDRESS (*elem);
-			  if (MSYMBOL_TYPE (elem->minsym) == mst_data_gnu_ifunc)
+			  CORE_ADDR msym_addr = BMSYMBOL_VALUE_ADDRESS (elem);
+			  if (MSYMBOL_TYPE (elem.minsym) == mst_data_gnu_ifunc)
 			    {
 			      struct gdbarch *gdbarch
-				= get_objfile_arch (elem->objfile);
+				= get_objfile_arch (elem.objfile);
 			      msym_addr
 				= (gdbarch_convert_from_func_ptr_addr
 				   (gdbarch,
@@ -2324,20 +2322,14 @@  convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
       if (ls->minimal_symbols != NULL)
 	{
 	  /* Sort minimal symbols by program space, too  */
-	  qsort (VEC_address (bound_minimal_symbol_d, ls->minimal_symbols),
-		 VEC_length (bound_minimal_symbol_d, ls->minimal_symbols),
-		 sizeof (bound_minimal_symbol_d), compare_msymbols);
+	  qsort (ls->minimal_symbols->data (), ls->minimal_symbols->size (),
+		 sizeof (bound_minimal_symbol), compare_msymbols);
 
-	  bound_minimal_symbol_d *elem;
-
-	  for (int i = 0;
-	       VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols,
-			    i, elem);
-	       ++i)
+	  for (const auto &elem : *ls->minimal_symbols)
 	    {
-	      program_space *pspace = elem->objfile->pspace;
+	      program_space *pspace = elem.objfile->pspace;
 	      set_current_program_space (pspace);
-	      minsym_found (state, elem->objfile, elem->minsym, &sals);
+	      minsym_found (state, elem.objfile, elem.minsym, &sals);
 	    }
 	}
     }
@@ -2386,7 +2378,7 @@  convert_explicit_location_to_linespec (struct linespec_state *self,
 {
   std::vector<symbol *> symbols;
   std::vector<symbol *> *labels;
-  VEC (bound_minimal_symbol_d) *minimal_symbols;
+  std::vector<bound_minimal_symbol> minimal_symbols;
 
   result->explicit_loc.func_name_match_type = fname_match_type;
 
@@ -2416,14 +2408,15 @@  convert_explicit_location_to_linespec (struct linespec_state *self,
 			     function_name, fname_match_type,
 			     &symbols, &minimal_symbols);
 
-      if (symbols.empty () && minimal_symbols == NULL)
+      if (symbols.empty () && minimal_symbols.empty ())
 	symbol_not_found_error (function_name,
 				result->explicit_loc.source_filename);
 
       result->explicit_loc.function_name = xstrdup (function_name);
       result->function_symbols
 	= new std::vector<symbol *> (std::move (symbols));
-      result->minimal_symbols = minimal_symbols;
+      result->minimal_symbols
+	= new std::vector<bound_minimal_symbol> (std::move (minimal_symbols));
     }
 
   if (label_name != NULL)
@@ -2773,10 +2766,7 @@  linespec_parser_delete (void *arg)
 
   delete PARSER_RESULT (parser)->file_symtabs;
   delete PARSER_RESULT (parser)->function_symbols;
-
-  if (PARSER_RESULT (parser)->minimal_symbols != NULL)
-    VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols);
-
+  delete PARSER_RESULT (parser)->minimal_symbols;
   delete PARSER_RESULT (parser)->labels.label_symbols;
   delete PARSER_RESULT (parser)->labels.function_symbols;
 
@@ -3036,7 +3026,7 @@  linespec_complete (completion_tracker &tracker, const char *text,
       const char *func_name = PARSER_EXPLICIT (&parser)->function_name;
 
       std::vector<symbol *> function_symbols;
-      VEC (bound_minimal_symbol_d) *minimal_symbols;
+      std::vector<bound_minimal_symbol> minimal_symbols;
       find_linespec_symbols (PARSER_STATE (&parser),
 			     PARSER_RESULT (&parser)->file_symtabs,
 			     func_name, match_type,
@@ -3044,7 +3034,8 @@  linespec_complete (completion_tracker &tracker, const char *text,
 
       PARSER_RESULT (&parser)->function_symbols
 	= new std::vector<symbol *> (std::move (function_symbols));
-      PARSER_RESULT (&parser)->minimal_symbols = minimal_symbols;
+      PARSER_RESULT (&parser)->minimal_symbols
+	= new std::vector<bound_minimal_symbol> (std::move (minimal_symbols));
 
       complete_label (tracker, &parser, parser.completion_word);
     }
@@ -3444,7 +3435,8 @@  decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
 
   std::vector<symbol *> symbols;
   info.result.symbols = &symbols;
-  info.result.minimal_symbols = NULL;
+  std::vector<bound_minimal_symbol> minimal_symbols;
+  info.result.minimal_symbols = &minimal_symbols;
 
   new_argptr = find_imps (arg, &symbol_names);
   if (symbol_names.empty ())
@@ -3454,8 +3446,7 @@  decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
 				    FUNCTIONS_DOMAIN);
 
   std::vector<symtab_and_line> values;
-  if (!symbols.empty ()
-      || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
+  if (!symbols.empty () || !minimal_symbols.empty ())
     {
       char *saved_arg;
 
@@ -3465,7 +3456,8 @@  decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
 
       ls->explicit_loc.function_name = xstrdup (saved_arg);
       ls->function_symbols = new std::vector<symbol *> (std::move (symbols));
-      ls->minimal_symbols = info.result.minimal_symbols;
+      ls->minimal_symbols
+	= new std::vector<bound_minimal_symbol> (std::move (minimal_symbols));
       values = convert_linespec_to_sals (self, ls);
 
       if (self->canonical)
@@ -3705,7 +3697,7 @@  static void
 find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
 	     const char *class_name, const char *method_name,
 	     VEC (symbolp) *sym_classes, std::vector<symbol *> *symbols,
-	     VEC (bound_minimal_symbol_d) **minsyms)
+	     std::vector<bound_minimal_symbol> *minsyms)
 {
   struct symbol *sym;
   int ix;
@@ -3724,7 +3716,7 @@  find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
   info.state = self;
   info.file_symtabs = file_symtabs;
   info.result.symbols = symbols;
-  info.result.minimal_symbols = NULL;
+  info.result.minimal_symbols = minsyms;
 
   /* Iterate over all the types, looking for the names of existing
      methods matching METHOD_NAME.  If we cannot find a direct method in a
@@ -3774,12 +3766,8 @@  find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
 	}
     }
 
-  if (!symbols->empty ()
-      || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
-    {
-      *minsyms = info.result.minimal_symbols;
-      return;
-    }
+  if (!symbols->empty () || !minsyms->empty ())
+    return;
 
   /* Throw an NOT_FOUND_ERROR.  This will be caught by the caller
      and other attempts to locate the symbol will be made.  */
@@ -3910,14 +3898,14 @@  find_function_symbols (struct linespec_state *state,
 		       std::vector<symtab *> *file_symtabs, const char *name,
 		       symbol_name_match_type name_match_type,
 		       std::vector<symbol *> *symbols,
-		       VEC (bound_minimal_symbol_d) **minsyms)
+		       std::vector<bound_minimal_symbol> *minsyms)
 {
   struct collect_info info;
   std::vector<const char *> symbol_names;
 
   info.state = state;
   info.result.symbols = symbols;
-  info.result.minimal_symbols = NULL;
+  info.result.minimal_symbols = minsyms;
   info.file_symtabs = file_symtabs;
 
   /* Try NAME as an Objective-C selector.  */
@@ -3928,14 +3916,6 @@  find_function_symbols (struct linespec_state *state,
   else
     add_matching_symbols_to_info (name, name_match_type, FUNCTIONS_DOMAIN,
 				  &info, state->search_pspace);
-
-  if (VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
-    {
-      VEC_free (bound_minimal_symbol_d, info.result.minimal_symbols);
-      *minsyms = NULL;
-    }
-  else
-    *minsyms = info.result.minimal_symbols;
 }
 
 /* Find all symbols named NAME in FILE_SYMTABS, returning debug symbols
@@ -3947,7 +3927,7 @@  find_linespec_symbols (struct linespec_state *state,
 		       const char *lookup_name,
 		       symbol_name_match_type name_match_type,
 		       std::vector <symbol *> *symbols,
-		       VEC (bound_minimal_symbol_d) **minsyms)
+		       std::vector<bound_minimal_symbol> *minsyms)
 {
   std::string canon = cp_canonicalize_string_no_typedefs (lookup_name);
   if (!canon.empty ())
@@ -3968,8 +3948,7 @@  find_linespec_symbols (struct linespec_state *state,
   /* If we were unable to locate a symbol of the same name, try dividing
      the name into class and method names and searching the class and its
      baseclasses.  */
-  if (symbols->empty ()
-      && VEC_empty (bound_minimal_symbol_d, *minsyms))
+  if (symbols->empty () && minsyms->empty ())
     {
       std::string klass, method;
       const char *last, *p, *scope_op;
@@ -4444,8 +4423,7 @@  search_minsyms_for_name (struct collect_info *info,
 	  if (classify_mtype (MSYMBOL_TYPE (item.minsym)) != classification)
 	    break;
 
-	  VEC_safe_push (bound_minimal_symbol_d,
-			 info->result.minimal_symbols, &item);
+	  info->result.minimal_symbols->push_back (item);
 	}
     }
 }