clause-local variable with copyin()

Domagoj Stolfa domagoj.stolfa at gmail.com
Sat Dec 17 18:48:59 UTC 2016


Hello,

>  I have trouble with clause-local variable.  A minimum working example
>  is attached.  The "sample" program simply displays a string in an
>  infinite loop with a USDT named as "dump-str", sample_debug.d does
>  copyin() and printf() the whole buffer assuming it is
>  nul-terminated:
> 
>  | sample$target:::dump-str
>  | {
>  |         this->st = copyin(arg0, 1024);
>  |
>  |         printf("(1)st = %s, %p\n", stringof(this->st),
>  |             (char *)this->st);
>  | }
>  | sample$target:::dump-str
>  | {
>  |         printf("(2)st = %s, %p\n", stringof(this->st),
>  |             (char *)this->st);
>  |         printf("(3)st = %s\n", stringof(copyin(arg0, 1024)));
>  | }
> 
>  The odd part is that it does not work with splitting the probe into
>  the two as above but works fine without the split.  The result was as
>  follows:
> 
>  |  % sudo make test
>  | dtrace -C -I/var/home/hrs/sample_str -s sample_debug.d -c /var/home/hrs/sample_str/sample
>  | dtrace: script 'sample_debug.d' matched 5 probes
>  | CPU     ID                    FUNCTION:NAME
>  |   0  61714                    main:dump-str (1)st = test-uname, fffffe0001a19118
>  |
>  |   0  61714                    main:dump-str (2)st = , fffffe0001a19118
>  | (3)st = test-uname
> 
>  this->st became empty at the beginning of the second probe.
> 
>  The symptom varied depending on the address of this->st, so I am
>  guessing that this->st was incorrectly freed at the end of the first
>  probe.  If I use copyinstr(arg0) instead of copyin(), this problem
>  does not occur.

That does seem like what's happening based on the described behaviour
and running the examples you've provided.

>  Do I misunderstand clause-local variable?  I noticed this when I use
>  if-then clause which was recently implemented as a syntax sugar to
>  split a probe automatically.  The following ended up with the same
>  result:
> 
>  | sample$target:::dump-str
>  | {
>  |         this->st = copyin(arg0, 1024);
>  |
>  |         printf("(1)st = %s, %p\n", stringof(this->st),
>  |             (char *)this->st);
>  |         if (0) {
>  |         }
>  |         printf("(2)st = %s, %p\n", stringof(this->st),
>  |             (char *)this->st);
>  |         printf("(3)st = %s\n", stringof(copyin(arg0, 1024)));
>  | }

No, the clause-local variables should remain intact eventhough the probe
is split up into two clauses. See [1] for an example. This is
reproducible on FreeBSD 12.0-CURRENT and seems like a bug.

[1] http://dtrace.org/guide/chp-variables.html#chp-variables-4

-- 
Best regards,
Domagoj Stolfa.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-dtrace/attachments/20161217/450196f6/attachment.sig>


More information about the freebsd-dtrace mailing list