[DTrace-devel] [PATCH 6/6 v3] Add disassembler annotations for assoc arrays

Kris Van Hees kris.van.hees at oracle.com
Thu Mar 10 05:55:28 UTC 2022


Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_dis.c                         | 29 ++++++++++++++++++++++
 test/unittest/disasm/tst.ann-gvar-assoc.r  |  2 ++
 test/unittest/disasm/tst.ann-gvar-assoc.sh | 22 ++++++++++++++++
 test/unittest/disasm/tst.ann-tvar-assoc.r  |  2 ++
 test/unittest/disasm/tst.ann-tvar-assoc.sh | 22 ++++++++++++++++
 5 files changed, 77 insertions(+)
 create mode 100644 test/unittest/disasm/tst.ann-gvar-assoc.r
 create mode 100755 test/unittest/disasm/tst.ann-gvar-assoc.sh
 create mode 100644 test/unittest/disasm/tst.ann-tvar-assoc.r
 create mode 100755 test/unittest/disasm/tst.ann-tvar-assoc.sh

diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
index d911dbf5..93e83296 100644
--- a/libdtrace/dt_dis.c
+++ b/libdtrace/dt_dis.c
@@ -337,6 +337,35 @@ dt_dis_bpf_args(const dtrace_difo_t *dp, const char *fn,
 			 dt_dis_varname_id(dp, in->imm + DIF_VAR_OTHER_UBASE,
 					DIFV_SCOPE_THREAD, addr));
 		return buf;
+	} else if (strcmp(fn, "dt_get_assoc") == 0) {
+		uint_t		varid;
+
+		/*
+		 * We know that the previous four 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 -= 4;
+		varid = in->imm + DIF_VAR_OTHER_UBASE;
+
+		/*
+		 * Four instructions prior to this there will be a STORE (TLS
+		 * associative array) or a STORE_IMM (global associative array).
+		 */
+		in -= 4;
+		if (in->code == (BPF_STX | BPF_MEM | BPF_DW))
+			snprintf(buf, len, "self->%s[]",
+				 dt_dis_varname_id(dp, varid, DIFV_SCOPE_THREAD,
+						   addr));
+		else if (in->code == (BPF_ST | BPF_MEM | BPF_DW))
+			snprintf(buf, len, "%s[]",
+				 dt_dis_varname_id(dp, varid, DIFV_SCOPE_GLOBAL,
+						   addr));
+		else
+			snprintf(buf, len, "???[]");
+
+		return buf;
 	}
 
 	return NULL;
diff --git a/test/unittest/disasm/tst.ann-gvar-assoc.r b/test/unittest/disasm/tst.ann-gvar-assoc.r
new file mode 100644
index 00000000..f7563a51
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-gvar-assoc.r
@@ -0,0 +1,2 @@
+85 0 1 0000 ffffffff    call dt_get_assoc             ! st[]
+85 0 1 0000 ffffffff    call dt_get_assoc             ! ld[]
diff --git a/test/unittest/disasm/tst.ann-gvar-assoc.sh b/test/unittest/disasm/tst.ann-gvar-assoc.sh
new file mode 100755
index 00000000..6690967d
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-gvar-assoc.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 '
+int st[int], ld[int];
+
+BEGIN
+{
+	st[2] = 42;
+	trace(ld[5]);
+	exit(0);
+}
+' 2>&1 | awk '/ call dt_get_assoc/ { sub(/^[^:]+: /, ""); print; }'
+
+exit $?
diff --git a/test/unittest/disasm/tst.ann-tvar-assoc.r b/test/unittest/disasm/tst.ann-tvar-assoc.r
new file mode 100644
index 00000000..573c93e2
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-tvar-assoc.r
@@ -0,0 +1,2 @@
+85 0 1 0000 ffffffff    call dt_get_assoc             ! self->st[]
+85 0 1 0000 ffffffff    call dt_get_assoc             ! self->ld[]
diff --git a/test/unittest/disasm/tst.ann-tvar-assoc.sh b/test/unittest/disasm/tst.ann-tvar-assoc.sh
new file mode 100755
index 00000000..354d8fbe
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-tvar-assoc.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 '
+self int st[int], ld[int];
+
+BEGIN
+{
+	self->st[2] = 42;
+	trace(self->ld[5]);
+	exit(0);
+}
+' 2>&1 | awk '/ call dt_get_assoc/ { sub(/^[^:]+: /, ""); print; }'
+
+exit $?
-- 
2.34.1




More information about the DTrace-devel mailing list