[DTrace-devel] [PATCH v2 2/9] Remove dangling char in parse-tree dump
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu Dec 21 20:26:19 UTC 2023
From: Eugene Loh <eugene.loh at oracle.com>
The dangling ']' had no matching '['. While we are at it,
introduce a line break in the output to neaten things up and
add some tests for -xtree output.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_parser.c | 9 +--
test/unittest/misc/tst.parser1.sh | 96 ++++++++++++++++++++++++++++
test/unittest/misc/tst.parser2.sh | 100 ++++++++++++++++++++++++++++++
test/unittest/misc/tst.parser4.sh | 100 ++++++++++++++++++++++++++++++
4 files changed, 299 insertions(+), 6 deletions(-)
create mode 100755 test/unittest/misc/tst.parser1.sh
create mode 100755 test/unittest/misc/tst.parser2.sh
create mode 100755 test/unittest/misc/tst.parser4.sh
diff --git a/libdtrace/dt_parser.c b/libdtrace/dt_parser.c
index f6addc78..89545c0b 100644
--- a/libdtrace/dt_parser.c
+++ b/libdtrace/dt_parser.c
@@ -5052,14 +5052,11 @@ dt_node_printr(dt_node_t *dnp, FILE *fp, int depth)
fprintf(fp, "%*s,\n", depth * 2, "");
}
+ fprintf(fp, "%*s]\n", depth * 2, "");
if (dnp->dn_aggfun) {
- fprintf(fp, "%*s] = ", depth * 2, "");
+ fprintf(fp, "%*s=\n", depth * 2, "");
dt_node_printr(dnp->dn_aggfun, fp, depth + 1);
- } else
- fprintf(fp, "%*s]\n", depth * 2, "");
-
- if (dnp->dn_aggfun)
- fprintf(fp, "%*s)\n", depth * 2, "");
+ }
break;
case DT_NODE_PDESC:
diff --git a/test/unittest/misc/tst.parser1.sh b/test/unittest/misc/tst.parser1.sh
new file mode 100755
index 00000000..e25ae8cd
--- /dev/null
+++ b/test/unittest/misc/tst.parser1.sh
@@ -0,0 +1,96 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2023, 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.
+#
+# @@nosort
+
+# Use a shell file rather than .d .r and .r.p files since we do not
+# want to send a large volume of output to the log file in the normal
+# case that the test passes.
+
+dtrace=$1
+tmpfile=$tmpdir/tst.parser1.$$
+chkfile=$tmpfile.check
+
+# Run DTrace.
+
+$dtrace -xtree=1 -e -n '
+BEGIN
+{
+ x = 1234;
+ printf("%d\n", x);
+ z = 32 * (x + 18);
+ @agg[x, z, "hello"] = llquantize(x, 2, 3, 5, 2);
+ exit(0);
+}
+' > $tmpfile 2>&1
+if [ $? -ne 0 ]; then
+ echo ERROR running DTrace
+ cat $tmpfile
+ exit 1
+fi
+
+# Generate check file.
+
+cat > $chkfile << EOF
+ PDESC :::BEGIN [0]
+ CTXATTR [i/i/u]
+ ACTION
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<-1> attr=[s/s/c] flags=0)
+ IDENT x (type=<-1> attr=[s/s/c] flags=0)
+ INT 0x4d2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D PRODUCER attr=[s/s/c]
+ FUNC printf (type=<-1> attr=[s/s/c] flags=0)
+ STRING "%d\n" (type=<string> attr=[s/s/c] flags=COOK,REF,DPTR)
+ ,
+ IDENT x (type=<-1> attr=[s/s/c] flags=0)
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<-1> attr=[s/s/c] flags=0)
+ IDENT z (type=<-1> attr=[s/s/c] flags=0)
+ OP2 * (type=<-1> attr=[s/s/c] flags=0)
+ INT 0x20 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ OP2 + (type=<-1> attr=[s/s/c] flags=0)
+ IDENT x (type=<-1> attr=[s/s/c] flags=0)
+ INT 0x12 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<-1> attr=[s/s/c] flags=0)
+ OP2 [ (type=<-1> attr=[s/s/c] flags=0)
+ IDENT @agg (type=<-1> attr=[s/s/c] flags=0)
+ IDENT x (type=<-1> attr=[s/s/c] flags=0)
+ FUNC llquantize (type=<-1> attr=[s/s/c] flags=0)
+ IDENT x (type=<-1> attr=[s/s/c] flags=0)
+ ,
+ INT 0x2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x3 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x5 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D PRODUCER attr=[s/s/c]
+ FUNC exit (type=<-1> attr=[s/s/c] flags=0)
+ INT 0x0 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+EOF
+
+# Check results.
+
+awk '
+# Look for the BEGIN clause.
+/PDESC :::BEGIN / {
+ # Print until we get the next clause.
+ while (index($0, "Parse tree") == 0) {
+ print;
+ getline;
+ }
+}' $tmpfile | diff -q - $chkfile > /dev/null
+if [ $? -ne 0 ]; then
+ echo ERROR in output
+ cat $tmpfile
+ exit 1
+fi
+
+exit 0
diff --git a/test/unittest/misc/tst.parser2.sh b/test/unittest/misc/tst.parser2.sh
new file mode 100755
index 00000000..e62b0bdf
--- /dev/null
+++ b/test/unittest/misc/tst.parser2.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2023, 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.
+#
+# @@nosort
+
+# Use a shell file rather than .d .r and .r.p files since we do not
+# want to send a large volume of output to the log file in the normal
+# case that the test passes.
+
+dtrace=$1
+tmpfile=$tmpdir/tst.parser2.$$
+chkfile=$tmpfile.check
+
+# Run DTrace.
+
+$dtrace -xtree=2 -e -n '
+BEGIN
+{
+ x = 1234;
+ printf("%d\n", x);
+ z = 32 * (x + 18);
+ @agg[x, z, "hello"] = llquantize(x, 2, 3, 5, 2);
+ exit(0);
+}
+' > $tmpfile 2>&1
+if [ $? -ne 0 ]; then
+ echo ERROR running DTrace
+ cat $tmpfile
+ exit 1
+fi
+
+# Generate check file.
+
+cat > $chkfile << EOF
+ PDESC :::BEGIN [0]
+ CTXATTR [u/u/c]
+ ACTION
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<int> attr=[s/s/c] flags=SIGN,COOK,WRITE)
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ INT 0x4d2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D PRODUCER attr=[s/s/c]
+ FUNC printf (type=<void> attr=[s/s/c] flags=SIGN,COOK)
+ STRING "%d\n" (type=<string> attr=[s/s/c] flags=COOK,REF,DPTR)
+ ,
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<int> attr=[s/s/c] flags=SIGN,COOK,WRITE)
+ VARIABLE (normally-assigned) z (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ OP2 * (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ INT 0x20 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ OP2 + (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ INT 0x12 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D EXPRESSION attr=[s/s/c]
+ AGGREGATE @agg attr=[s/s/c] [
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ ,
+ VARIABLE (normally-assigned) z (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ ,
+ STRING "hello" (type=<string> attr=[s/s/c] flags=COOK,REF,DPTR)
+ ]
+ =
+ FUNC llquantize (type=<<DYN>> attr=[s/s/c] flags=SIGN,COOK,REF)
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ ,
+ INT 0x2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x3 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x5 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D PRODUCER attr=[s/s/c]
+ FUNC exit (type=<void> attr=[s/s/c] flags=SIGN,COOK)
+ INT 0x0 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+EOF
+
+# Check results.
+
+awk '
+# Look for the BEGIN clause.
+/PDESC :::BEGIN / {
+ # Print until we get the next clause.
+ while (index($0, "Parse tree") == 0) {
+ print;
+ getline;
+ }
+}' $tmpfile | diff -q - $chkfile > /dev/null
+if [ $? -ne 0 ]; then
+ echo ERROR in output
+ cat $tmpfile
+ exit 1
+fi
+
+exit 0
diff --git a/test/unittest/misc/tst.parser4.sh b/test/unittest/misc/tst.parser4.sh
new file mode 100755
index 00000000..97a26821
--- /dev/null
+++ b/test/unittest/misc/tst.parser4.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2023, 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.
+#
+# @@nosort
+
+# Use a shell file rather than .d .r and .r.p files since we do not
+# want to send a large volume of output to the log file in the normal
+# case that the test passes.
+
+dtrace=$1
+tmpfile=$tmpdir/tst.parser4.$$
+chkfile=$tmpfile.check
+
+# Run DTrace.
+
+$dtrace -xtree=4 -e -n '
+BEGIN
+{
+ x = 1234;
+ printf("%d\n", x);
+ z = 32 * (x + 18);
+ @agg[x, z, "hello"] = llquantize(x, 2, 3, 5, 2);
+ exit(0);
+}
+' > $tmpfile 2>&1
+if [ $? -ne 0 ]; then
+ echo ERROR running DTrace
+ cat $tmpfile
+ exit 1
+fi
+
+# Generate check file.
+
+cat > $chkfile << EOF
+ PDESC :::BEGIN [0]
+ CTXATTR [u/u/c]
+ ACTION
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<int> attr=[s/s/c] flags=SIGN,COOK,WRITE)
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ INT 0x4d2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D PRODUCER attr=[s/s/c]
+ FUNC printf (type=<void> attr=[s/s/c] flags=SIGN,COOK)
+ STRING "%d\n" (type=<string> attr=[s/s/c] flags=COOK,REF,DPTR)
+ ,
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ D EXPRESSION attr=[s/s/c]
+ OP2 = (type=<int> attr=[s/s/c] flags=SIGN,COOK,WRITE)
+ VARIABLE (normally-assigned) z (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ OP2 * (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ INT 0x20 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ OP2 + (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ INT 0x12 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D EXPRESSION attr=[s/s/c]
+ AGGREGATE @agg attr=[s/s/c] [
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ ,
+ VARIABLE (normally-assigned) z (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ ,
+ STRING "hello" (type=<string> attr=[s/s/c] flags=COOK,REF,DPTR)
+ ]
+ =
+ FUNC llquantize (type=<<DYN>> attr=[s/s/c] flags=SIGN,COOK,REF)
+ VARIABLE (normally-assigned) x (type=<int> attr=[s/s/c] flags=SIGN,COOK,LVAL,WRITE)
+ ,
+ INT 0x2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x3 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x5 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ ,
+ INT 0x2 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+ D PRODUCER attr=[s/s/c]
+ FUNC exit (type=<void> attr=[s/s/c] flags=SIGN,COOK)
+ INT 0x0 (type=<int> attr=[s/s/c] flags=SIGN,COOK)
+EOF
+
+# Check results.
+
+awk '
+# Look for the BEGIN clause.
+/PDESC :::BEGIN / {
+ # Print until we get the next clause.
+ while (index($0, "Parse tree") == 0) {
+ print;
+ getline;
+ }
+}' $tmpfile | diff -q - $chkfile > /dev/null
+if [ $? -ne 0 ]; then
+ echo ERROR in output
+ cat $tmpfile
+ exit 1
+fi
+
+exit 0
--
2.18.4
More information about the DTrace-devel
mailing list