Skip to content

Commit

Permalink
Fix the -xverbose option
Browse files Browse the repository at this point in the history
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.

Note that -xdisasm=N does not modify the -xverbose behaviour because the
-xverbose option is specifically defined to providw clause disassembly
(equivalent with -S without -xdisasm=N being specified).

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@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Jul 28, 2022
1 parent c8715f7 commit 380e08c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
50 changes: 26 additions & 24 deletions libdtrace/dt_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -2695,14 +2688,23 @@ dt_program_construct(dtrace_hdl_t *dtp, dt_probe_t *prp, uint_t cflags,
return dp;
}

dtrace_prog_t *
dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[])
static dtrace_prog_t *
dt_program_compile(dtrace_hdl_t *dtp, dtrace_probespec_t spec, uint_t cflags,
int argc, char *const argv[], FILE *fp, const char *s)
{
dtrace_prog_t *rv;
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);
rv = dt_compile(dtp, DT_CTX_DPROG, spec, NULL, cflags, argc, argv, fp,
s);
if (rv == NULL)
return NULL;

Expand All @@ -2712,19 +2714,19 @@ dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
}

dtrace_prog_t *
dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp,
uint_t cflags, int argc, char *const argv[])
dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s,
dtrace_probespec_t spec, uint_t cflags,
int argc, char *const argv[])
{
dtrace_prog_t *rv;

rv = dt_compile(dtp, DT_CTX_DPROG, DTRACE_PROBESPEC_NAME, NULL, cflags,
argc, argv, fp, NULL);
if (rv == NULL)
return NULL;

DT_DISASM_CLAUSE(dtp, cflags, rv, stderr);
return dt_program_compile(dtp, spec, cflags, argc, argv, NULL, s);
}

return rv;
dtrace_prog_t *
dtrace_program_fcompile(dtrace_hdl_t *dtp, FILE *fp, uint_t cflags,
int argc, char *const argv[])
{
return dt_program_compile(dtp, DTRACE_PROBESPEC_NAME, cflags,
argc, argv, fp, NULL);
}

int
Expand Down
19 changes: 19 additions & 0 deletions test/unittest/options/tst.S.sh
Original file line number Diff line number Diff line change
@@ -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 $?
19 changes: 19 additions & 0 deletions test/unittest/options/tst.verbose.sh
Original file line number Diff line number Diff line change
@@ -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 $?

0 comments on commit 380e08c

Please sign in to comment.