Introduce register_operation
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:16 +0000 (07:28 -0700)
This adds class register_operation, which implements OP_REGISTER.

gdb/ChangeLog
2021-03-08  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
gdb/ax-gdb.c
gdb/eval.c
gdb/expop.h

index b237cade1760e486c3dba1c6b409134995d254ee..0633260cb5a67708b0cd588f6182fd4816540af2 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-08  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.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class last_operation): New.
index 602817007035fed6f9e461858920d539a5ab26e7..5ffe5a00da15edb912bc227820399f4c7f154cf0 100644 (file)
@@ -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
index 56010ee22e931325f6f4d5aa02fabd5d91edc22c..4601c92ed5f4c1751c3ad2b9c0e66515acdc10bc 100644 (file)
@@ -1254,7 +1254,7 @@ eval_op_func_static_var (struct type *expect_type, struct expression *exp,
 
 /* Helper function that implements the body of OP_REGISTER.  */
 
-static struct value *
+struct value *
 eval_op_register (struct type *expect_type, struct expression *exp,
                  enum noside noside, const char *name)
 {
index 73b66bf154bed2c2ba96c40863055796e07f4e42..a0e00302532fc120f8ac9221ca107ee71929e9e7 100644 (file)
@@ -58,6 +58,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
 {
@@ -597,6 +600,33 @@ public:
   { 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 */