Jeremy Uejio's Blog

Jeremy Uejio's Weblog
Thursday Dec 15, 2005

dtrace for S9 wish

While debugging an Xlib issue on Solaris 9, I sure wished dtrace was available for that OS. I just wanted to see when the values of width and height to the XCreatePixmap call were greater than a certain value. A simple dtrace script such as:

#!/usr/sbin/dtrace -s
 
pid$target:libX11:XCreatePixmap:entry
/arg2 > 4095||arg3 > 4095/
{
	printf("width=%d, height=%d, depth=%d\n",arg2,arg3,arg4);
}

would have done the trick. But, since dtrace isn't available for S9, I ended up creating a preload library and used LD_PRELOAD. So, something like:

#include <stdio.h>
#include <dlfcn.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xatom.h>
/* 
   compile with:
   cc -I/usr/openwin/include -o preloadpixmap.so.1 -G -K pic preloadpixmap.c
   then:
   setenv LD_PRELOAD ./preloadpixmap.so.1
*/

Pixmap XCreatePixmap(display, d, width, height, depth)
     Display *display;
     Drawable d;
     unsigned int width, height;
     unsigned int depth;
{
  Pixmap pix;
  static void *(* fptr)() = 0;
  if (fptr == 0) {
    fptr = (void *(*)())dlsym(RTLD_NEXT,"XCreatePixmap");
    if (fptr == NULL) {
      (void) printf("dlopen: %s\n", dlerror());
      return NULL;
    }
  }
     if ((width>4095)||(height>4095)) {
        printf("XCreatePixmap: width=%d, height=%d, depth=%d\n",
		width,height,depth);
     }
  pix = (Pixmap)((*fptr)(display,d,width,height,depth));
  return pix;
}

dtrace would have been soo much easier...

 

Comments:

Post a Comment:
Comments are closed for this entry.

Archives
Links
Referrers