Move `compute_probe_arg' and `compile_probe_arg' to probe.c
[deliverable/binutils-gdb.git] / gdb / probe.c
index 5ab2593bf914eaf9e67d00a46439155e1d0ef1ba..7a412776bfcc5706801f09138440bdf63c74a977 100644 (file)
@@ -30,6 +30,9 @@
 #include "gdb_regex.h"
 #include "frame.h"
 #include "arch-utils.h"
+#include "value.h"
+#include "ax.h"
+#include "ax-gdb.h"
 #include <ctype.h>
 
 typedef struct bound_probe bound_probe_s;
@@ -826,6 +829,87 @@ will show information about all types of probes."),
   return &info_probes_cmdlist;
 }
 
+\f
+
+/* This is called to compute the value of one of the $_probe_arg*
+   convenience variables.  */
+
+static struct value *
+compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
+                  void *data)
+{
+  struct frame_info *frame = get_selected_frame (_("No frame selected"));
+  CORE_ADDR pc = get_frame_pc (frame);
+  int sel = (int) (uintptr_t) data;
+  struct bound_probe pc_probe;
+  const struct sym_probe_fns *pc_probe_fns;
+  unsigned n_args;
+
+  /* SEL == -1 means "_probe_argc".  */
+  gdb_assert (sel >= -1);
+
+  pc_probe = find_probe_by_pc (pc);
+  if (pc_probe.probe == NULL)
+    error (_("No probe at PC %s"), core_addr_to_string (pc));
+
+  n_args = get_probe_argument_count (pc_probe.probe, frame);
+  if (sel == -1)
+    return value_from_longest (builtin_type (arch)->builtin_int, n_args);
+
+  if (sel >= n_args)
+    error (_("Invalid probe argument %d -- probe has %u arguments available"),
+          sel, n_args);
+
+  return evaluate_probe_argument (pc_probe.probe, sel, frame);
+}
+
+/* This is called to compile one of the $_probe_arg* convenience
+   variables into an agent expression.  */
+
+static void
+compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
+                  struct axs_value *value, void *data)
+{
+  CORE_ADDR pc = expr->scope;
+  int sel = (int) (uintptr_t) data;
+  struct bound_probe pc_probe;
+  const struct sym_probe_fns *pc_probe_fns;
+  int n_args;
+  struct frame_info *frame = get_selected_frame (NULL);
+
+  /* SEL == -1 means "_probe_argc".  */
+  gdb_assert (sel >= -1);
+
+  pc_probe = find_probe_by_pc (pc);
+  if (pc_probe.probe == NULL)
+    error (_("No probe at PC %s"), core_addr_to_string (pc));
+
+  n_args = get_probe_argument_count (pc_probe.probe, frame);
+
+  if (sel == -1)
+    {
+      value->kind = axs_rvalue;
+      value->type = builtin_type (expr->gdbarch)->builtin_int;
+      ax_const_l (expr, n_args);
+      return;
+    }
+
+  gdb_assert (sel >= 0);
+  if (sel >= n_args)
+    error (_("Invalid probe argument %d -- probe has %d arguments available"),
+          sel, n_args);
+
+  pc_probe.probe->pops->compile_to_ax (pc_probe.probe, expr, value, sel);
+}
+
+static const struct internalvar_funcs probe_funcs =
+{
+  compute_probe_arg,
+  compile_probe_arg,
+  NULL
+};
+
+
 VEC (probe_ops_cp) *all_probe_ops;
 
 void _initialize_probe (void);
@@ -835,6 +919,33 @@ _initialize_probe (void)
 {
   VEC_safe_push (probe_ops_cp, all_probe_ops, &probe_ops_any);
 
+  create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
+                               (void *) (uintptr_t) -1);
+  create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
+                               (void *) (uintptr_t) 0);
+  create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
+                               (void *) (uintptr_t) 1);
+  create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
+                               (void *) (uintptr_t) 2);
+  create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
+                               (void *) (uintptr_t) 3);
+  create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
+                               (void *) (uintptr_t) 4);
+  create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
+                               (void *) (uintptr_t) 5);
+  create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
+                               (void *) (uintptr_t) 6);
+  create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
+                               (void *) (uintptr_t) 7);
+  create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
+                               (void *) (uintptr_t) 8);
+  create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
+                               (void *) (uintptr_t) 9);
+  create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
+                               (void *) (uintptr_t) 10);
+  create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
+                               (void *) (uintptr_t) 11);
+
   add_cmd ("all", class_info, info_probes_command,
           _("\
 Show information about all type of probes."),
This page took 0.025416 seconds and 4 git commands to generate.