Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
On-demand Objective-C message tracing
#import <Foundation/Foundation.h>
// clang -g -fobjc-arc -framework Foundation -o array array.m
void observeObject (id objectToWatch) {
// Just a stub to give DTrace something to hook in to.
}
int main (void) {
@autoreleasepool {
NSArray *thing1 = @[ @1, @2, @3, @4];
observeObject (thing1);
[thing1 enumerateObjectsUsingBlock: ^(id thing, NSUInteger index, BOOL *whoa) {
NSLog (@"Saw %@", thing);
}];
observeObject (nil);
NSLog (@"it's got %ld elements", thing1.count);
}
return 0;
} // main
pid$target::objc_msgSend:entry
/arg0 == 0/
{
@stacks[ustack(5)] = count();
}
END
{
trunc (@stacks, 20);
}
pid$target::objc_msgSend:entry
/arg0 == 0/
{
ustack ();
}
/* run with
* # dtrace -qs watch-array.d -c ./array
*/
int64_t observedObject;
pid$target::observeObject:entry
{
printf ("observing object: %p\n", arg0);
observedObject = arg0;
}
objc$target:::entry
/arg0 == observedObject/
{
printf("%s %s\n", probemod, probefunc);
/* uncomment to print stack:
* ustack();
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.