Skip navigation.
 
mlRe: NSLog every selector on an object?
FROM : Bill Bumgarner
DATE : Sat May 10 19:48:00 2008

> On May 9, 2008, at 9:44 PM, Matt James wrote:

>> Is there any way to overload a class in such a manner as to print 
>> out every
>> method call it makes at any given time before it runs the method? 
>> Right
>> now, I'm overloading a few methods of this particular class and 
>> putting
>> NSLog's at the first line, but I was wondering if there was a way 
>> to jump in
>> before _ALL_ methods on an object and perform this particular task.
>> Thanks for any help!


You could implement an NSProxy type thing and shove that in the 
middle.  Or diddle the isa of the class to point to a new isa that 
logs-and-forwards via various mechanisms described within the previous 
messages (including the link to my weblog, which definitely could be 
hacked to do this).

Personally, I'd use dtrace.  I wrote up a couple of later articles on 
logging / debugging messages to nil.

http://www.friday.com/bbum/2008/01/03/objective-c-using-dtrace-to-trace-messages-to-nil/

http://www.friday.com/bbum/2008/01/26/objective-c-printing-class-name-from-dtrace/

You would want to change the '/arg0==0/' qualifier to qualify for your 
instance of interest.  This will be just a bit non-trivial to do 
compared to the described recipes.  You'll need to stash the id of the 
object of interest into dtrace's world somehow.  You could do so with 
a BEGIN{} hook, but that'll require firing up the dtrace script 
*after* the object has come into existence.  A better solution might 
be to have a couple of dtrace trace points in the script;  one that 
does the qualified logging and one that, when triggered, stashes away 
an object of interest's id such that the qualifier can see it.

b.bum

Related mailsAuthorDate
mlNSLog every selector on an object? Matt James May 10, 05:44
mlRe: NSLog every selector on an object? Christiaan Hofman May 10, 13:11
mlRe: NSLog every selector on an object? Jonathon Mah May 10, 15:49
mlRe: NSLog every selector on an object? objectwerks inc May 10, 18:32
mlRe: NSLog every selector on an object? Bill Bumgarner May 10, 19:48
mlRe: NSLog every selector on an object? Gerd Knops May 10, 20:34
mlRe: NSLog every selector on an object? Scott Little May 10, 23:34
mlRe: NSLog every selector on an object? Stéphane Corthésy May 11, 11:53
mlRe: NSLog every selector on an object? Matt James May 11, 15:33
mlRe: NSLog every selector on an object? objectwerks inc May 12, 01:45
mlRe: NSLog every selector on an object? Scott Little May 12, 13:02
mlRe: NSLog every selector on an object? Carlos Salinas May 12, 18:08