[DTrace-devel] printf() with no "action" is not printed

Kris Van Hees kris.van.hees at oracle.com
Thu Jun 18 17:59:44 PDT 2020


On Thu, Jun 18, 2020 at 04:51:06PM -0700, Eugene Loh wrote:
> Consider
> 
>          # dtrace -n 'BEGIN
>          {
>              printf("Hello world.\n");
>              printf("Hello world. %d\n", 0);
>              exit(0);
>          }'
> 
> The first printf() is not printed.  The second one is.
> 
> I think the problem is that user space prints output based on "records" 
> that are formed during BPF code generation, but the first printf() 
> doesn't need any BPF code and therefore has no "record."  (The second 
> printf -- suboptimally but fortuitously -- currently needs BPF generated 
> so that the kernel will write a 0 back to user space.)
> 
> I'll look at a fix tomorrow, but if someone can guide me to the fix 
> that'd be helpful.  I'm not familiar with this part of the code.  I'm 
> okay poking around -- should be a good learning experience -- but it 
> might be a lot faster if I had hints.

Oh, nice catch.  Yes, indeed, when there is only the constant format string,
we do not have a record and therefore we never provide output because there
isn't anything to trigger it.

Fix is trivial - let me add a test or two and I'll post a patch.  (Fixing it
took less time than writing this email.)  Take a look at the patch once it
lands in your email and you will see why.



More information about the DTrace-devel mailing list