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

Get Swifty - Update everything to use ObjC++ or Swift contexts explicitly #121

Merged
merged 5 commits into from
Nov 15, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions commands/FBAccessibilityCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def forceStartAccessibilityServer():
if not fb.evaluateBooleanExpression('[UIView instancesRespondToSelector:@selector(_accessibilityElementsInContainer:)]'):
#Starting accessibility server is different for simulator and device
if fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] model]').GetObjectDescription().lower().find('simulator') >= 0:
lldb.debugger.HandleCommand('expr (void)[[UIApplication sharedApplication] accessibilityActivate]')
lldb.debugger.HandleCommand('eobjc (void)[[UIApplication sharedApplication] accessibilityActivate]')
else:
lldb.debugger.HandleCommand('expr (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]')
lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]')

def accessibilityLabel(view):
#using Apple private API to get real value of accessibility string for element.
Expand Down
6 changes: 3 additions & 3 deletions commands/FBAutoLayoutCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def args(self):
return [ fb.FBCommandArgument(arg='view', type='UIView *', help='The view to print the Auto Layout trace for.', default='(id)[[UIApplication sharedApplication] keyWindow]') ]

def run(self, arguments, options):
lldb.debugger.HandleCommand('po (id)[{} _autolayoutTrace]'.format(arguments[0]))
lldb.debugger.HandleCommand('poobjc (id)[{} _autolayoutTrace]'.format(arguments[0]))


def setBorderOnAmbiguousViewRecursive(view, width, color):
Expand All @@ -40,8 +40,8 @@ def setBorderOnAmbiguousViewRecursive(view, width, color):
isAmbiguous = fb.evaluateBooleanExpression('(BOOL)[%s hasAmbiguousLayout]' % view)
if isAmbiguous:
layer = viewHelpers.convertToLayer(view)
lldb.debugger.HandleCommand('expr (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width))
lldb.debugger.HandleCommand('expr (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color))
lldb.debugger.HandleCommand('eobjc (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width))
lldb.debugger.HandleCommand('eobjc (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color))

subviews = fb.evaluateExpression('(id)[%s subviews]' % view)
subviewsCount = int(fb.evaluateExpression('(int)[(id)%s count]' % subviews))
Expand Down
6 changes: 3 additions & 3 deletions commands/FBComponentCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def options(self):

def run(self, arguments, options):
if options.set:
lldb.debugger.HandleCommand('expr (void)[CKComponentDebugController setDebugMode:YES]')
lldb.debugger.HandleCommand('eobjc (void)[CKComponentDebugController setDebugMode:YES]')
print 'Debug mode for ComponentKit has been set.'
elif options.unset:
lldb.debugger.HandleCommand('expr (void)[CKComponentDebugController setDebugMode:NO]')
lldb.debugger.HandleCommand('eobjc (void)[CKComponentDebugController setDebugMode:NO]')
print 'Debug mode for ComponentKit has been unset.'
else:
print 'No option for ComponentKit Debug mode specified.'
Expand All @@ -60,7 +60,7 @@ def run(self, arguments, options):
upwards = 'YES' if options.upwards else 'NO'
showViews = 'YES' if options.showViews == 'YES' else 'NO'

lldb.debugger.HandleCommand('po (id)[CKComponentHierarchyDebugHelper componentHierarchyDescriptionForView:(UIView *)' + arguments[0] + ' searchUpwards:' + upwards + ' showViews:' + showViews + ']')
lldb.debugger.HandleCommand('poobjc (id)[CKComponentHierarchyDebugHelper componentHierarchyDescriptionForView:(UIView *)' + arguments[0] + ' searchUpwards:' + upwards + ' showViews:' + showViews + ']')

class FBComponentsReflowCommand(fb.FBCommand):
def name(self):
Expand Down
6 changes: 3 additions & 3 deletions commands/FBDisplayCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def options(self):

def run(self, args, options):
def setBorder(layer, width, color, colorClass):
lldb.debugger.HandleCommand('expr (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width))
lldb.debugger.HandleCommand('expr (void)[%s setBorderColor:(CGColorRef)[(id)[%s %sColor] CGColor]]' % (layer, colorClass, color))
lldb.debugger.HandleCommand('eobjc (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width))
lldb.debugger.HandleCommand('eobjc (void)[%s setBorderColor:(CGColorRef)[(id)[%s %sColor] CGColor]]' % (layer, colorClass, color))

obj = args[0]
depth = int(options.depth)
Expand Down Expand Up @@ -111,7 +111,7 @@ def args(self):

def run(self, args, options):
def setUnborder(layer):
lldb.debugger.HandleCommand('expr (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, 0))
lldb.debugger.HandleCommand('eobjc (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, 0))

obj = args[0]
depth = int(options.depth)
Expand Down
2 changes: 1 addition & 1 deletion commands/FBFindCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ def run(self, arguments, options):
@staticmethod
def taplog_callback(frame, bp_loc, internal_dict):
parameterExpr = objc.functionPreambleExpressionForObjectParameterAtIndex(0)
lldb.debugger.HandleCommand('po [[[%s allTouches] anyObject] view]' % (parameterExpr))
lldb.debugger.HandleCommand('poobjc (UIView *)[[[%s allTouches] anyObject] view]' % (parameterExpr))
# We don't want to proceed event (click on button for example), so we just skip it
lldb.debugger.HandleCommand('thread return')
4 changes: 2 additions & 2 deletions commands/FBFlickerCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def inputCallback(self, input):
if isMac:
recursionName = '_subtreeDescription'

lldb.debugger.HandleCommand('po [(id)' + oldView + ' ' + recusionName + ']')
lldb.debugger.HandleCommand('poobjc (NSString *)[(id)' + oldView + ' ' + recusionName + ']')
else:
print '\nI really have no idea what you meant by \'' + input + '\'... =\\\n'

Expand All @@ -121,7 +121,7 @@ def setCurrentView(self, view, oldView=None):
if oldView:
viewHelpers.unmaskView(oldView)
viewHelpers.maskView(self.currentView, 'red', '0.4')
lldb.debugger.HandleCommand('po (id)' + view)
lldb.debugger.HandleCommand('poobjc (id)' + view)

def superviewOfView(view):
superview = fb.evaluateObjectExpression('[' + view + ' superview]')
Expand Down
4 changes: 2 additions & 2 deletions commands/FBInvocationCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def prettyPrintInvocation(frame, invocation):
for argDescription in argDescriptions:
s = re.sub(r'argument [0-9]+: ', '', argDescription)

lldb.debugger.HandleCommand('expr void *$v')
lldb.debugger.HandleCommand('expr (void)[' + invocation + ' getArgument:&$v atIndex:' + str(index) + ']')
lldb.debugger.HandleCommand('eobjc void *$v')
lldb.debugger.HandleCommand('eobjc (void)[' + invocation + ' getArgument:&$v atIndex:' + str(index) + ']')

address = findArgAdressAtIndexFromStackFrame(frame, index)

Expand Down
122 changes: 117 additions & 5 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def lldbcommands():
FBPrintTargetActions(),
FBPrintJSON(),
FBPrintAsCurl(),
FBPrintInObjc(),
FBPrintInSwift(),
FBPrintObjectInObjc(),
FBPrintObjectInSwift(),
FBExpressionInObjc(),
FBExpressionInSwift(),
]

class FBPrintViewHierarchyCommand(fb.FBCommand):
Expand Down Expand Up @@ -91,7 +97,7 @@ def description(self):
return 'Print layer tree from the perspective of the render server.'

def run(self, arguments, options):
lldb.debugger.HandleCommand('po [NSString stringWithCString:(char *)CARenderServerGetInfo(0, 2, 0)]')
lldb.debugger.HandleCommand('poobjc (NSString *)[NSString stringWithCString:(char *)CARenderServerGetInfo(0, 2, 0)]')


class FBPrintViewControllerHierarchyCommand(fb.FBCommand):
Expand All @@ -109,7 +115,7 @@ def run(self, arguments, options):

if arguments[0] == '__keyWindow_rootVC_dynamic__':
if fb.evaluateBooleanExpression('[UIViewController respondsToSelector:@selector(_printHierarchy)]'):
lldb.debugger.HandleCommand('po [UIViewController _printHierarchy]')
lldb.debugger.HandleCommand('poobjc (NSString *)[UIViewController _printHierarchy]')
return

arguments[0] = '(id)[(id)[[UIApplication sharedApplication] keyWindow] rootViewController]'
Expand Down Expand Up @@ -280,7 +286,7 @@ def run(self, arguments, options):
ivarTypeCommand = '((char *)ivar_getTypeEncoding((void*)object_getInstanceVariable((id){}, \"{}\", 0)))[0]'.format(object, ivarName)
ivarTypeEncodingFirstChar = fb.evaluateExpression(ivarTypeCommand)

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

class FBPrintKeyPath(fb.FBCommand):
Expand All @@ -302,7 +308,7 @@ def run(self, arguments, options):
else:
objectToMessage, keypath = command.split('.', 1)
object = fb.evaluateObjectExpression(objectToMessage)
printCommand = 'po [{} valueForKeyPath:@"{}"]'.format(object, keypath)
printCommand = 'poobjc (id)[{} valueForKeyPath:@"{}"]'.format(object, keypath)
lldb.debugger.HandleCommand(printCommand)


Expand Down Expand Up @@ -399,7 +405,7 @@ def run(self, arguments, option):
elif encoding_text == 'utf32l':
enc = 0x9c000100

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

class FBPrintTargetActions(fb.FBCommand):
Expand Down Expand Up @@ -516,3 +522,109 @@ def run(self, arguments, options):

commandString += ' "{}"'.format(URL)
print commandString

class FBPrintInObjc(fb.FBCommand):
def name(self):
return 'pobjc'

def description(self):
return 'Print the expression result, with the expression run in an ObjC++ context. (Shortcut for "expression -l ObjC++ -- " )'

def args(self):
return [
fb.FBCommandArgument(arg='expression', help='ObjC expression to evaluate and print.'),
]

def run(self, arguments, options):
expression = arguments[0]
lldb.debugger.HandleCommand('expression -l ObjC++ -- ' + expression)

class FBPrintInSwift(fb.FBCommand):
def name(self):
return 'pswift'

def description(self):
return 'Print the expression result, with the expression run in a Swift context. (Shortcut for "expression -l Swift -- " )'

def args(self):
return [
fb.FBCommandArgument(arg='expression', help='Swift expression to evaluate and print.'),
]

def run(self, arguments, options):
expression = arguments[0]
lldb.debugger.HandleCommand('expression -l Swift -- ' + expression)

class FBPrintObjectInObjc(fb.FBCommand):
def name(self):
return 'poobjc'

def description(self):
return 'Print the expression result, with the expression run in an ObjC++ context. (Shortcut for "expression -O -l ObjC++ -- " )'

def args(self):
return [
fb.FBCommandArgument(arg='expression', help='ObjC expression to evaluate and print.'),
]

def run(self, arguments, options):
expression = arguments[0]
lldb.debugger.HandleCommand('expression -O -l ObjC++ -- ' + expression)

class FBPrintObjectInSwift(fb.FBCommand):
def name(self):
return 'poswift'

def description(self):
return 'Print the expression result, with the expression run in a Swift context. (Shortcut for "expression -O -l Swift -- " )'

def args(self):
return [
fb.FBCommandArgument(arg='expression', help='Swift expression to evaluate and print.'),
]

def run(self, arguments, options):
expression = arguments[0]
lldb.debugger.HandleCommand('expression -O -l Swift -- ' + expression)

class FBExpressionInObjc(fb.FBCommand):
def name(self):
return 'eobjc'

def description(self):
return 'Run expression run in an ObjC++ context. (Shortcut for "expression -l ObjC++" )'

def args(self):
return [
fb.FBCommandArgument(arg='expression', help='ObjC expression to evaluate and print.'),
]

def run(self, arguments, options):
values = arguments[0].split("--", 1)
if len(values) is 2:
(arguments, expression) = arguments
lldb.debugger.HandleCommand('expression -l ObjC++ ' + arguments + " -- " + expression)
else:
expression = arguments[0]
lldb.debugger.HandleCommand('expression -l ObjC++ -- ' + expression)

class FBExpressionInSwift(fb.FBCommand):
def name(self):
return 'eswift'

def description(self):
return 'Run expression run in a Swift context. (Shortcut for "expression -l Swift" )'

def args(self):
return [
fb.FBCommandArgument(arg='expression', help='Swift expression to evaluate and print.'),
]

def run(self, arguments, options):
values = arguments[0].split("--", 1)
if len(values) is 2:
(arguments, expression) = arguments
lldb.debugger.HandleCommand('expression -l Swift ' + arguments + " -- " + expression)
else:
expression = arguments[0]
lldb.debugger.HandleCommand('expression -l Swift -- ' + expression)
16 changes: 8 additions & 8 deletions commands/FBVisualizationCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def _showColor(color):
colorToUse = '[UIColor colorWithCIColor:(CIColor *){}]'.format(color)

imageSize = 58
lldb.debugger.HandleCommand('expr (void)UIGraphicsBeginImageContextWithOptions((CGSize)CGSizeMake({imageSize}, {imageSize}), NO, 0.0)'.format(imageSize=imageSize))
lldb.debugger.HandleCommand('expr (void)[(id){} setFill]'.format(colorToUse))
lldb.debugger.HandleCommand('expr (void)UIRectFill((CGRect)CGRectMake(0.0, 0.0, {imageSize}, {imageSize}))'.format(imageSize=imageSize))
lldb.debugger.HandleCommand('eobjc (void)UIGraphicsBeginImageContextWithOptions((CGSize)CGSizeMake({imageSize}, {imageSize}), NO, 0.0)'.format(imageSize=imageSize))
lldb.debugger.HandleCommand('eobjc (void)[(id){} setFill]'.format(colorToUse))
lldb.debugger.HandleCommand('eobjc (void)UIRectFill((CGRect)CGRectMake(0.0, 0.0, {imageSize}, {imageSize}))'.format(imageSize=imageSize))

frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame()
result = frame.EvaluateExpression('(UIImage *)UIGraphicsGetImageFromCurrentImageContext()')
Expand All @@ -96,7 +96,7 @@ def _showColor(color):
image = result.GetValue()
_showImage(image)

lldb.debugger.HandleCommand('expr (void)UIGraphicsEndImageContext()')
lldb.debugger.HandleCommand('eobjc (void)UIGraphicsEndImageContext()')

def _showLayer(layer):
layer = '(' + layer + ')'
Expand All @@ -108,8 +108,8 @@ def _showLayer(layer):
print 'Nothing to see here - the size of this element is {} x {}.'.format(width, height)
return

lldb.debugger.HandleCommand('expr (void)UIGraphicsBeginImageContextWithOptions(' + size + ', NO, 0.0)')
lldb.debugger.HandleCommand('expr (void)[(id)' + layer + ' renderInContext:(void *)UIGraphicsGetCurrentContext()]')
lldb.debugger.HandleCommand('eobjc (void)UIGraphicsBeginImageContextWithOptions(' + size + ', NO, 0.0)')
lldb.debugger.HandleCommand('eobjc (void)[(id)' + layer + ' renderInContext:(void *)UIGraphicsGetCurrentContext()]')

frame = lldb.debugger.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame()
result = frame.EvaluateExpression('(UIImage *)UIGraphicsGetImageFromCurrentImageContext()')
Expand All @@ -119,7 +119,7 @@ def _showLayer(layer):
image = result.GetValue()
_showImage(image)

lldb.debugger.HandleCommand('expr (void)UIGraphicsEndImageContext()')
lldb.debugger.HandleCommand('eobjc (void)UIGraphicsEndImageContext()')

def _dataIsImage(data):
data = '(' + data + ')'
Expand Down Expand Up @@ -163,7 +163,7 @@ def _visualize(target):
if _dataIsImage(target):
_showImage('(id)[UIImage imageWithData:' + target + ']')
elif _dataIsString(target):
lldb.debugger.HandleCommand('po (NSString*)[[NSString alloc] initWithData:' + target + ' encoding:4]')
lldb.debugger.HandleCommand('poobjc (NSString*)[[NSString alloc] initWithData:' + target + ' encoding:4]')
else:
print 'Data isn\'t an image and isn\'t a string.'
else:
Expand Down
16 changes: 8 additions & 8 deletions fblldbviewhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import fblldbobjcruntimehelpers as runtimeHelpers

def flushCoreAnimationTransaction():
lldb.debugger.HandleCommand('expr (void)[CATransaction flush]')
lldb.debugger.HandleCommand('eobjc (void)[CATransaction flush]')

def setViewHidden(object, hidden):
lldb.debugger.HandleCommand('expr (void)[' + object + ' setHidden:' + str(int(hidden)) + ']')
lldb.debugger.HandleCommand('eobjc (void)[' + object + ' setHidden:' + str(int(hidden)) + ']')
flushCoreAnimationTransaction()

def maskView(viewOrLayer, color, alpha):
Expand All @@ -31,16 +31,16 @@ def maskView(viewOrLayer, color, alpha):
size.GetChildMemberWithName('height').GetValue())
mask = fb.evaluateExpression('(id)[[UIView alloc] initWithFrame:%s]' % rectExpr)

lldb.debugger.HandleCommand('expr (void)[%s setTag:(NSInteger)%s]' % (mask, viewOrLayer))
lldb.debugger.HandleCommand('expr (void)[%s setBackgroundColor:[UIColor %sColor]]' % (mask, color))
lldb.debugger.HandleCommand('expr (void)[%s setAlpha:(CGFloat)%s]' % (mask, alpha))
lldb.debugger.HandleCommand('expr (void)[%s addSubview:%s]' % (window, mask))
lldb.debugger.HandleCommand('eobjc (void)[%s setTag:(NSInteger)%s]' % (mask, viewOrLayer))
lldb.debugger.HandleCommand('eobjc (void)[%s setBackgroundColor:[UIColor %sColor]]' % (mask, color))
lldb.debugger.HandleCommand('eobjc (void)[%s setAlpha:(CGFloat)%s]' % (mask, alpha))
lldb.debugger.HandleCommand('eobjc (void)[%s addSubview:%s]' % (window, mask))
flushCoreAnimationTransaction()

def unmaskView(viewOrLayer):
window = fb.evaluateExpression('(UIWindow *)[[UIApplication sharedApplication] keyWindow]')
mask = fb.evaluateExpression('(UIView *)[%s viewWithTag:(NSInteger)%s]' % (window, viewOrLayer))
lldb.debugger.HandleCommand('expr (void)[%s removeFromSuperview]' % mask)
lldb.debugger.HandleCommand('eobjc (void)[%s removeFromSuperview]' % mask)
flushCoreAnimationTransaction()

def convertPoint(x, y, fromViewOrLayer, toViewOrLayer):
Expand Down Expand Up @@ -113,4 +113,4 @@ def upwardsRecursiveDescription(view, maxDepth=0):
return builder

def slowAnimation(speed=1):
lldb.debugger.HandleCommand('expr (void)[[[UIApplication sharedApplication] windows] setValue:@(%s) forKeyPath:@"layer.speed"]' % speed)
lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] windows] setValue:@(%s) forKeyPath:@"layer.speed"]' % speed)