[DTrace-devel] [PATCH v2 20/20] Support probeprov, probemod, probefunc, probename built-in variables

Eugene Loh eugene.loh at oracle.com
Sat Jun 5 20:09:33 PDT 2021


I haven't gotten to this patch yet, but I had a question that I think is 
related to it -- specifically to the CG stuff that writes a string to 
the output buffer.  Why does it include the varint prefix?  E.g., consider:

dtrace -qn 'BEGIN {trace("the"                                         
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick"                                   
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown"                             
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown fox"                         
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown fox jumped"                  
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown fox jumped over"             
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown fox jumped over the"         
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown fox jumped over the lazy"    
); exit(0)}'
dtrace -qn 'BEGIN {trace("the quick brown fox jumped over the lazy 
dog"); exit(0)}'

One gets at least a "non-printable" prefix, but (depending on what's 
there) a bunch of, er, output.  :^)

Maybe you want something like (modulo cut-and-paste ugliness and other 
sloppiness):

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 9d671071..386ab244 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -775,22 +775,20 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, 
dtrace_actkind_t kind,
                 dt_regset_xalloc(drp, BPF_REG_0);
                 emite(dlp,  BPF_CALL_FUNC(idp->di_id), idp);

-               /* Add length of the string (adjusted for terminating 
byte). */
-               emit(dlp,   BPF_ALU64_IMM(BPF_ADD, reg, 1));
-               emit(dlp,   BPF_ALU64_REG(BPF_ADD, BPF_REG_0, reg));
-               dt_regset_free(drp, reg);
-
                 /*
-                * Copy string data (varint length + string content) to the
-                * output buffer at [%r9 + off].  The amount of bytes 
copied is
-                * the lesser of the data size and the maximum string size.
+                * Copy string data (string pointer offset by varint 
length) to
+                * the output buffer at [%r9 + off].  The amount of 
bytes copied
+                * is the lesser of the data size (including terminating 
byte)
+                * and the maximum string size.
                  */
                 emit(dlp,   BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
                 emit(dlp,   BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
                 emit(dlp,   BPF_MOV_REG(BPF_REG_2, dnp->dn_reg));
                 dt_regset_free(drp, dnp->dn_reg);
-               emit(dlp,   BPF_MOV_REG(BPF_REG_3, BPF_REG_0));
+               emit(dlp,   BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_0));
                 dt_regset_free(drp, BPF_REG_0);
+               emit(dlp,   BPF_MOV_REG(BPF_REG_3, reg));
+               emit(dlp,   BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, 1));
                 emit(dlp,   BPF_BRANCH_IMM(BPF_JLT, BPF_REG_3, size, 
vcopy));
                 emit(dlp,   BPF_MOV_IMM(BPF_REG_3, size));
                 idp = dt_dlib_get_func(yypcb->pcb_hdl, "dt_memcpy");

That's relative to your patch, not to what was there before.

Oh, and one needs tests to catch this sort of thing.

And capitalization issue in the commit msg:

On 6/3/21 11:21 AM, Kris Van Hees wrote:

> THis patch adds support for the built-in variables that provide the
> component names for the probe description of the current probe in a
> D clause, i.e. the probe that triggered the execution of the clause.


More information about the DTrace-devel mailing list