[DTrace-devel] [PATCH 06/12] Fix the -xverbose option

Kris Van Hees kris.van.hees at oracle.com
Wed Jul 13 19:17:47 UTC 2022


The -xverbose option should be equivalent to the -S option.  The
-xverbose option sets DTRACE_C_DIFV in the dt_cflags, but the compiler
only ever checked the cflags passed from the command line program for
the DTRACE_C_DIFV flag.  As a result, only -S had the intended
behaviour whereas -xverbose was essentially ignored.

When a D script is compiled that is not a library script or the builtin
ERROR probe, and the DTRACE_C_DIFV flag is set in dt_cflags, it is also
set in the cflags used by the compiler.

The support for -xcpp is also updated with this patch to set DTRACE_C_CPP
under the same circumstances.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cc.c                    | 25 ++++++++++++++++++-------
 test/unittest/options/tst.S.sh       | 19 +++++++++++++++++++
 test/unittest/options/tst.verbose.sh | 19 +++++++++++++++++++
 3 files changed, 56 insertions(+), 7 deletions(-)
 create mode 100755 test/unittest/options/tst.S.sh
 create mode 100755 test/unittest/options/tst.verbose.sh

diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index 1383aec0..5064d599 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -1930,13 +1930,6 @@ dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg,
 	dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL);
 	dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL);
 
-	/*
-	 * If the 'cpp' option was passed, treat it as equivalent to '-C',
-	 * unless a D library is being compiled.
-	 */
-	if (!(cflags & DTRACE_C_DLIB))
-		cflags |= dtp->dt_cflags & DTRACE_C_CPP;
-
 	if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL)
 		return NULL; /* errno is set for us */
 
@@ -2687,6 +2680,15 @@ dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
 {
 	dtrace_prog_t *rv;
 
+	/*
+	 * If the 'cpp' option was passed, treat it as equivalent to '-C',
+	 * unless a D library is being compiled or the default ERROR probe.
+	 * If the 'verbose' option was passed, treat it as equivalent to '-S',
+	 * unless a D library is being compiled or the default ERROR probe.
+	 */
+	if (!(cflags & (DTRACE_C_DLIB | DTRACE_C_EPROBE)))
+		cflags |= dtp->dt_cflags & (DTRACE_C_CPP | DTRACE_C_DIFV);
+
 	rv = dt_compile(dtp, DT_CTX_DPROG, spec, NULL, cflags,
 			argc, argv, NULL, s);
 	if (rv == NULL)
@@ -2703,6 +2705,15 @@ dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp,
 {
 	dtrace_prog_t *rv;
 
+	/*
+	 * If the 'cpp' option was passed, treat it as equivalent to '-C',
+	 * unless a D library is being compiled or the default ERROR probe.
+	 * If the 'verbose' option was passed, treat it as equivalent to '-S',
+	 * unless a D library is being compiled or the default ERROR probe.
+	 */
+	if (!(cflags & (DTRACE_C_DLIB | DTRACE_C_EPROBE)))
+		cflags |= dtp->dt_cflags & (DTRACE_C_CPP | DTRACE_C_DIFV);
+
 	rv = dt_compile(dtp, DT_CTX_DPROG, DTRACE_PROBESPEC_NAME, NULL, cflags,
 			argc, argv, fp, NULL);
 	if (rv == NULL)
diff --git a/test/unittest/options/tst.S.sh b/test/unittest/options/tst.S.sh
new file mode 100755
index 00000000..3d5e057d
--- /dev/null
+++ b/test/unittest/options/tst.S.sh
@@ -0,0 +1,19 @@
+#!/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 -S -n 'BEGIN { exit(0); }' 2>&1 | \
+	awk '{ print; }
+	     /^Disassembly of clause :::BEGIN/ { hdr = 1; next; }
+	     /^[0-9]{4} [0-9]{5}: [0-9a-f]{2} / { ins++; next; }
+	     END {
+		exit(hdr && ins > 20 ? 0 : 1);
+	     }'
+
+exit $?
diff --git a/test/unittest/options/tst.verbose.sh b/test/unittest/options/tst.verbose.sh
new file mode 100755
index 00000000..b9e1bdef
--- /dev/null
+++ b/test/unittest/options/tst.verbose.sh
@@ -0,0 +1,19 @@
+#!/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 -xverbose -n 'BEGIN { exit(0); }' 2>&1 | \
+	awk '{ print; }
+	     /^Disassembly of clause :::BEGIN/ { hdr = 1; next; }
+	     /^[0-9]{4} [0-9]{5}: [0-9a-f]{2} / { ins++; next; }
+	     END {
+		exit(hdr && ins > 20 ? 0 : 1);
+	     }'
+
+exit $?
-- 
2.34.1




More information about the DTrace-devel mailing list