[18/30] Change value_of_variable to take a block_symbol

Message ID 20231029-split-objfile-2023-bound-sym-october-v1-18-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 value_of_variable to take a block_symbol and to call the
new read_var_value overload.
---
 gdb/ada-lang.c       |  2 +-
 gdb/dwarf2/loc.c     |  2 +-
 gdb/eval.c           | 17 +++++++----------
 gdb/f-valprint.c     |  4 ++--
 gdb/python/py-type.c |  2 +-
 gdb/rust-lang.c      |  2 +-
 gdb/valarith.c       |  2 +-
 gdb/valops.c         | 15 ++++++++-------
 gdb/value.c          |  2 +-
 gdb/value.h          |  6 ++----
 10 files changed, 25 insertions(+), 29 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 8f2fc5410d4..1f854940b36 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11389,7 +11389,7 @@  get_var_value (const char *name, const char *err_msg)
 	error (("%s"), err_msg);
     }
 
-  return value_of_variable (syms[0].symbol, syms[0].block);
+  return value_of_variable (syms[0]);
 }
 
 /* Value of integer variable named NAME in the current environment.
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 17509f81464..fad32cfc27c 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -627,7 +627,7 @@  compute_var_value (const char *name)
   struct block_symbol sym = lookup_symbol (name, nullptr, VAR_DOMAIN,
 					   nullptr);
   if (sym.symbol != nullptr)
-    return value_of_variable (sym.symbol, sym.block);
+    return value_of_variable (sym);
   return nullptr;
 }
 
diff --git a/gdb/eval.c b/gdb/eval.c
index 0f5e3c18a05..5b40eed6799 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -532,7 +532,7 @@  evaluate_var_value (enum noside noside, block_symbol var)
 
   try
     {
-      ret = value_of_variable (var.symbol, var.block);
+      ret = value_of_variable (var);
     }
 
   catch (const gdb_exception_error &except)
@@ -773,7 +773,7 @@  scope_operation::evaluate_funcall (struct type *expect_type,
       find_overload_match (arg_view, nullptr,
 			   NON_METHOD, nullptr, function,
 			   nullptr, &symp, nullptr, 1, noside);
-      callee = value_of_variable (symp.symbol, get_selected_block (0));
+      callee = value_of_variable (symp);
     }
 
   return evaluate_subexp_do_call (exp, noside, callee, arg_view,
@@ -2028,17 +2028,15 @@  eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
   addr = value_as_long (ret);
   if (addr)
     {
-      struct symbol *sym = NULL;
-
       /* The address might point to a function descriptor;
 	 resolve it to the actual code address instead.  */
       addr = gdbarch_convert_from_func_ptr_addr
 	(exp->gdbarch, addr, current_inferior ()->top_target ());
 
       /* Is it a high_level symbol?  */
-      sym = find_pc_function (addr).symbol;
-      if (sym != NULL)
-	method = value_of_variable (sym, 0);
+      block_symbol sym = find_pc_function (addr);
+      if (sym.symbol != nullptr)
+	method = value_of_variable (sym);
     }
 
   /* If we found a method with symbol information, check to see
@@ -2668,7 +2666,7 @@  var_value_operation::evaluate_for_address (struct expression *exp,
       return value::zero (type, not_lval);
     }
   else
-    return address_of_variable (var, std::get<0> (m_storage).block);
+    return address_of_variable (std::get<0> (m_storage));
 }
 
 value *
@@ -2681,8 +2679,7 @@  var_value_operation::evaluate_with_coercion (struct expression *exp,
       && !type->is_vector ()
       && CAST_IS_CONVERSION (exp->language_defn))
     {
-      struct value *val = address_of_variable (var,
-					       std::get<0> (m_storage).block);
+      struct value *val = address_of_variable (std::get<0> (m_storage));
       return value_cast (lookup_pointer_type (type->target_type ()), val);
     }
   return evaluate (nullptr, exp, noside);
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 2b7dafc4de3..5cafb5137e0 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -556,7 +556,7 @@  f_language::value_print_inner (struct value *val, struct ui_file *stream,
 		  if (sym.symbol == nullptr)
 		    error (_("failed to find symbol for name list component %s"),
 			   field_name);
-		  field = value_of_variable (sym.symbol, sym.block);
+		  field = value_of_variable (sym);
 		}
 	      else
 		field = value_field (val, index);
@@ -657,7 +657,7 @@  info_common_command_for_block (const struct block *block, const char *comname,
 
 	    try
 	      {
-		val = value_of_variable (common->contents[index], block);
+		val = value_of_variable ({ common->contents[index], block });
 		value_print (val, gdb_stdout, &opts);
 	      }
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index bfaa6d24d94..3c8b7f6c8b6 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1065,7 +1065,7 @@  typy_template_argument (PyObject *self, PyObject *args)
   try
     {
       scoped_value_mark free_values;
-      struct value *val = value_of_variable (sym, block);
+      struct value *val = value_of_variable ({ sym, block });
       result = value_to_value_object (val);
     }
   catch (const gdb_exception &except)
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index aa106b44bd9..841ca74137b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1574,7 +1574,7 @@  rust_structop::evaluate_funcall (struct type *expect_type,
   if (fn_type->field (0).type ()->code () == TYPE_CODE_PTR)
     args[0] = value_addr (args[0]);
 
-  value *function = address_of_variable (sym.symbol, block);
+  value *function = address_of_variable (sym);
 
   for (int i = 0; i < ops.size (); ++i)
     args[i + 1] = ops[i]->evaluate (nullptr, exp, noside);
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 5f9ecdf912c..de77c757b04 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -355,7 +355,7 @@  value_user_defined_cpp_op (gdb::array_view<value *> args, char *oper,
 	 expect a reference as its first argument
 	 rather the explicit structure.  */
       args[0] = value_ind (args[0]);
-      return value_of_variable (symp.symbol, symp.block);
+      return value_of_variable (symp);
     }
 
   error (_("Could not find %s."), oper);
diff --git a/gdb/valops.c b/gdb/valops.c
index 9cb9a7147e2..07cc66b2a8d 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -130,7 +130,7 @@  find_function_in_inferior (const char *name, struct objfile **objf_p)
       if (objf_p)
 	*objf_p = sym.symbol->objfile ();
 
-      return value_of_variable (sym.symbol, sym.block);
+      return value_of_variable (sym);
     }
   else
     {
@@ -1383,26 +1383,27 @@  value_repeat (struct value *arg1, int count)
 }
 
 struct value *
-value_of_variable (struct symbol *var, const struct block *b)
+value_of_variable (block_symbol var)
 {
   frame_info_ptr frame = NULL;
 
-  if (symbol_read_needs_frame (var))
+  if (symbol_read_needs_frame (var.symbol))
     frame = get_selected_frame (_("No frame selected."));
 
-  return read_var_value (var, b, frame);
+  return read_var_value (var, frame);
 }
 
 struct value *
-address_of_variable (struct symbol *var, const struct block *b)
+address_of_variable (block_symbol bvar)
 {
+  symbol *var = bvar.symbol;
   struct type *type = var->type ();
   struct value *val;
 
   /* Evaluate it first; if the result is a memory address, we're fine.
      Lazy evaluation pays off here.  */
 
-  val = value_of_variable (var, b);
+  val = value_of_variable (bvar);
   type = val->type ();
 
   if ((val->lval () == lval_memory && val->lazy ())
@@ -3830,7 +3831,7 @@  value_maybe_namespace_elt (const struct type *curtype,
 	   && (sym.symbol->aclass () == LOC_TYPEDEF))
     result = value::allocate (sym.symbol->type ());
   else
-    result = value_of_variable (sym.symbol, sym.block);
+    result = value_of_variable (sym);
 
   if (want_address)
     result = value_addr (result);
diff --git a/gdb/value.c b/gdb/value.c
index 17b7c53d052..4fd77b774f6 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2897,7 +2897,7 @@  value_static_field (struct type *type, int fieldno)
 	    retval = value_at_lazy (field_type, msym.value_address ());
 	}
       else
-	retval = value_of_variable (sym.symbol, sym.block);
+	retval = value_of_variable (sym);
       break;
     }
     default:
diff --git a/gdb/value.h b/gdb/value.h
index 37c07a41205..7cb830110fc 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1117,11 +1117,9 @@  extern struct value *value_from_register (struct type *type, int regnum,
 extern CORE_ADDR address_from_register (int regnum,
 					frame_info_ptr frame);
 
-extern struct value *value_of_variable (struct symbol *var,
-					const struct block *b);
+extern struct value *value_of_variable (block_symbol var);
 
-extern struct value *address_of_variable (struct symbol *var,
-					  const struct block *b);
+extern struct value *address_of_variable (block_symbol var);
 
 extern struct value *value_of_register (int regnum, frame_info_ptr frame);