Dtrace fasttrap function call usage

I have been doing some modification work on a/the fasttrap provider in DTrace. I have made some modifications to make it work for a/the function usage list. For example dtrace -n 'pid$target:test::return{@func[probefunc]=count();}' -c ./test, will list all functions with the number of times each function is called. Also if a function had more than one return path DTrace would give a Pread() Fail error and the probe for the function would fail.

The attached patches solved the problem for me.
 

Attachments

Dtrace PID Provider

When using Dtrace PID provider with entry probe or the offset probe on a program using TLS, dtrace would hang in tls_get_addr_common function.If you use scanf or fscanf in your program you can notice this behaviour. This I believe is due to dtrace using gs segment register to point to the scratch space, and TLS also loading the thread variable from gs register.

If you change the following code in fasttrap_isa.c

Code:
#ifdef __i386__
        addr = USD_GETBASE(&curthread->td_pcb->pcb_gsd);
#else
        addr = curthread->td_pcb->pcb_gsbase;
#endif
        addr += sizeof (void *);
to

Code:
#ifdef __i386__
        addr = USD_GETBASE(&curthread->td_pcb->pcb_gsd);
#else
        addr = curthread->td_pcb->pcb_gsbase;
#endif
        addr += sizeof (void *) * 3;
the dtrace will not hang. I am not sure what is happening here and whether this is the correct solution.

Note: These changes were made on FreeBSD 9.2-RELEASE i386
 
Back
Top