[PATCH 083/203] Introduce register_operation

Tom Tromey
2021-01-01T21:48:31Z

This adds class register_operation, which implements OP_REGISTER.

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

* expop.h (class register_operation): New.
* eval.c (eval_op_register): No longer static.
* ax-gdb.c (register_operation::do_generate_ax): New method.
---
gdb/ChangeLog | 6 ++++++
gdb/ax-gdb.c | 24 ++++++++++++++++++++++++
gdb/eval.c | 2 +-
gdb/expop.h | 30 ++++++++++++++++++++++++++++++
4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 60281700703..5ffe5a00da1 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2341,6 +2341,30 @@ var_msym_value_operation::do_generate_ax (struct expression *exp,
}
}

+void
+register_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ const char *name = std::get<0> (m_storage).c_str ();
+ int len = std::get<0> (m_storage).size ();
+ int reg;
+
+ reg = user_reg_map_name_to_regnum (ax->gdbarch, name, len);
+ if (reg == -1)
+ internal_error (__FILE__, __LINE__,
+ _("Register $%s not available"), name);
+ /* No support for tracing user registers yet. */
+ if (reg >= gdbarch_num_cooked_regs (ax->gdbarch))
+ error (_("'%s' is a user-register; "
+ "GDB cannot yet trace user-register contents."),
+ name);
+ value->kind = axs_lvalue_register;
+ value->u.reg = reg;
+ value->type = register_type (ax->gdbarch, reg);
+}
+
}

/* This handles the middle-to-right-side of code generation for binary
diff --git a/gdb/eval.c b/gdb/eval.c
index f28c7ace8be..510a7b720cb 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1245,7 +1245,7 @@ eval_op_func_static_var (struct type *expect_type, struct expression *exp,
return evaluate_var_value (noside, sym.block, sym.symbol);
}

-static struct value *
+struct value *
eval_op_register (struct type *expect_type, struct expression *exp,
enum noside noside, const char *name)
{
diff --git a/gdb/expop.h b/gdb/expop.h
index 110ad0a29ab..32b57a0fff7 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -57,6 +57,9 @@ extern struct value *eval_op_func_static_var (struct type *expect_type,
struct expression *exp,
enum noside noside,
value *func, const char *var);
+extern struct value *eval_op_register (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside, const char *name);

namespace expr
{
@@ -586,6 +589,33 @@ class last_operation
{ return OP_LAST; }
};

+class register_operation
+ : public tuple_holding_operation<std::string>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ return eval_op_register (expect_type, exp, noside,
+ std::get<0> (m_storage).c_str ());
+ }
+
+ enum exp_opcode opcode () const override
+ { return OP_REGISTER; }
+
+protected:
+
+ void do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+ override;
+};
+
} /* namespace expr */

#endif /* EXPOP_H */
--
2.26.2