1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| #import "NSObject+JAlldb.h" #import <objc/message.h>
@implementation NSObject (JAlldb)
const void* propertiesKey = "com.coder.lldb-exclusive.propertiesKey"; const void* ivarKey = "com.coder.lldb-exclusive.ivarKey"; const void* methodKey = "com.coder.lldb-exclusive.methodKey";
- (NSArray *)p_propertyList:(BOOL)recursive { NSArray *glist = objc_getAssociatedObject([self class], propertiesKey);
return glist == nil ? ^{ unsigned int count = 0; NSMutableArray *plistM = [NSMutableArray arrayWithCapacity:count]; Class cls = [self class]; do { objc_property_t *list = class_copyPropertyList(cls, &count); for (int i = 0; i < count; ++i) { objc_property_t pty = list[i]; const char *pname = property_getName(pty); [plistM addObject:[NSString stringWithUTF8String:pname]]; } free(list); cls = [cls superclass]; } while (cls && recursive); objc_setAssociatedObject([self class],propertiesKey, plistM, OBJC_ASSOCIATION_COPY_NONATOMIC); NSLog(@"Found %ld properties on %@",plistM.count,[self class]); return plistM.copy; }() : glist; }
- (NSArray *)p_ivarList:(BOOL)recursive{ NSArray *glist = objc_getAssociatedObject([self class], ivarKey); return glist == nil ? ^{ unsigned int count = 0; NSMutableArray *plistM = [NSMutableArray arrayWithCapacity:count]; Class cls = [self class]; do { Ivar *list = class_copyIvarList(cls, &count); for (int i = 0; i < count; ++i) { Ivar ity = list[i]; const char *iname = ivar_getName(ity); [plistM addObject:[NSString stringWithUTF8String:iname]]; } free(list); cls = [cls superclass]; } while (cls && recursive); NSLog(@"Found %ld ivar on %@",plistM.count,[self class]); objc_setAssociatedObject([self class],ivarKey, plistM, OBJC_ASSOCIATION_COPY_NONATOMIC); return plistM.copy; }() : glist; }
- (NSArray *)p_methodList:(BOOL)recursive { NSArray *glist = objc_getAssociatedObject([self class], methodKey); return glist == nil ? ^{ unsigned int methodCount = 0; NSMutableArray *plistM = [NSMutableArray arrayWithCapacity:methodCount]; Class cls = [self class]; do { Method *methods = class_copyMethodList(cls, &methodCount); for (unsigned int i = 0; i < methodCount; i++) { Method method = methods[i];
[plistM addObject:[NSString stringWithUTF8String:sel_getName(method_getName(method))]]; } free(methods); cls = [cls superclass]; }while (cls && recursive); printf("Found %d methods on '%s'\n", methodCount, class_getName([self class])); objc_setAssociatedObject([self class],ivarKey, plistM, OBJC_ASSOCIATION_COPY_NONATOMIC); return plistM.copy; }() : glist; }
- (void)p_cleanCacheList { objc_removeAssociatedObjects([self class]); }
@end
|