Re: Tracing userland calls through to a driver

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 15 Sep 2022 08:43:47 UTC
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