Skip to content

Commit

Permalink
Remove dangling char in parse-tree dump
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Jan 26, 2024
1 parent 65c7605 commit 46931ca
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 6 deletions.
9 changes: 3 additions & 6 deletions libdtrace/dt_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5062,14 +5062,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:
Expand Down
96 changes: 96 additions & 0 deletions test/unittest/misc/tst.parser1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2024, 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
100 changes: 100 additions & 0 deletions test/unittest/misc/tst.parser2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2024, 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
100 changes: 100 additions & 0 deletions test/unittest/misc/tst.parser4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2024, 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

0 comments on commit 46931ca

Please sign in to comment.