# Using dtrace to print kernel struct argument



## Farhan Khan (Feb 20, 2022)

Hi all,

TLDR; I want to print out a complicated struct in a human readable way dtrace. I could manually add in the struct, but there are several nested structs and that gets messy and difficult to replicate very quickly. How does one do this?

Detailed: I am trying to display the print a structure that is returned by the kernel function usbd_get_endpoint. The background is because I am running usbd_transfer_setup but getting an error condition and do not understand why, so I want to instrument usbd_get_endpoint, which is called by usbd_transfer_setup.

I want to print out the struct usb_endpoint in a human readable format. It is located in sys/dev/usb/usbdi.h

Currently I have done this:

```
#include <sys/dev/usb/usbdi.h>

fbt::usbd_get_endpoint:return
{
    printf("Exit %d\n", arg0);
}
```

Here are my outputs:


```
[farhan@freebsddev ~]$ sudo dtrace -s usbd_get_endpoint.d
dtrace: failed to compile script usbd_get_endpoint.d: invalid control directive: #include
[farhan@freebsddev ~]$ sudo dtrace -C -s usbd_get_endpoint.d
dtrace: failed to compile script usbd_get_endpoint.d: line 1: invalid type combination
```
Is including header files possible in dtrace? If so, how is this done?


----------



## covacat (Feb 20, 2022)

i have no idea but you may have to pipe it thru cpp first like with other stuff (like dtc)


----------



## Farhan Khan (Feb 20, 2022)

covacat said:


> i have no idea but you may have to pipe it thru cpp first like with other stuff (like dtc)


What does that mean?


----------



## covacat (Feb 20, 2022)

Farhan Khan said:


> What does that mean?


that you use cpp(1)  as a preprocessor (c compilers do that automatically)
again, don't know if applies to dtrace


----------



## Andriy (Feb 21, 2022)

You don't need to include any headers into your script. All types used in kernel are already available via kernel's CTF.


----------

