Created
October 29, 2010 09:30
-
-
Save holtwick/653205 to your computer and use it in GitHub Desktop.
This file contains 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
#if DEBUG | |
#import <objc/runtime.h> | |
#import <objc/message.h> | |
#include <execinfo.h> | |
#include <stdio.h> | |
void dumpCall(id *__selfPtr, SEL __cmd) { | |
// Get argument stack | |
id __self = *__selfPtr; | |
void *stack = __selfPtr; | |
stack += sizeof(__self) + sizeof(__cmd); | |
// Prepare Method info | |
Method method = class_getInstanceMethod([__self class], __cmd); | |
NSArray *parts = [NSStringFromSelector(method_getName(method)) componentsSeparatedByString:@":"]; | |
NSString *output = [NSString stringWithFormat:@"* -[%@", NSStringFromClass([__self class])]; | |
// Loop arguments | |
for(unsigned i = 2; i < method_getNumberOfArguments(method); i++) { | |
char *argtype = method_copyArgumentType(method, i); | |
// Object | |
if(strlen(argtype) == 1) { | |
if(argtype[0] == '@') { | |
id o = (id)*(Handle)stack; | |
if([o isKindOfClass:[NSString class]]) { | |
output = [output stringByAppendingFormat:@" %@:@%@", [parts objectAtIndex:i - 2], [o repr]]; | |
} else { | |
output = [output stringByAppendingFormat:@" %@:%@", [parts objectAtIndex:i - 2], o]; | |
} | |
stack += sizeof(o); | |
} | |
else if(argtype[0] == 'i') { | |
int *v = stack; | |
output = [output stringByAppendingFormat:@" %@:%d", [parts objectAtIndex:i - 2], *v]; | |
stack += sizeof(int); | |
} | |
// ... | |
else { | |
output = [output stringByAppendingFormat:@" %@:***fail at '%s' ***", [parts objectAtIndex:i - 2], argtype]; | |
break; | |
} | |
} else { | |
if(strcmp(argtype, "{CGPoint=") > 0) { | |
CGPoint *v = (CGPoint *)(Handle)stack; | |
output = [output stringByAppendingFormat:@" %@:%@", [parts objectAtIndex:i - 2], NSStringFromCGPoint(*v)]; | |
stack += sizeof(CGPoint); | |
} | |
// ... | |
else { | |
output = [output stringByAppendingFormat:@" %@:***fail at '%s' ***", [parts objectAtIndex:i - 2], argtype]; | |
break; | |
} | |
} | |
free(argtype); | |
} | |
NSLog(@"%@]", output); | |
} | |
#define XPingFull dumpCall(&self, _cmd); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. Unfortunately it doesn't work on my iPhone. In line 26, o is assigned garbage and I get a crash in the next line. The calling method has one object (non-NSString) parameter. Does this only work on specific binary architectures?