From nobody Thu Mar 23 14:25:47 2023 X-Original-To: dtrace@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pj71D424Qz41Q0f for ; Thu, 23 Mar 2023 14:25:52 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pj71C4SDdz4Y7J for ; Thu, 23 Mar 2023 14:25:51 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=klFPaRBe; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::836 as permitted sender) smtp.mailfrom=markjdb@gmail.com; dmarc=none Received: by mail-qt1-x836.google.com with SMTP id n2so26752057qtp.0 for ; Thu, 23 Mar 2023 07:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679581551; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=nMOuAX9Wdi+4ZQvGb0gLuH4byqKWi8ZH/0oGxROZ0Jo=; b=klFPaRBe5dQY7G1+/Y7xqGCaezw1PWmMatSp6b9RmKfl+GQdBFF07C2eJBjfOegixQ Vhc5MYD9MWKB+w5zzjTXQvQHPUJ9p7ektImh8LjtIYTYuvKCOU1PmNza011sezsUVNSc qRBiXyDy3y+Bb3xsYHBQVRGb7i2bjmSNxgVDgOMOHneTxl4vRec0uhhJX59UeQ6KIkQh h8HwYzqservA7WVSn/OlTzESeccczJK9sx1kS29U3xzku/lgEcYBK94jfGBgnfS8Ve9N vTQ2Pg3IL0yCYGOq/6qaS3V0uJMYsNCxN/tTiDwc+pifLkpOSuG6/vy6zpKlMCyb9inD CF4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679581551; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nMOuAX9Wdi+4ZQvGb0gLuH4byqKWi8ZH/0oGxROZ0Jo=; b=mZyIcz1jl42WgjbWHnIVVuCeVt+337jhOquOZtl2oC1zArKJ8J8g7sxPsLMY3Riwe3 cibCoGq7RUijqw8UPu4DTEqtE+5G/pq1AGcd/2xbDW4uNyhnJeMDyGE8nAiKF8G0gnBG 7e5bG9ZZloYYu6mxGnMOJlA7WlhVoqTpOb7NhtE/pXh8+EeqAEBiC+VkZDPAwet8xopR 111ZzAlq9Ogk24PxG99zdXskwdNZfABrWQRjgpFqVd+2LM1IEcD+D5mk5HIIWmPBbA/0 WZ1EB9LwCPk3Z9fVT47pgB3poerxnsvcWimnPbwlcIpWeZCgivHaTMQnBeK5BOKydSM8 EjpA== X-Gm-Message-State: AO0yUKVlaT9ZcmDoszBnmAmKigI9xTzvRMMWu4EK8coOisrf43cHS2hK Q3AHcoi3BnMZVhecgwkXDcKiK8++Z64= X-Google-Smtp-Source: AK7set8EaUhXhhpKSolhkiN3Jj63CUB2sLR7wRpRpaG3ODjBnvzoHdx2PzSDWLVct1ul1V+WsIAJzQ== X-Received: by 2002:ac8:5ccc:0:b0:3d5:cf4e:bd0 with SMTP id s12-20020ac85ccc000000b003d5cf4e0bd0mr12513028qta.63.1679581550687; Thu, 23 Mar 2023 07:25:50 -0700 (PDT) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id 78-20020a370551000000b0074236d3a149sm4121427qkf.92.2023.03.23.07.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 07:25:50 -0700 (PDT) Date: Thu, 23 Mar 2023 10:25:47 -0400 From: Mark Johnston To: Domagoj Stolfa Cc: "Bjoern A. Zeeb" , dtrace@freebsd.org Subject: Re: USDT support (in build framework)? Message-ID: References: List-Id: A discussion list for developers working on DTrace in FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-dtrace List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-dtrace@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spamd-Result: default: False [-1.70 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MID_RHS_NOT_FQDN(0.50)[]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_THREE(0.00)[3]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::836:from]; TAGGED_RCPT(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dtrace@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; ARC_NA(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; DKIM_TRACE(0.00)[gmail.com:+]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; MLMMJ_DEST(0.00)[dtrace@freebsd.org]; FREEMAIL_TO(0.00)[gmail.com]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 4Pj71C4SDdz4Y7J X-Spamd-Bar: - X-ThisMailContainsUnwantedMimeParts: N 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 #include +#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 *); +}; From nobody Tue Mar 28 12:52:27 2023 X-Original-To: freebsd-dtrace@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pm8jQ6Kssz41tH5 for ; Tue, 28 Mar 2023 12:52:42 +0000 (UTC) (envelope-from christos@freebsd.org) Received: from margiolis.net (mail.margiolis.net [95.179.159.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pm8jP5tF9z4Shx; Tue, 28 Mar 2023 12:52:41 +0000 (UTC) (envelope-from christos@freebsd.org) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=margiolis.net header.s=default header.b=p+rOZCVX; spf=softfail (mx1.freebsd.org: 95.179.159.8 is neither permitted nor denied by domain of christos@freebsd.org) smtp.mailfrom=christos@freebsd.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=default; bh=peV78Zs6wykt xrsewpFSajgQAo+OlTiU6UB8WYGu/jc=; h=subject:cc:to:from:date; d=margiolis.net; b=p+rOZCVXCmAv3AHt1LsYGuHohV6a9l2KaXIHcCVYq7pnlzkUcE5 tURs2Tj505u3FFohNp6iGI6jtqQbC+tXsPJqrG5n/QfG1uFr0Ze7eZekWGUXxTPFYzC2AF VzwrlnMlusL4TbXwTcEyx4dk2R1zsdnNVOWVMBIpH/93FJMQD4= Received: from pleb (ppp-94-66-59-63.home.otenet.gr [94.66.59.63]) by margiolis.net (OpenSMTPD) with ESMTPSA id 1b917f8f (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 28 Mar 2023 12:52:32 +0000 (UTC) Date: Tue, 28 Mar 2023 15:52:27 +0300 From: Christos Margiolis To: status-updates@freebsdfoundation.org Cc: freebsd-dtrace@freebsd.org, markj@freebsd.org, jrm@freebsd.org Subject: [Development report #6] Improve the kinst DTrace provider Message-ID: <20230328125227.zz35ufmmkocnpfdi@pleb> List-Id: A discussion list for developers working on DTrace in FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-dtrace List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-dtrace@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spamd-Result: default: False [-2.80 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_ALLOW(-0.20)[margiolis.net:s=default]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[freebsd-dtrace@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[margiolis.net:+]; ASN(0.00)[asn:20473, ipnet:95.179.144.0/20, country:US]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_COUNT_TWO(0.00)[2]; FREEFALL_USER(0.00)[christos]; ARC_NA(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 4Pm8jP5tF9z4Shx X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N The past few days I've been working on various bug fixes both in kinst and in libdtrace. Inline function tracing is almost done [1]. libdtrace now parses all loaded kernel modules, instead of just `kernel`. This makes it compatible with kinst, which also searches all loaded modules. After some testing I noticed that it is possible to have both a non-inline and an inline definition of the same function in a kernel module. If libdtrace finds such a case, it creates an additional FBT probe for the non-inline definition: # dtrace -dn 'kinst::cam_strvis_flag:entry' kinst::cam_strvis:25, kinst::cam_strvis_flag:0, fbt::cam_strvis_flag:entry { } dtrace: description 'kinst::cam_strvis_flag:entry' matched 3 probes For inline tracing, I implemented the algorithm described here [2] (markj@ has also implemented it in lib/libproc/proc_sym.c) to make sure that both the modules' ELF and debug files are up to date (i.e the module has been built with `DEBUG_FLAGS=-g`), otherwise we might run into version mismatches between functions. If such a mismatch is found, libdtrace prints a warning and skips that module. I wrote a few Kyua tests for kinst and made use of sys/dev/dtrace/dtrace_test.c (see inline tracing PR). In my previous email I mentioned that I modified kinst to search for `push %rbp` anywhere in a function, and skip the function if no `push %rbp` is found. Since this affects safe-to-trace functions that do not `push %rbp`, I'm working on an experimental change to exclude only exception handlers, and not search for `push %rbp` at all [3]. However, I'm still not sure this is 100% fail-proof, and I will need to do some more testing to make sure there are no accidental crashes. [1] https://reviews.freebsd.org/D38825 [2] https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html [3] https://reviews.freebsd.org/D39229