[binutils-gdb] Introduce internalvar_operation

Tom Tromey tromey@sourceware.org
Mon Mar 8 14:52:31 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e6e01e16c547b21be2e3fc6b0783492aea98c427

commit e6e01e16c547b21be2e3fc6b0783492aea98c427
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Mar 8 07:27:57 2021 -0700

    Introduce internalvar_operation
    
    This adds class internalvar_operation, which implements
    OP_INTERNALVAR.
    
    gdb/ChangeLog
    2021-03-08  Tom Tromey  <tom@tromey.com>
    
            * expop.h (class internalvar_operation): New.
            * ax-gdb.c (internalvar_operation::do_generate_ax): New method.

Diff:
---
 gdb/ChangeLog |  5 +++++
 gdb/ax-gdb.c  | 25 +++++++++++++++++++++++++
 gdb/expop.h   | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9acaee4c152..05f67b855b7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+	* expop.h (class internalvar_operation): New.
+	* ax-gdb.c (internalvar_operation::do_generate_ax): New method.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
 	* expop.h (class bool_operation): New.
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 5ffe5a00da1..e25e2942475 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2365,6 +2365,31 @@ register_operation::do_generate_ax (struct expression *exp,
   value->type = register_type (ax->gdbarch, reg);
 }
 
+void
+internalvar_operation::do_generate_ax (struct expression *exp,
+				       struct agent_expr *ax,
+				       struct axs_value *value,
+				       struct type *cast_type)
+{
+  struct internalvar *var = std::get<0> (m_storage);
+  const char *name = internalvar_name (var);
+  struct trace_state_variable *tsv;
+
+  tsv = find_trace_state_variable (name);
+  if (tsv)
+    {
+      ax_tsv (ax, aop_getv, tsv->number);
+      if (ax->tracing)
+	ax_tsv (ax, aop_tracev, tsv->number);
+      /* Trace state variables are always 64-bit integers.  */
+      value->kind = axs_rvalue;
+      value->type = builtin_type (ax->gdbarch)->builtin_long_long;
+    }
+  else if (! compile_internalvar_to_ax (var, ax, value))
+    error (_("$%s is not a trace state variable; GDB agent "
+	     "expressions cannot use convenience variables."), name);
+}
+
 }
 
 /* This handles the middle-to-right-side of code generation for binary
diff --git a/gdb/expop.h b/gdb/expop.h
index 44098b84761..d143815a259 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -649,6 +649,38 @@ public:
   { return true; }
 };
 
+class internalvar_operation
+  : public tuple_holding_operation<internalvar *>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    return value_of_internalvar (exp->gdbarch,
+				 std::get<0> (m_storage));
+  }
+
+  internalvar *get_internalvar () const
+  {
+    return std::get<0> (m_storage);
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_INTERNALVAR; }
+
+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 */


More information about the Gdb-cvs mailing list