[DTrace-devel] [PATCH 59/61] Add disassembly for aggregation variables

eugene.loh at oracle.com eugene.loh at oracle.com
Fri Jul 8 14:45:43 UTC 2022


From: Eugene Loh <eugene.loh at oracle.com>

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 libdtrace/dt_dis.c                  | 19 +++++++++++++++++++
 test/unittest/disasm/tst.ann-agg.r  |  3 +++
 test/unittest/disasm/tst.ann-agg.sh | 22 ++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 test/unittest/disasm/tst.ann-agg.r
 create mode 100755 test/unittest/disasm/tst.ann-agg.sh

diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
index 98fcd20e..8af6a246 100644
--- a/libdtrace/dt_dis.c
+++ b/libdtrace/dt_dis.c
@@ -355,6 +355,25 @@ dt_dis_bpf_args(const dtrace_difo_t *dp, const char *fn,
 		snprintf(buf, len, "%s",
 			 dt_dis_varname_id(dp, in->imm, DIFV_SCOPE_GLOBAL, addr));
 		return buf;
+	} else if (strcmp(fn, "dt_get_agg") == 0) {
+		/*
+		 * If the immediately preceding instruction is a 16-byte
+		 * instruction, back up to streamline instruction counting.
+		 */
+		if (in[-2].code == (BPF_LD | BPF_DW | BPF_IMM) &&
+		    in[-1].code == 0)
+			in--;
+
+		/*
+		 * We know that the previous six instructions exist and
+		 * move the variable id to a register in the first instruction
+		 * of that seqeuence (because we wrote the code generator to
+		 * emit the instructions in this exact order.)
+		 */
+		in -= 6;
+		snprintf(buf, len, "@%s",
+			 dt_dis_varname_id(dp, in->imm, DIFV_SCOPE_GLOBAL, addr));
+		return buf;
 	} else if (strcmp(fn, "dt_get_tvar") == 0) {
 		/*
 		 * We know that the previous three instructions exist and
diff --git a/test/unittest/disasm/tst.ann-agg.r b/test/unittest/disasm/tst.ann-agg.r
new file mode 100644
index 00000000..c14f6464
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-agg.r
@@ -0,0 +1,3 @@
+85 0 1 0000 ffffffff    call dt_get_agg               ! @myvar_agg
+85 0 1 0000 ffffffff    call dt_get_agg               ! @myvar_agg_3keys
+85 0 1 0000 ffffffff    call dt_get_agg               ! @myvar_agg_min
diff --git a/test/unittest/disasm/tst.ann-agg.sh b/test/unittest/disasm/tst.ann-agg.sh
new file mode 100755
index 00000000..3f8e74a4
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-agg.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# 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.
+#
+
+dtrace=$1
+
+$dtrace $dt_flags -Sen '
+BEGIN
+{
+	myvar_global = 0xdeadbeef;
+	@myvar_agg = quantize(myvar_global);
+	@myvar_agg_3keys[1, 2, "hi"] = sum(myvar_global);
+	@myvar_agg_min = min(myvar_global);
+	exit(0);
+}
+' 2>&1 | awk '/ call dt_get_agg/ { sub(/^[^:]+: /, ""); print; }'
+
+exit $?
-- 
2.18.4




More information about the DTrace-devel mailing list