[DTrace-devel] [PATCH 05/15] cg: support save/restore of probe arguments
Kris Van Hees
kris.van.hees at oracle.com
Thu Feb 23 07:23:55 UTC 2023
With the upcoming introduction of dependent probes (probes that use
another underlying probe as trigger), we need to be able to save the
probe arguments for the underlying probe so that the arguments can be
modified in preparation for execution the clauses of the dependent
probe. After all such clauses have been executed, the probe arguments
need to be restored in case there is another dependent probe (with
possibly different arguments).
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
libdtrace/dt_cg.c | 30 ++++++++++++++++++++++++++++++
libdtrace/dt_cg.h | 2 ++
libdtrace/dt_dctx.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 67e691ca..f1d05d6c 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -422,6 +422,36 @@ dt_cg_tramp_copy_rval_from_regs(dt_pcb_t *pcb)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_ARG(i), 0));
}
+/*
+ * Save the probe arguments.
+ */
+void
+dt_cg_tramp_save_args(dt_pcb_t *pcb)
+{
+ dt_irlist_t *dlp = &pcb->pcb_ir;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(((dt_mstate_t *)0)->argv); i++) {
+ emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_7, DMST_ARG(i)));
+ emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_SAVED_ARG(i), BPF_REG_0));
+ }
+}
+
+/*
+ * Restore the saved probe arguments.
+ */
+void
+dt_cg_tramp_restore_args(dt_pcb_t *pcb)
+{
+ dt_irlist_t *dlp = &pcb->pcb_ir;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(((dt_mstate_t *)0)->argv); i++) {
+ emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_7, DMST_SAVED_ARG(i)));
+ emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_ARG(i), BPF_REG_0));
+ }
+}
+
typedef struct {
dt_irlist_t *dlp;
dt_activity_t act;
diff --git a/libdtrace/dt_cg.h b/libdtrace/dt_cg.h
index 3742bc6a..179fa103 100644
--- a/libdtrace/dt_cg.h
+++ b/libdtrace/dt_cg.h
@@ -26,6 +26,8 @@ extern void dt_cg_tramp_clear_regs(dt_pcb_t *pcb);
extern void dt_cg_tramp_copy_regs(dt_pcb_t *pcb);
extern void dt_cg_tramp_copy_args_from_regs(dt_pcb_t *pcb, int called);
extern void dt_cg_tramp_copy_rval_from_regs(dt_pcb_t *pcb);
+extern void dt_cg_tramp_save_args(dt_pcb_t *pcb);
+extern void dt_cg_tramp_restore_args(dt_pcb_t *pcb);
extern void dt_cg_tramp_call_clauses(dt_pcb_t *pcb, const dt_probe_t *prp,
dt_activity_t act);
extern void dt_cg_tramp_return(dt_pcb_t *pcb);
diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
index c93fff2b..dcf111fb 100644
--- a/libdtrace/dt_dctx.h
+++ b/libdtrace/dt_dctx.h
@@ -29,6 +29,7 @@ typedef struct dt_mstate {
uint64_t tstamp; /* cached timestamp value */
dt_pt_regs regs; /* CPU registers */
uint64_t argv[10]; /* Probe arguments */
+ uint64_t saved_argv[10]; /* Saved probe arguments */
} dt_mstate_t;
#define DMST_EPID offsetof(dt_mstate_t, epid)
@@ -42,6 +43,7 @@ typedef struct dt_mstate {
#define DMST_TSTAMP offsetof(dt_mstate_t, tstamp)
#define DMST_REGS offsetof(dt_mstate_t, regs)
#define DMST_ARG(n) offsetof(dt_mstate_t, argv[n])
+#define DMST_SAVED_ARG(n) offsetof(dt_mstate_t, saved_argv[n])
/*
* The DTrace context.
--
2.39.1
More information about the DTrace-devel
mailing list