Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def lldbcommands():
FBPrintOnscreenTableViewCells(),
FBPrintInternals(),
FBPrintInstanceVariable(),
FBPrintKeyPath(),
]

class FBPrintViewHierarchyCommand(fb.FBCommand):
Expand Down Expand Up @@ -272,3 +273,24 @@ def run(self, arguments, options):

printCommand = 'po' if ('@' in ivarTypeEncodingFirstChar) else 'p'
lldb.debugger.HandleCommand('{} (({} *)({}))->{}'.format(printCommand, objectClass, object, ivarName))

class FBPrintKeyPath(fb.FBCommand):
def name(self):
return 'pkp'

def description(self):
return "Print out the value of the key path expression using -valueForKeyPath:"

def args(self):
return [
fb.FBCommandArgument(arg='keypath', type='NSString *', help='The keypath to print'),
]

def run(self, arguments, options):
if len(arguments[0].split('.')) == 1:
print '"' + arguments[0] + '" is not a keypath =('
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about treating this case as equal to po? That way, we can all type pkp except when evaluating something fancy.

Copy link
Author

Choose a reason for hiding this comment

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

It's an interesting idea, to add durable-ness, but I think it'd need a lot more checks than the presence of a '.' to be worth implementing. IE, [UIApplication sharedApplication].keyWindow would still blow up. I'd rather blow up in all slightly-wrong scenarios just keep clarity of intent.

Copy link
Contributor

Choose a reason for hiding this comment

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

See my other comment. Personally, while debugging, I'd rather make things as convenient as possible :)

Copy link
Author

Choose a reason for hiding this comment

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

Yea, looking at it again, I totally agree.

return

object, keypath = arguments[0].split('.', 1)
printCommand = 'po [{} valueForKeyPath:@"{}"]'.format(object, keypath)
Copy link
Contributor

Choose a reason for hiding this comment

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

In a previous commit you had it evaluating object as an expression, before evaluating the -valueForKeyPath:. How come you removed that? It seems useful because it could allow:

pkp [someObject methodTaking:1 and:2].foo.bar.whatever

lldb.debugger.HandleCommand(printCommand)