[DTrace-devel] [PATCH 58/61] Make sure disassembly distinguishes between gvars and agg vars

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


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

When the disassembler recognizes access of a variable by value,
it looks up a variable name that matches the offset and scope.
The scope of aggregation variables is also "global", however,
and so the presence of aggregations can lead to incorrect
disassembly of global variables.

Check the variable "kind" when looking up variables accessed
by value.

When the disassembler recognizes aggregation names, a similar
test for them can be introduced.

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

diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
index 58c02fd5..98fcd20e 100644
--- a/libdtrace/dt_dis.c
+++ b/libdtrace/dt_dis.c
@@ -71,6 +71,7 @@ dt_dis_varname_off(const dtrace_difo_t *dp, uint_t off, uint_t scope, uint_t add
 	for (i = 0; i < dp->dtdo_varlen; i++) {
 		const dtrace_difv_t *dvp = &dp->dtdo_vartab[i];
 		if (dvp->dtdv_offset == off && dvp->dtdv_scope == scope &&
+		    dvp->dtdv_kind != DIFV_KIND_AGGREGATE &&
 		    dvp->dtdv_insn_from <= addr && addr <= dvp->dtdv_insn_to) {
 			if (dvp->dtdv_name < dp->dtdo_strlen)
 				return dt_difo_getstr(dp, dvp->dtdv_name);
diff --git a/test/unittest/disasm/tst.ann-gvar-agg.r b/test/unittest/disasm/tst.ann-gvar-agg.r
new file mode 100644
index 00000000..41cafcd0
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-gvar-agg.r
@@ -0,0 +1 @@
+myvar_global
diff --git a/test/unittest/disasm/tst.ann-gvar-agg.sh b/test/unittest/disasm/tst.ann-gvar-agg.sh
new file mode 100755
index 00000000..81f1c511
--- /dev/null
+++ b/test/unittest/disasm/tst.ann-gvar-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
+
+# Test that annotation of gvars is not confused by agg vars.
+
+$dtrace $dt_flags -Sen '
+BEGIN
+{
+	@myvar_agg = count();
+	myvar_global = 0xdeadbeef;
+	exit(0);
+}
+' 2>&1 | grep -A4 deadbeef | awk '/myvar_/ {print $NF}'
+
+exit $?
-- 
2.18.4




More information about the DTrace-devel mailing list