[005/203] Split out eval_op_register

Message ID 20210101214723.1784144-6-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:44 p.m.
This splits OP_REGISTER into a new function for future use.

gdb/ChangeLog
2021-01-01  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_register): New function.
	(evaluate_subexp_standard): Use it.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 50 +++++++++++++++++++++++++++++---------------------
 2 files changed, 34 insertions(+), 21 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 5312525e850..cff323bba46 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1244,6 +1244,34 @@  eval_op_func_static_var (struct type *expect_type, struct expression *exp,
   return evaluate_var_value (noside, sym.block, sym.symbol);
 }
 
+static struct value *
+eval_op_register (struct type *expect_type, struct expression *exp,
+		  enum noside noside, const char *name)
+{
+  int regno;
+  struct value *val;
+
+  regno = user_reg_map_name_to_regnum (exp->gdbarch,
+				       name, strlen (name));
+  if (regno == -1)
+    error (_("Register $%s not available."), name);
+
+  /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
+     a value with the appropriate register type.  Unfortunately,
+     we don't have easy access to the type of user registers.
+     So for these registers, we fetch the register value regardless
+     of the evaluation mode.  */
+  if (noside == EVAL_AVOID_SIDE_EFFECTS
+      && regno < gdbarch_num_cooked_regs (exp->gdbarch))
+    val = value_zero (register_type (exp->gdbarch, regno), not_lval);
+  else
+    val = value_of_register (regno, get_selected_frame (NULL));
+  if (val == NULL)
+    error (_("Value of register %s not available."), name);
+  else
+    return val;
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
 			  struct expression *exp, int *pos,
@@ -1341,29 +1369,9 @@  evaluate_subexp_standard (struct type *expect_type,
     case OP_REGISTER:
       {
 	const char *name = &exp->elts[pc + 2].string;
-	int regno;
-	struct value *val;
 
 	(*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
-	regno = user_reg_map_name_to_regnum (exp->gdbarch,
-					     name, strlen (name));
-	if (regno == -1)
-	  error (_("Register $%s not available."), name);
-
-	/* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
-	   a value with the appropriate register type.  Unfortunately,
-	   we don't have easy access to the type of user registers.
-	   So for these registers, we fetch the register value regardless
-	   of the evaluation mode.  */
-	if (noside == EVAL_AVOID_SIDE_EFFECTS
-	    && regno < gdbarch_num_cooked_regs (exp->gdbarch))
-	  val = value_zero (register_type (exp->gdbarch, regno), not_lval);
-	else
-	  val = value_of_register (regno, get_selected_frame (NULL));
-	if (val == NULL)
-	  error (_("Value of register %s not available."), name);
-	else
-	  return val;
+	return eval_op_register (expect_type, exp, noside, name);
       }
     case OP_BOOL:
       (*pos) += 2;