[16/30] Use block_symbol in overload-handling code

Message ID 20231029-split-objfile-2023-bound-sym-october-v1-16-612531df2734@tromey.com
State New
Headers
Series Baby step for objfile splitting |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom Tromey Oct. 29, 2023, 11:23 p.m. UTC
  This changes the overload-handling code to use block_symbol.  This is
needed to update one of its callers to use the new read_var_value
overload.
---
 gdb/cp-support.c | 46 ++++++++++++++++++++++++++--------------------
 gdb/cp-support.h |  6 +++---
 gdb/eval.c       | 35 ++++++++++++++++++-----------------
 gdb/infcall.c    |  2 +-
 gdb/valarith.c   |  9 ++++-----
 gdb/valops.c     | 34 +++++++++++++++++-----------------
 gdb/value.h      |  4 ++--
 7 files changed, 71 insertions(+), 65 deletions(-)
  

Patch

diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index e02e859b99a..4fbde37b280 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -57,17 +57,17 @@  static void demangled_name_complaint (const char *name);
 
 /* Functions related to overload resolution.  */
 
-static void overload_list_add_symbol (struct symbol *sym,
+static void overload_list_add_symbol (block_symbol sym,
 				      const char *oload_name,
-				      std::vector<symbol *> *overload_list);
+				      std::vector<block_symbol> *overload_list);
 
 static void add_symbol_overload_list_using
   (const char *func_name, const char *the_namespace,
-   std::vector<symbol *> *overload_list);
+   std::vector<block_symbol> *overload_list);
 
 static void add_symbol_overload_list_qualified
   (const char *func_name,
-   std::vector<symbol *> *overload_list);
+   std::vector<block_symbol> *overload_list);
 
 /* The list of "maint cplus" commands.  */
 
@@ -1210,18 +1210,20 @@  cp_entire_prefix_len (const char *name)
    OVERLOAD_LIST.  */
 
 static void
-overload_list_add_symbol (struct symbol *sym,
+overload_list_add_symbol (block_symbol bsym,
 			  const char *oload_name,
-			  std::vector<symbol *> *overload_list)
+			  std::vector<block_symbol> *overload_list)
 {
+  symbol *sym = bsym.symbol;
+
   /* If there is no type information, we can't do anything, so
      skip.  */
   if (sym->type () == NULL)
     return;
 
   /* skip any symbols that we've already considered.  */
-  for (symbol *listed_sym : *overload_list)
-    if (strcmp (sym->linkage_name (), listed_sym->linkage_name ()) == 0)
+  for (block_symbol listed_sym : *overload_list)
+    if (strcmp (sym->linkage_name (), listed_sym.symbol->linkage_name ()) == 0)
       return;
 
   /* Get the demangled name without parameters */
@@ -1234,18 +1236,18 @@  overload_list_add_symbol (struct symbol *sym,
   if (strcmp (sym_name.get (), oload_name) != 0)
     return;
 
-  overload_list->push_back (sym);
+  overload_list->push_back (bsym);
 }
 
 /* Return a null-terminated list of pointers to function symbols that
    are named FUNC_NAME and are visible within NAMESPACE.  */
 
-struct std::vector<symbol *>
+struct std::vector<block_symbol>
 make_symbol_overload_list (const char *func_name,
 			   const char *the_namespace)
 {
   const char *name;
-  std::vector<symbol *> overload_list;
+  std::vector<block_symbol> overload_list;
 
   overload_list.reserve (100);
 
@@ -1273,12 +1275,15 @@  make_symbol_overload_list (const char *func_name,
 static void
 add_symbol_overload_list_block (const char *name,
 				const struct block *block,
-				std::vector<symbol *> *overload_list)
+				std::vector<block_symbol> *overload_list)
 {
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
   for (struct symbol *sym : block_iterator_range (block, &lookup_name))
-    overload_list_add_symbol (sym, name, overload_list);
+    {
+      block_symbol bsym { sym, block };
+      overload_list_add_symbol (bsym, name, overload_list);
+    }
 }
 
 /* Adds the function FUNC_NAME from NAMESPACE to the overload set.  */
@@ -1286,7 +1291,7 @@  add_symbol_overload_list_block (const char *name,
 static void
 add_symbol_overload_list_namespace (const char *func_name,
 				    const char *the_namespace,
-				    std::vector<symbol *> *overload_list)
+				    std::vector<block_symbol> *overload_list)
 {
   const char *name;
   const struct block *block = NULL;
@@ -1322,9 +1327,10 @@  add_symbol_overload_list_namespace (const char *func_name,
    base types.  */
 
 static void
-add_symbol_overload_list_adl_namespace (struct type *type,
-					const char *func_name,
-					std::vector<symbol *> *overload_list)
+add_symbol_overload_list_adl_namespace
+     (struct type *type,
+      const char *func_name,
+      std::vector<block_symbol> *overload_list)
 {
   char *the_namespace;
   const char *type_name;
@@ -1374,7 +1380,7 @@  add_symbol_overload_list_adl_namespace (struct type *type,
 void
 add_symbol_overload_list_adl (gdb::array_view<type *> arg_types,
 			      const char *func_name,
-			      std::vector<symbol *> *overload_list)
+			      std::vector<block_symbol> *overload_list)
 {
   for (type *arg_type : arg_types)
     add_symbol_overload_list_adl_namespace (arg_type, func_name,
@@ -1389,7 +1395,7 @@  add_symbol_overload_list_adl (gdb::array_view<type *> arg_types,
 static void
 add_symbol_overload_list_using (const char *func_name,
 				const char *the_namespace,
-				std::vector<symbol *> *overload_list)
+				std::vector<block_symbol> *overload_list)
 {
   struct using_direct *current;
   const struct block *block;
@@ -1438,7 +1444,7 @@  add_symbol_overload_list_using (const char *func_name,
 
 static void
 add_symbol_overload_list_qualified (const char *func_name,
-				    std::vector<symbol *> *overload_list)
+				    std::vector<block_symbol> *overload_list)
 {
   const struct block *surrounding_static_block = 0;
 
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 709dca46df1..7f27120a0fe 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -107,13 +107,13 @@  extern gdb::unique_xmalloc_ptr<char> cp_remove_params
 extern gdb::unique_xmalloc_ptr<char> cp_remove_params_if_any
   (const char *demangled_name, bool completion_mode);
 
-extern std::vector<symbol *> make_symbol_overload_list (const char *,
-							const char *);
+extern std::vector<block_symbol> make_symbol_overload_list (const char *,
+							    const char *);
 
 extern void add_symbol_overload_list_adl
   (gdb::array_view<type *> arg_types,
    const char *func_name,
-   std::vector<symbol *> *overload_list);
+   std::vector<block_symbol> *overload_list);
 
 extern struct type *cp_lookup_rtti_type (const char *name,
 					 const struct block *block);
diff --git a/gdb/eval.c b/gdb/eval.c
index 9b76d3d5376..ba09599b28a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -693,15 +693,15 @@  var_value_operation::evaluate_funcall (struct type *expect_type,
   for (int i = 0; i < args.size (); ++i)
     argvec[i] = args[i]->evaluate_with_coercion (exp, noside);
 
-  struct symbol *symp;
+  block_symbol symp;
   find_overload_match (argvec, NULL, NON_METHOD,
-		       NULL, std::get<0> (m_storage).symbol,
+		       NULL, std::get<0> (m_storage),
 		       NULL, &symp, NULL, 0, noside);
 
-  if (symp->type ()->code () == TYPE_CODE_ERROR)
-    error_unknown_type (symp->print_name ());
+  if (symp.symbol->type ()->code () == TYPE_CODE_ERROR)
+    error_unknown_type (symp.symbol->print_name ());
   value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
-				      symp);
+				      symp.symbol);
 
   return evaluate_subexp_do_call (exp, noside, callee, argvec,
 				  nullptr, expect_type);
@@ -722,7 +722,7 @@  scope_operation::evaluate_funcall (struct type *expect_type,
   const std::string &name = std::get<1> (m_storage);
   struct type *type = std::get<0> (m_storage);
 
-  symbol *function = NULL;
+  block_symbol function {};
   const char *function_name = NULL;
   std::vector<value *> argvec (1 + args.size ());
   if (type->code () == TYPE_CODE_NAMESPACE)
@@ -730,8 +730,8 @@  scope_operation::evaluate_funcall (struct type *expect_type,
       function = cp_lookup_symbol_namespace (type->name (),
 					     name.c_str (),
 					     get_selected_block (0),
-					     VAR_DOMAIN).symbol;
-      if (function == NULL)
+					     VAR_DOMAIN);
+      if (function.symbol == nullptr)
 	error (_("No symbol \"%s\" in namespace \"%s\"."),
 	       name.c_str (), type->name ());
     }
@@ -755,7 +755,7 @@  scope_operation::evaluate_funcall (struct type *expect_type,
       int static_memfuncp;
 
       find_overload_match (arg_view, function_name, METHOD,
-			   &argvec[0], nullptr, &callee, nullptr,
+			   &argvec[0], {}, &callee, nullptr,
 			   &static_memfuncp, 0, noside);
       if (!static_memfuncp)
 	{
@@ -769,12 +769,12 @@  scope_operation::evaluate_funcall (struct type *expect_type,
     }
   else
     {
-      symbol *symp;
+      block_symbol symp;
       arg_view = arg_view.slice (1);
       find_overload_match (arg_view, nullptr,
 			   NON_METHOD, nullptr, function,
 			   nullptr, &symp, nullptr, 1, noside);
-      callee = value_of_variable (symp, get_selected_block (0));
+      callee = value_of_variable (symp.symbol, get_selected_block (0));
     }
 
   return evaluate_subexp_do_call (exp, noside, callee, arg_view,
@@ -914,7 +914,7 @@  structop_base_operation::evaluate_funcall
 	 evaluation.  */
       value *val0 = vals[0];
       find_overload_match (arg_view, tstr, METHOD,
-			   &val0, nullptr, &callee, nullptr,
+			   &val0, {}, &callee, nullptr,
 			   &static_memfuncp, 0, noside);
       vals[0] = val0;
     }
@@ -2319,14 +2319,15 @@  adl_func_operation::evaluate (struct type *expect_type,
   for (int i = 0; i < arg_ops.size (); ++i)
     args[i] = arg_ops[i]->evaluate_with_coercion (exp, noside);
 
-  struct symbol *symp;
+  block_symbol symp;
   find_overload_match (args, std::get<0> (m_storage).c_str (),
 		       NON_METHOD,
-		       nullptr, nullptr,
+		       nullptr, {},
 		       nullptr, &symp, nullptr, 0, noside);
-  if (symp->type ()->code () == TYPE_CODE_ERROR)
-    error_unknown_type (symp->print_name ());
-  value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
+  if (symp.symbol->type ()->code () == TYPE_CODE_ERROR)
+    error_unknown_type (symp.symbol->print_name ());
+  value *callee = evaluate_var_value (noside, std::get<1> (m_storage),
+				      symp.symbol);
   return evaluate_subexp_do_call (exp, noside, callee, args,
 				  nullptr, expect_type);
 
diff --git a/gdb/infcall.c b/gdb/infcall.c
index a36a5e81b3a..54c14a097bc 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -1187,7 +1187,7 @@  call_function_by_hand_dummy (struct value *function,
 	  value *cctor_args[2] = { clone_ptr, original_arg };
 	  find_overload_match (gdb::make_array_view (cctor_args, 2),
 			       param_type->name (), METHOD,
-			       &clone_ptr, nullptr, &copy_ctor, nullptr,
+			       &clone_ptr, {}, &copy_ctor, nullptr,
 			       nullptr, 0, EVAL_NORMAL);
 
 	  if (copy_ctor == nullptr)
diff --git a/gdb/valarith.c b/gdb/valarith.c
index f3acf98c98b..5f9ecdf912c 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -338,25 +338,24 @@  static struct value *
 value_user_defined_cpp_op (gdb::array_view<value *> args, char *oper,
 			   int *static_memfuncp, enum noside noside)
 {
-
-  struct symbol *symp = NULL;
   struct value *valp = NULL;
 
+  block_symbol symp;
   find_overload_match (args, oper, BOTH /* could be method */,
 		       &args[0] /* objp */,
-		       NULL /* pass NULL symbol since symbol is unknown */,
+		       {} /* pass NULL symbol since symbol is unknown */,
 		       &valp, &symp, static_memfuncp, 0, noside);
 
   if (valp)
     return valp;
 
-  if (symp)
+  if (symp.symbol != nullptr)
     {
       /* This is a non member function and does not
 	 expect a reference as its first argument
 	 rather the explicit structure.  */
       args[0] = value_ind (args[0]);
-      return value_of_variable (symp, 0);
+      return value_of_variable (symp.symbol, symp.block);
     }
 
   error (_("Could not find %s."), oper);
diff --git a/gdb/valops.c b/gdb/valops.c
index b7ed458a649..9cb9a7147e2 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -57,13 +57,13 @@  static struct value *search_struct_method (const char *, struct value **,
 
 static int find_oload_champ_namespace (gdb::array_view<value *> args,
 				       const char *, const char *,
-				       std::vector<symbol *> *oload_syms,
+				       std::vector<block_symbol> *oload_syms,
 				       badness_vector *,
 				       const int no_adl);
 
 static int find_oload_champ_namespace_loop (gdb::array_view<value *> args,
-					    const char *, const char *,
-					    int, std::vector<symbol *> *oload_syms,
+					    const char *, const char *, int,
+					    std::vector<block_symbol> *oload_syms,
 					    badness_vector *, int *,
 					    const int no_adl);
 
@@ -71,7 +71,7 @@  static int find_oload_champ (gdb::array_view<value *> args,
 			     size_t num_fns,
 			     fn_field *methods,
 			     xmethod_worker_up *xmethods,
-			     symbol **functions,
+			     block_symbol *functions,
 			     badness_vector *oload_champ_bv);
 
 static int oload_method_static_p (struct fn_field *, int);
@@ -2709,8 +2709,8 @@  incomplete_type_hint (gdb::array_view<value *> args)
 int
 find_overload_match (gdb::array_view<value *> args,
 		     const char *name, enum oload_search_type method,
-		     struct value **objp, struct symbol *fsym,
-		     struct value **valp, struct symbol **symp, 
+		     struct value **objp, block_symbol fsym,
+		     struct value **valp, block_symbol *symp,
 		     int *staticp, const int no_adl,
 		     const enum noside noside)
 {
@@ -2732,7 +2732,7 @@  find_overload_match (gdb::array_view<value *> args,
   /* For methods, the list of overloaded methods.  */
   gdb::array_view<fn_field> methods;
   /* For non-methods, the list of overloaded function symbols.  */
-  std::vector<symbol *> functions;
+  std::vector<block_symbol> functions;
   /* For xmethods, the vector of xmethod workers.  */
   std::vector<xmethod_worker_up> xmethods;
   struct type *basetype = NULL;
@@ -2875,15 +2875,15 @@  find_overload_match (gdb::array_view<value *> args,
       if (method == BOTH)
 	args[0] = value_ind (args[0]);
 
-      if (fsym)
+      if (fsym.symbol != nullptr)
 	{
-	  qualified_name = fsym->natural_name ();
+	  qualified_name = fsym.symbol->natural_name ();
 
 	  /* If we have a function with a C++ name, try to extract just
 	     the function part.  Do not try this for non-functions (e.g.
 	     function pointers).  */
 	  if (qualified_name
-	      && (check_typedef (fsym->type ())->code ()
+	      && (check_typedef (fsym.symbol->type ())->code ()
 		  == TYPE_CODE_FUNC))
 	    {
 	      temp_func = cp_func_name (qualified_name);
@@ -3059,7 +3059,7 @@  static int
 find_oload_champ_namespace (gdb::array_view<value *> args,
 			    const char *func_name,
 			    const char *qualified_name,
-			    std::vector<symbol *> *oload_syms,
+			    std::vector<block_symbol> *oload_syms,
 			    badness_vector *oload_champ_bv,
 			    const int no_adl)
 {
@@ -3086,7 +3086,7 @@  find_oload_champ_namespace_loop (gdb::array_view<value *> args,
 				 const char *func_name,
 				 const char *qualified_name,
 				 int namespace_len,
-				 std::vector<symbol *> *oload_syms,
+				 std::vector<block_symbol> *oload_syms,
 				 badness_vector *oload_champ_bv,
 				 int *oload_champ,
 				 const int no_adl)
@@ -3133,7 +3133,7 @@  find_oload_champ_namespace_loop (gdb::array_view<value *> args,
   strncpy (new_namespace, qualified_name, namespace_len);
   new_namespace[namespace_len] = '\0';
 
-  std::vector<symbol *> new_oload_syms
+  std::vector<block_symbol> new_oload_syms
     = make_symbol_overload_list (func_name, new_namespace);
 
   /* If we have reached the deepest level perform argument
@@ -3202,7 +3202,7 @@  find_oload_champ (gdb::array_view<value *> args,
 		  size_t num_fns,
 		  fn_field *methods,
 		  xmethod_worker_up *xmethods,
-		  symbol **functions,
+		  block_symbol *functions,
 		  badness_vector *oload_champ_bv)
 {
   /* A measure of how good an overloaded instance is.  */
@@ -3238,14 +3238,14 @@  find_oload_champ (gdb::array_view<value *> args,
 	      static_offset = oload_method_static_p (methods, ix);
 	    }
 	  else
-	    nparms = functions[ix]->type ()->num_fields ();
+	    nparms = functions[ix].symbol->type ()->num_fields ();
 
 	  parm_types.reserve (nparms);
 	  for (jj = 0; jj < nparms; jj++)
 	    {
 	      type *t = (methods != NULL
 			 ? (TYPE_FN_FIELD_ARGS (methods, ix)[jj].type ())
-			 : functions[ix]->type ()->field (jj).type ());
+			 : functions[ix].symbol->type ()->field (jj).type ());
 	      parm_types.push_back (t);
 	    }
 	}
@@ -3269,7 +3269,7 @@  find_oload_champ (gdb::array_view<value *> args,
 	    gdb_printf (gdb_stderr,
 			"Overloaded function instance "
 			"%s # of parms %d\n",
-			functions[ix]->demangled_name (),
+			functions[ix].symbol->demangled_name (),
 			(int) parm_types.size ());
 
 	  gdb_printf (gdb_stderr,
diff --git a/gdb/value.h b/gdb/value.h
index b683cbf5f90..6f0b61a853d 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1294,8 +1294,8 @@  enum oload_search_type { NON_METHOD, METHOD, BOTH };
 extern int find_overload_match (gdb::array_view<value *> args,
 				const char *name,
 				enum oload_search_type method,
-				struct value **objp, struct symbol *fsym,
-				struct value **valp, struct symbol **symp,
+				struct value **objp, block_symbol fsym,
+				struct value **valp, block_symbol *symp,
 				int *staticp, const int no_adl,
 				enum noside noside);