[DTrace-devel] setting options in g_cflags, dt_cflags, pcb_cflags

Eugene Loh eugene.loh at oracle.com
Fri Aug 14 12:33:27 PDT 2020


I think there is a rat's nest here, but it seems there is a mess in 
options handling, basically inherited from DTv1.

Let's start with this demonstration from DTv1:

     % cat u2.d
     #define mybegin BEGIN
     mybegin { exit(0) }

     % sudo /usr/sbin/dtrace -s u2.d
     dtrace: failed to compile script u2.d: line 1: invalid control 
directive: #define

Oops.  Oh yeah, right.  Need -C:

     % sudo /usr/sbin/dtrace -C -s u2.d
     dtrace: script 'u2.d' matched 1 probe
     CPU     ID                    FUNCTION:NAME
       2      1                           :BEGIN

Great.  The documentation seems to say that "-x cpp" should be equally good:

     % sudo /usr/sbin/dtrace -x cpp -s u2.d
     dtrace: failed to compile script u2.d: line 1: invalid control 
directive: #define

Wait, what's wrong?  Apparently, -C sets DTRACE_C_CPP in dtrace.c's 
g_cflags variable, and that is what is checked to decide whether to 
invoke the preprocessor.  In contrast, in dt_opt_cflags(), "-x cpp" sets 
pcb_cflags or dt_cflags.  That setting is never checked.

And, preprocessing is not the only victim of the complicated logic 
behind the various places we manage options -- e.g., g_cflags, 
pcb_cflags, and dt_cflags -- but I thought it made sense to start with a 
concrete example.

Oh yeah, we don't test "-x cpp":

     $ git grep -w cpp test/
     test/unittest/misc/tst.enablerace.sh:   # satisfy the ancient cpp 
that -C defaults to.

Anyhow, I can try proposing a patch, but I thought I'd check in for 
comments before putting one together.

PS  Also, -C only works with files, not with command-line programs.  E.g.,

     % sudo /usr/sbin/dtrace -C -n '
     #define mybegin BEGIN
     mybegin { exit(0) }
     '
     dtrace: invalid probe specifier
     #define mybegin BEGIN
     mybegin { exit(0) }
     : invalid control directive: #define

I guess maybe that's implied by the docs?  Not obvious.  Probably hard 
to fix, given how we hand this stuff off to the preprocessor.




More information about the DTrace-devel mailing list