Created
January 3, 2017 19:49
-
-
Save lilyball/4ae544382622dc84bfc690e068beb66d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
command script import ~/path/to/viewControllers.py | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import lldb | |
import shlex | |
#import argparse | |
#def create_argument_parser(): | |
#description = '''With no arguments, print the view controller hierarchy.''' | |
#parser = argparse.ArgumentParser(description=descriptoin, prog='viewControllers') | |
#parser.add_argument('-l', '--limit-to-view', dest='view', metavar='address', help='limit controllers to the responder chain for this view') | |
#return parser | |
def viewControllers(debugger, command, result, internal_dict): | |
#parser = create_argument_parser() | |
#try: | |
#args = parser.parse_args(shlex.split(command)) | |
#except SystemExit: | |
## bad arguments cause ArgumentParser to throw SystemExit | |
#result.SetError('argument parsing failed') | |
#return | |
args = shlex.split(command) | |
if len(args) != 1: | |
result.SetError('expected one argument') | |
return | |
target = debugger.GetSelectedTarget() | |
code = ''' | |
import UIKit | |
var results: [UIViewController] = [] | |
for resp in sequence(first: unsafeBitCast('''+args[0]+''', to: UIResponder.self), next: { $0.next }) { | |
if let vc = resp as? UIViewController { | |
results.append(vc) | |
} | |
} | |
results''' | |
opts = lldb.SBExpressionOptions() | |
opts.SetLanguage(lldb.eLanguageTypeSwift) | |
opts.SetUnwindOnError(True) | |
opts.SetTimeoutInMicroSeconds(5000000) # 5 seconds | |
val = target.EvaluateExpression(code, opts) | |
if val.error.fail: | |
result.SetError(val.error, "unknown error") | |
return | |
if val.num_children: | |
for child in val: | |
print >>result, "{} {}".format(child.name, child.description.strip()) | |
else: | |
print >>result, "no results" | |
def __lldb_init_module(debugger, internal_dict): | |
#parser = create_argument_parser() | |
#viewControllers.__doc__ = parser.format_help() | |
viewControllers.__doc__ = '''Usage: viewControllers <address> | |
Prints the view controllers in the responder chain for the view identified by <address>.''' | |
debugger.HandleCommand('command script add -f viewControllers.viewControllers viewControllers') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment