From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Split out eval_op_register X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ffff730bf6a939490b5e93a323ba2e4026d27818;p=binutils-gdb.git Split out eval_op_register This splits OP_REGISTER into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey * eval.c (eval_op_register): New function. (evaluate_subexp_standard): Use it. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a549ce0da6a..9d50fe0ca36 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * eval.c (eval_op_register): New function. + (evaluate_subexp_standard): Use it. + 2021-03-08 Tom Tromey * eval.c (eval_op_func_static_var): New function. diff --git a/gdb/eval.c b/gdb/eval.c index c36594304d4..60eb01dfa71 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1251,6 +1251,36 @@ eval_op_func_static_var (struct type *expect_type, struct expression *exp, return evaluate_var_value (noside, sym.block, sym.symbol); } +/* Helper function that implements the body of OP_REGISTER. */ + +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, @@ -1348,29 +1378,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;