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.
About

uejio

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today