blog.farhan.codes

Farhan's Personal and Professional Blog


Simple dtrace use-case

Very small example of using dtrace, mostly for me to refernece in the future.

As I port this wifi card, I am running into a situation where ifconfig is reporting an error that I do not understand. From previous reading, I know that ifconfig interfaces with the kernel through ioctl. Driver code initially handles ioctl requests by implementing the ic->ic_ioctl handler.

To that end, in my handler I printed the u_long cmd variable with the intention of looking up the value. However, the source has them listed like this in /usr/src/sys/sys/sockio.h.

#define SIOCSIFMEDIA    _IOWR('i', 55, struct ifreq)    /* set net media */

Short of printing dozens of other values and comparing, I used dtrace to include the header file and check the value in real time.

#!/usr/sbin/dtrace -Cs

#include <sys/sockio.h>

fbt:kernel:ieee80211_ioctl:entry
{
	/* The 2nd argument, arg1, is cmd */
	cmd = arg1;
	printf("ieee80211_ioctl: %lx", cmd);
	if (cmd == SIOCSIFMEDIA) {
		printf("cmd = SIOCSIFMEDIA");
	}
		
}

This is a very simple of what I needed to solve my dilemma.

‘Tis all!