Re: USDT support (in build framework)?
- In reply to: Domagoj Stolfa : "Re: USDT support (in build framework)?"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 23 Mar 2023 14:25:47 UTC
On Thu, Mar 23, 2023 at 11:58:07AM +0000, Domagoj Stolfa wrote: > Hi: > > > I've done this for bhyve, specifically for virtio-net. I believe this is > the whole patch I needed: > > > +OBJS:=bhyve_provider.o ${OBJS} > +DTRACE_OBJS=${SRCS:C/\.c/.o/} > + > +beforelinking: > + dtrace -G -s ${BHYVE_SRCDIR}/bhyve_provider.d ${DTRACE_OBJS} > + > > > however, it has been a while and I don't 100% recall if anything else > was necessary. I had to create a helper DTRACE_OBJS because using OBJS > would cause linking to fail later on. I'm sure there are better ways of > doing it, but this seems to work for me. Let me know if it fails! For a while it's been possible to simply add the provider definition to SRCS. We have rules in share/mk that handle the rest. Below is a patch which adds a USDT probe to cat(1) as an example, the probe just prints the file name of each file that gets processed. BTW, I can't seem to declare a probe argument with type const char * - when dtrace -h generates the header, the const qualifer gets stripped away. That seems like a bug. # dtrace -n 'cat$target:::foo {printf("%s", copyinstr(arg0));}' -c "cat /dev/null" dtrace: description 'cat$target:::foo ' matched 1 probe CPU ID FUNCTION:NAME 6 99502 scanfiles:foo /dev/null dtrace: pid 80789 has exited diff --git a/bin/cat/Makefile b/bin/cat/Makefile index 06bb071363f8..81cad980eaa3 100644 --- a/bin/cat/Makefile +++ b/bin/cat/Makefile @@ -5,6 +5,7 @@ PACKAGE=runtime PROG= cat +SRCS= cat.c catprov.d .ifdef BOOTSTRAPPING # For the bootstrap cat we disable all wide char support to allow building diff --git a/bin/cat/cat.c b/bin/cat/cat.c index 5a1fab0c26a0..91f31d0b4668 100644 --- a/bin/cat/cat.c +++ b/bin/cat/cat.c @@ -74,6 +74,8 @@ __FBSDID("$FreeBSD$"); #include <casper/cap_fileargs.h> #include <casper/cap_net.h> +#include "catprov.h" + static int bflag, eflag, lflag, nflag, sflag, tflag, vflag; static int rval; static const char *filename; @@ -266,6 +268,7 @@ scanfiles(char *argv[], int cooked __unused) fd = udom_open(path, O_RDONLY); #endif } + CAT_FOO(__DECONST(char *, filename)); if (fd < 0) { warn("%s", path); rval = 1; diff --git a/bin/cat/catprov.d b/bin/cat/catprov.d new file mode 100644 index 000000000000..5d9d2444cc23 --- /dev/null +++ b/bin/cat/catprov.d @@ -0,0 +1,3 @@ +provider cat { + probe foo(char *); +};