chisel icon indicating copy to clipboard operation
chisel copied to clipboard

Add evalfile command

Open longv2go opened this issue 7 years ago • 1 comments

evalfile command can evaluate a multiline source code from a file. You can also supply a argument after the file parameter.

// /path/to/test.m

@import ObjectiveC.runtime;

NSMutableArray *result = (id)[NSMutableArray array];
unsigned int count;
objc_property_t *props = (objc_property_t *)class_copyPropertyList((Class)$arg0, &count);
for (int i = 0; i < count; i++) {
    char *name = (char *)property_getName(props[i]);
    [result addObject:(id)[NSString stringWithUTF8String:name]];
}
RETURN(result);
lldb> p/x (char*)NSClassFromString(@"UIView")
(char *) $35 = 0x00000001119a7ff8
lldb> evalfile  /path/to/test.m 0x00000001119a7ff8
<__NSArrayM 0x608000057040>(
hash,
superclass,
description,
debugDescription,
hash,
superclass,
description,
......
)

longv2go avatar Sep 14 '18 03:09 longv2go

Thanks for the pull request. I did something similar recently, but without the arguments. Have you tried wrapping the code in a function? Or alternatively, a class method or a category? For example:

@import ObjectiveC.runtime;

@implementation NSObject (ObjectProperties)

+ (NSArray *)propertyNames {
    NSMutableArray *result = (id)[NSMutableArray array];
    unsigned int count;
    objc_property_t *props = (objc_property_t *)class_copyPropertyList(self, &count);
    for (int i = 0; i < count; i++) {
        char *name = (char *)property_getName(props[i]);
        [result addObject:(id)[NSString stringWithUTF8String:name]];
    }
    return result;
}

@end

And then from lldb:

lldb> evalfile /path/to/test.m
lldb> po [UIView propertyNames]

kastiglione avatar Oct 27 '18 06:10 kastiglione