Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add evalfile command #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add evalfile command #248

wants to merge 1 commit into from

Conversation

longv2go
Copy link
Contributor

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,
......
)

evalfile support args

ret = fb.evaluate(source)
# if ret is not an address then print it directly
if ret[0:2] != '0x':
Copy link
Contributor

@kastiglione kastiglione Oct 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do not ret.startswith('0x')

print ret
else:
command = 'po {}'.format(ret)
lldb.debugger.HandleCommand(command)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do print fb.evaluateExpressionValue(ret).GetObjectDescription()

ret = process.ReadCStringFromMemory(int(ret.GetValue(), 16), 2**20, error)
if not error.Success():
print error
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these changes about?

@kastiglione
Copy link
Contributor

kastiglione commented Oct 27, 2018

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants