Skip to content

Instantly share code, notes, and snippets.

@jkasten2
Last active November 23, 2016 00:22
Show Gist options
  • Save jkasten2/0654ec7c8a577ea26127d924a6f4a20c to your computer and use it in GitHub Desktop.
Save jkasten2/0654ec7c8a577ea26127d924a6f4a20c to your computer and use it in GitHub Desktop.
Some Objective-c debug functions
void DumpProtocols(Class cls) {
unsigned count;
Protocol * __unsafe_unretained * pl = class_copyProtocolList(cls, &count);
for (unsigned i = 0; i < count; i++)
NSLog(@"Class %@ implements protocol <%s>", cls, protocol_getName(pl[i]));
free(pl);
}
void DumpObjcMethods(Class clz) {
unsigned int methodCount = 0;
Method *methods = class_copyMethodList(clz, &methodCount);
NSLog(@"Found %d methods on '%s'\n", methodCount, class_getName(clz));
for (unsigned int i = 0; i < methodCount; i++) {
Method method = methods[i];
NSLog(@"'%s' has method named '%s' of encoding '%s'\n",
class_getName(clz),
sel_getName(method_getName(method)),
method_getTypeEncoding(method));
}
free(methods);
}
void logImpPointer(Class newClass, SEL newSel) {
Method newMeth = class_getInstanceMethod(newClass, newSel);
IMP imp = method_getImplementation(newMeth);
NSLog(@"logImpPointer:%@, %d", NSStringFromSelector(newSel), (int)imp);
}
void dumpAppDelegate() {
return;
UIApplication *sharedApp = [UIApplication sharedApplication];
NSLog(@"sharedApp.delegate: %@", sharedApp.delegate);
if (sharedApp.delegate) {
logImpPointer([sharedApp.delegate class], @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:));
NSLog(@"sharedApp.delegate.class: %@", NSStringFromClass(sharedApp.delegate.class));
DumpProtocols(sharedApp.delegate.class);
DumpObjcMethods(sharedApp.delegate.class);
}
}
// Get Stack trace
[NSThread callStackSymbols]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment