From nobody Thu Sep 15 08:43:47 2022 X-Original-To: freebsd-drivers@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 4MSrMr0GkHz4cWQD for ; Thu, 15 Sep 2022 08:43:52 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MSrMq6pRyz3Srd; Thu, 15 Sep 2022 08:43:51 +0000 (UTC) (envelope-from kp@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663231432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NRUZRrnjMezypX+BN9Hr7FqvtHeJsKe3qej4IGpPy+M=; b=o/y2NB1mg3HBk+p+VWG6GTHwtLmhKH2I+beyncJO5DW+12rTzUi6fYb6jQdU6Aj2SK4jst 1CsdR2pO7t23QZpM4RBvWuLwkSWkYj+IYlRhQ7Zp7e1Fdn2XfLAlMaLXogTb4es/Y5nMGI a1bGjf0AKXUOMTucMMpnbO4OLasxbkGkJw4Ww7DXv0Naw+Tw609SzfQXuyFkdCK+jtOdSs +hv69H87TfmUhlfZePNwV70La2dgMsBgNiyGiyr8W3lXQ2mA4gEyZowmLZNNdiZ9plF6em fXV3hwP4lShdlFz6EUmVUjPlKNbinZszGveeP1hhY+6eg6QZDeqATZ9XbWjiWg== Received: from venus.codepro.be (venus.codepro.be [5.9.86.228]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx1.codepro.be", Issuer "R3" (verified OK)) (Authenticated sender: kp) by smtp.freebsd.org (Postfix) with ESMTPSA id 4MSrMq51TczkMS; Thu, 15 Sep 2022 08:43:51 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: by venus.codepro.be (Postfix, authenticated sender kp) id 8420D1B985; Thu, 15 Sep 2022 10:43:48 +0200 (CEST) From: Kristof Provost To: Lee MATTHEWS Cc: freebsd-drivers@freebsd.org Subject: Re: Tracing userland calls through to a driver Date: Thu, 15 Sep 2022 10:43:47 +0200 X-Mailer: MailMate (1.14r5852) Message-ID: <7C93934E-7DF5-44FC-93B5-331AE3490189@FreeBSD.org> In-Reply-To: <484f6c4f5a2840daafaeda4943f22793@stormshield.eu> References: <484f6c4f5a2840daafaeda4943f22793@stormshield.eu> List-Id: Writing device drivers for FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-drivers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-drivers@freebsd.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_MailMate_347D4661-E9A5-4E2F-997D-72ABF7C2E717_=" Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663231432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NRUZRrnjMezypX+BN9Hr7FqvtHeJsKe3qej4IGpPy+M=; b=RBcE9mg0YbLEAMC0B6ec54ISDMJgvS3qclELAJpksONXhu2F2UcjnVy8Q/MOzOkhSqCE1s bmPjguheKecKjkGcsZz/Hl4O78FfJ2l/Q6zao+QcsOdfK8+Bg9CEhooG+wUJAlUukGO3Tz nIpuZw4M1NkCcXQhgOjwNVXX6UE0HXLTfyBJRy2Krb8Pkvmbu1/JM1h5YvJ6RD7qf9j6UO OYDryuFFLERMWPChaH8vAXVJbV2U+cmy2Rh9ZLIQhirf6I7rUFh1SvD8/yjtjvsf27Vmpv MVamOCSsf8CyeMOuKncWuGpKoH+WNOj1E5VGQxU9y7aweYKz1dBeO6p+8fRlSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663231432; a=rsa-sha256; cv=none; b=xMXPsHyD3xqSXtatcB4GKXGElZxpSjHhnSv+56At/O/MHVcB58kU3+R0UwT/Dfx37VFIbH a0SMjwmuLK8sJ4e3ed6UCPTuuSjT145VdC+USgmE6pm0NwSnvaodSWMoLxRby8AUy01PjN BZcESsJ3a+Tiycy0NsR5OnjjJf7YXSJ3PZF6EnPnlGd8FRORRMEEvAwtYhu5iamwGgHqOZ WYcj/bYElXXPC8GvnxCrt/52F5C1dM5HvSwSwNCCKkXSvLj7Oxr+cXtK7NNTw1AvbdL/e0 0ZmR6zrOWEHT+N6G++FJuzL4aA924uMBjogcUWlT2g7Vn8jTBTpgSQdi01WawQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N --=_MailMate_347D4661-E9A5-4E2F-997D-72ABF7C2E717_= Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 15 Sep 2022, at 10:37, Lee MATTHEWS wrote: > I am trying to debug some GPIO issues on FreeBSD 10.3. > That’s an unsupported version (unless you meant 12.3), so the first thing to do is to see if your issue is still present in main. > I'd like to know if it is possible to know what process in userland > (via a process id) has called a method in the driver. > > So for example, in the driver, the functions are bound via DEVMETHOD > like : > > > static device_method_t winbond_gpio_methods[] = { > /* Device interface */ > ... > DEVMETHOD(gpio_pin_set, winbond_gpio_pin_set), > DEVMETHOD(gpio_pin_get, winbond_gpio_pin_get), > ... > DEVMETHOD_END > }; > > > When the function winbond_gpio_pin_get() is called, how can I know > what called this? > > For things like this I’d either look at truss(1), which will tell you what system calls the user space process called, or Dtrace. Something like `dtrace -n fbt::winbond_gpio_pin_set:entry { stack(); }` should give you a pointer already. Dtrace can take a bit of effort to learn, but it’s generally well worth it. The wiki has some initial hints: https://wiki.freebsd.org/DTrace Best regards, Kristof --=_MailMate_347D4661-E9A5-4E2F-997D-72ABF7C2E717_= Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On 15 Sep 2022, at 10:37, Lee MATTHEWS wrote:

I am trying to debug some GPIO issu= es on FreeBSD 10.3.


That=E2=80=99s an unsupported version (unless you meant 1= 2.3), so the first thing to do is to see if your issue is still present i= n main.

I'd like to know if it is possible = to know what process in userland (via a process id) has called a method i= n the driver.

So for example, in the driver, the functions are bound vi= a DEVMETHOD like :

static device_method_t winbond_gpio_methods[] =3D {
/* Device interface */
=2E..
DEVMETHOD(gpio_pin_set, winbond_gpio_pin_set),
DEVMETHOD(gpio_pin_get, winbond_gpio_pin_get),
=2E..
DEVMETHOD_END
};

When the function winbond_gpio_pin_get() is called, how c= an I know what called this?


For things like this I=E2=80=99d either look at truss(1),= which will tell you what system calls the user space process called, or = Dtrace.

Something like dtrace -n fbt::winbond_gpio_pin_set:= entry { stack(); } should give you a pointer already.
Dtrace can take a bit of effort to learn, but it=E2=80=99s generally well= worth it. The wiki has some initial hints: https://wiki.freebsd.org/DTrace

Best regards,
Kristof

--=_MailMate_347D4661-E9A5-4E2F-997D-72ABF7C2E717_=--