Jeremy Uejio's Blog

Jeremy Uejio's Weblog
Wednesday Jul 02, 2008

simple DTrace script to print function argument

Someone asked me for a DTrace script to print out the argument to an arbitrary function. I'm not exactly sure if this is what he meant, so I wrote a script which lets you specify a function name and the position of the string argument that you want printed out and then the command to run.  Since it's a script, you can modify to print out integer args or to connect to a running process, etc...

The script is called printarg.d.  You have to run it either as root or with sufficient privileges in /etc/user_attr.  For example, this entry allows me to run dtrace scripts:

uejio::::type=normal;defaultpriv=basic,dtrace_user,dtrace_proc,dtrace_kernel

Anyway, here's an example:

$ printarg.d XLoadQueryFont 1 -c dtcalc
XLoadQueryFont: arg1=-dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*
XLoadQueryFont: arg1=-dt-interface system-medium-r-normal-m sans-17-170-72-72-p-97-iso8859-1
XLoadQueryFont: arg1=-dt-interface user-medium-r-normal-m sans-14-140-72-72-m-90-iso8859-1


Here's another example:

$ printarg.d fopen 0 -c dtcalc
fopen: arg0=/home/uejio/.Xauthority
fopen: arg0=/usr/openwin/lib/locale/locale.alias
fopen: arg0=/usr/openwin/lib/locale/locale.dir
fopen: arg0=/usr/openwin/lib/locale/locale.alias
fopen: arg0=/usr/openwin/lib/locale/locale.alias
fopen: arg0=/usr/openwin/lib/locale/locale.dir
fopen: arg0=/usr/openwin/lib/X11/Xcms.txt
fopen: arg0=/home/uejio/.icons/blueprint-cursor-theme/cursors/arrow
fopen: arg0=/home/uejio/.icons/blueprint-cursor-theme/index.theme
fopen: arg0=/usr/share/icons/blueprint-cursor-theme/cursors/arrow
fopen: arg0=/usr/share/icons/blueprint-cursor-theme/index.theme
fopen: arg0=/usr/share/pixmaps/blueprint-cursor-theme/cursors/arrow
fopen: arg0=/usr/share/pixmaps/blueprint-cursor-theme/index.theme
fopen: arg0=/home/uejio/.icons/default/cursors/arrow
fopen: arg0=/home/uejio/.icons/default/index.theme
fopen: arg0=/usr/share/icons/default/cursors/arrow
fopen: arg0=/usr/share/icons/default/index.theme
fopen: arg0=/usr/share/pixmaps/default/cursors/arrow
fopen: arg0=/usr/share/pixmaps/default/index.theme
fopen: arg0=/usr/dt/appconfig/icons/C/Dtcalc.l.bm
fopen: arg0=/usr/dt/appconfig/icons/C/Dtcalc.l_m.bm


Well, I thought this was pretty cool and so easy to do in DTrace, but your mileage may vary. ;-)

If anyone knows of a simpler way to calculate the args to pass in, please let me know.


Archives
Links
Referrers