[DTrace-devel] [PATCH] Add support for array/struct/union to trace()

Kris Van Hees kris.van.hees at oracle.com
Wed Jan 26 16:26:19 UTC 2022


Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cg.c                        | 28 +++++++++++++++++++++++-
 test/unittest/actions/trace/tst.array.d  | 18 +++++++++++++++
 test/unittest/actions/trace/tst.struct.d | 27 +++++++++++++++++++++++
 test/unittest/actions/trace/tst.union.d  | 25 +++++++++++++++++++++
 4 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/actions/trace/tst.array.d
 create mode 100644 test/unittest/actions/trace/tst.struct.d
 create mode 100644 test/unittest/actions/trace/tst.union.d

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index c8421109..e233e757 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -1002,6 +1002,32 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		return 0;
 	}
 
+	/* Handle tracing of by-ref values (arrays, struct, union). */
+	if (kind == DTRACEACT_DIFEXPR && (arg & DT_NF_REF)) {
+		off = dt_rec_add(dtp, dt_cg_fill_gap, kind,
+				 size, size, pfp, arg);
+
+		TRACE_REGSET("store_val(): Begin ");
+		dt_cg_check_notnull(dlp, drp, dnp->dn_reg);
+
+		if (dt_regset_xalloc_args(drp) == -1)
+			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
+
+		emit(dlp, BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
+		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
+		emit(dlp, BPF_MOV_IMM(BPF_REG_2, size));
+		emit(dlp, BPF_MOV_REG(BPF_REG_3, dnp->dn_reg));
+		dt_regset_free(drp, dnp->dn_reg);
+		dt_regset_xalloc(drp, BPF_REG_0);
+		emit(dlp, BPF_CALL_HELPER(BPF_FUNC_probe_read));
+		dt_regset_free_args(drp);
+
+		dt_regset_free(drp, BPF_REG_0);
+		TRACE_REGSET("store_val(): End   ");
+
+		return 0;
+	}
+
 	return -1;
 }
 
diff --git a/test/unittest/actions/trace/tst.array.d b/test/unittest/actions/trace/tst.array.d
new file mode 100644
index 00000000..104d42e1
--- /dev/null
+++ b/test/unittest/actions/trace/tst.array.d
@@ -0,0 +1,18 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The trace() action prints an array correctly.
+ *
+ * SECTION: Actions and Subroutines/trace()
+ */
+
+BEGIN
+{
+	trace(curthread->comm);
+	exit(0);
+}
diff --git a/test/unittest/actions/trace/tst.struct.d b/test/unittest/actions/trace/tst.struct.d
new file mode 100644
index 00000000..ec60ea11
--- /dev/null
+++ b/test/unittest/actions/trace/tst.struct.d
@@ -0,0 +1,27 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The trace() action prints a struct correctly.
+ *
+ * SECTION: Actions and Subroutines/trace()
+ */
+
+struct {
+	int	a;
+	char	b;
+	int	c;
+} st;
+
+BEGIN
+{
+	st.a = 0x1234;
+	st.b = 0;
+	st.c = 0x9876;
+	trace(st);
+	exit(0);
+}
diff --git a/test/unittest/actions/trace/tst.union.d b/test/unittest/actions/trace/tst.union.d
new file mode 100644
index 00000000..b9d107d3
--- /dev/null
+++ b/test/unittest/actions/trace/tst.union.d
@@ -0,0 +1,25 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The trace() action prints a union correctly.
+ *
+ * SECTION: Actions and Subroutines/trace()
+ */
+
+union {
+	int	a;
+	char	b[3];
+	short	c;
+} u;
+
+BEGIN
+{
+	u.a = 0x12345678;
+	trace(u.b);
+	exit(0);
+}
-- 
2.34.1




More information about the DTrace-devel mailing list