Skip to content
Merged
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def lldbcommands():
FBPrintInstanceVariable(),
FBPrintKeyPath(),
FBPrintData(),
FBPrintTargetActions(),
]

class FBPrintViewHierarchyCommand(fb.FBCommand):
Expand Down Expand Up @@ -371,3 +372,28 @@ def run(self, arguments, option):

print_command = 'po (NSString *)[[NSString alloc] initWithData:{} encoding:{}]'.format(arguments[0], enc)
lldb.debugger.HandleCommand(print_command)

class FBPrintTargetActions(fb.FBCommand):

def name(self):
return 'pactions'

def description(self):
return 'Print the actions and targets of a control.'

def args(self):
return [ fb.FBCommandArgument(arg='control', type='UIControl *', help='The control to inspect the actions of.') ]

def run(self, arguments, options):
control = arguments[0]
targets = fb.evaluateObjectExpression('[[{control} allTargets] allObjects]'.format(control=control))
targetCount = fb.evaluateIntegerExpression('[{targets} count]'.format(targets=targets))

for index in range(0, targetCount):
target = fb.evaluateObjectExpression('[{targets} objectAtIndex:{index}]'.format(targets=targets, index=index))
actions = fb.evaluateObjectExpression('[{control} actionsForTarget:{target} forControlEvent:0]'.format(control=control, target=target))

targetDescription = fb.evaluateExpressionValue('(id){target}'.format(target=target)).GetObjectDescription()
actionsDescription = fb.evaluateExpressionValue('(id)[{actions} componentsJoinedByString:@","]'.format(actions=actions)).GetObjectDescription()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does this look like when it prints?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I meant to include an example output, thanks for asking!

For a view controller, something like:

<XXXViewController: 0xdddddddd>: didTapButton:

If there are multiple actions:

<XXXViewController: 0xdddddddd>: didTapButton:, didTouchButton:

The output would be messier if the target provides a verbose -description method. Perhaps this shouldn't rely on the built in -description and should instead manually format the <Class: 0xdddddddd> string.


print '{target}: {actions}'.format(target=targetDescription, actions=actionsDescription)