Created
February 21, 2013 14:53
-
-
Save markd2/5005201 to your computer and use it in GitHub Desktop.
On-demand Objective-C message tracing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pid$target::objc_msgSend:entry | |
/arg0 == 0/ | |
{ | |
@stacks[ustack(5)] = count(); | |
} | |
END | |
{ | |
trunc (@stacks, 20); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pid$target::objc_msgSend:entry | |
/arg0 == 0/ | |
{ | |
ustack (); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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