When applications using USDT are compiled with -x lazyload, dtrace(1)
will not link drti.o into the generated object file. As a result, probes
are not registered automatically when the application starts; when
dtrace(1) attaches to a process running this application, it will
discover any DOF sections and register them on the process' behalf. This
reduces startup cost and kernel memory consumption for applications that
use USDT, which is important for USDT providers in commonly-used libraries,
such as libthr (for the plockstat provider).
libdtrace relies on some libproc interfaces to open files and register
DOF in the context of the target process. FreeBSD doesn't have interfaces
to support this, so we instead add a pid field to dof_helper_t. The ioctl
handler then verifies that DOF registration is either done by the process
itself (via drti.o, typically), or by a process that is ptracing the
target process (dtrace(1), typically).
Some light refactoring is needed to support DOF registration by one
process on behalf of another. I avoided adding #ifdefs for this since it
gets messy, and because the changes could be adopted upstream.