I can write a simple dtrace script to tell me each time the -orderOut: method 
is called in my program.

   #pragma D option quiet

   objc$target::-orderOut?:entry
   {
       printf( "%30s %10s %x %x\n", probemod, probefunc, arg0, arg1 );
   }

I know that arg0 contains the address of self for the orderOut method which is 
my NSWindow.

So, is it possible to obtain the title of the NSWindow and print it out each 
time this probe fires? If so, how?


The other possible solution would be to setup a -setTitle: probe, grab the 
window title from it, and setup a hashed array based on self. I did find one 
stackoverflow question about how to get the data from a CFStringRef ( 
http://stackoverflow.com/questions/1413623/how-do-i-print-a-cfstringref-in-a-dtrace-action
 ), but it doesn't appear to work for a NSString.

   objc$target:NSWindow:-setTitle?:entry
   {
       printf( "%30s %10s %x %x %x\n", probemod, probefunc, arg0, arg1, arg2 );

       this->str = *(ptr_t*)copyin(arg2+2*sizeof(ptr_t), sizeof(ptr_t));

       printf("string addr = %p\n", this->str);
       printf("string val  = %s\n", copyinstr(this->str));
   }

DTrace reported:

NSWindow -setTitle: 100685240 7fff92d82f73 7fff78a6eb80 string addr = 
7fff8e7e83b9 string val=Window dtrace: error on enabled probe ID 5 (ID 35737: 
objc9434:NSWindow:-setTitle::entry): invalid address (0x6c007400690074) in 
action #8 at DIF offset 24

Any thoughts on this would be of interest.

Thank you.

_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org

Reply via email to