55# This source code is licensed under the MIT license found in the
66# LICENSE file in the root directory of this source tree.
77
8+ # Can be removed when Python 2 support is removed.
9+ from __future__ import print_function
10+
811import lldb
912import fblldbbase as fb
1013import fblldbobjcruntimehelpers as objc
@@ -58,9 +61,9 @@ def run(self, arguments, options):
5861 watchpoint = lldb .debugger .GetSelectedTarget ().WatchAddress (objectAddress + ivarOffset , ivarSize , False , True , error )
5962
6063 if error .Success ():
61- print 'Remember to delete the watchpoint using: watchpoint delete {}' .format (watchpoint .GetID ())
64+ print ( 'Remember to delete the watchpoint using: watchpoint delete {}' .format (watchpoint .GetID () ))
6265 else :
63- print 'Could not create the watchpoint: {}' .format (error .GetCString ())
66+ print ( 'Could not create the watchpoint: {}' .format (error .GetCString () ))
6467
6568class FBFrameworkAddressBreakpointCommand (fb .FBCommand ):
6669 def name (self ):
@@ -108,12 +111,12 @@ def run(self, arguments, options):
108111 match = methodPattern .match (expression )
109112
110113 if not match :
111- print 'Failed to parse expression. Do you even Objective-C?!'
114+ print ( 'Failed to parse expression. Do you even Objective-C?!' )
112115 return
113116
114117 expressionForSelf = objc .functionPreambleExpressionForSelf ()
115118 if not expressionForSelf :
116- print 'Your architecture, {}, is truly fantastic. However, I don\' t currently support it.' .format (arch )
119+ print ( 'Your architecture, {}, is truly fantastic. However, I don\' t currently support it.' .format (arch ) )
117120 return
118121
119122 methodTypeCharacter = match .group ('scope' )
@@ -139,7 +142,7 @@ def run(self, arguments, options):
139142 targetClass = fb .evaluateObjectExpression ('[{} class]' .format (targetObject ), False )
140143
141144 if not targetClass or int (targetClass , 0 ) == 0 :
142- print 'Couldn\' t find a class from the expression "{}". Did you typo?' .format (classNameOrExpression )
145+ print ( 'Couldn\' t find a class from the expression "{}". Did you typo?' .format (classNameOrExpression ) )
143146 return
144147
145148 if methodIsClassMethod :
@@ -155,7 +158,7 @@ def run(self, arguments, options):
155158 nextClass = objc .class_getSuperclass (nextClass )
156159
157160 if not found :
158- print 'There doesn\' t seem to be an implementation of {} in the class hierarchy. Made a boo boo with the selector name?' .format (selector )
161+ print ( 'There doesn\' t seem to be an implementation of {} in the class hierarchy. Made a boo boo with the selector name?' .format (selector ) )
159162 return
160163
161164 breakpointClassName = objc .class_getName (nextClass )
@@ -167,7 +170,7 @@ def run(self, arguments, options):
167170 else :
168171 breakpointCondition = '(void*){} == {}' .format (expressionForSelf , targetObject )
169172
170- print 'Setting a breakpoint at {} with condition {}' .format (breakpointFullName , breakpointCondition )
173+ print ( 'Setting a breakpoint at {} with condition {}' .format (breakpointFullName , breakpointCondition ) )
171174
172175 if category :
173176 lldb .debugger .HandleCommand ('breakpoint set --skip-prologue false --fullname "{}" --condition "{}"' .format (breakpointFullName , breakpointCondition ))
@@ -205,11 +208,11 @@ def switchBreakpointState(expression,on):
205208 target = lldb .debugger .GetSelectedTarget ()
206209 for breakpoint in target .breakpoint_iter ():
207210 if breakpoint .IsEnabled () != on and (expression_pattern .search (str (breakpoint ))):
208- print str (breakpoint )
211+ print ( str (breakpoint ) )
209212 breakpoint .SetEnabled (on )
210213 for location in breakpoint :
211214 if location .IsEnabled () != on and (expression_pattern .search (str (location )) or expression == hex (location .GetAddress ()) ):
212- print str (location )
215+ print ( str (location ) )
213216 location .SetEnabled (on )
214217
215218class FBMethodBreakpointEnableCommand (fb .FBCommand ):
@@ -330,7 +333,7 @@ def run(self, arguments, options):
330333 return
331334
332335 if len (arguments ) == 0 or not arguments [0 ].strip ():
333- print 'Usage: findinstances <classOrProtocol> [<predicate>]; Run `help findinstances`'
336+ print ( 'Usage: findinstances <classOrProtocol> [<predicate>]; Run `help findinstances`' )
334337 return
335338
336339 query = arguments [0 ]
@@ -348,7 +351,7 @@ def loadChiselIfNecessary(self):
348351
349352 path = self .chiselLibraryPath ()
350353 if not os .path .exists (path ):
351- print 'Chisel library missing: ' + path
354+ print ( 'Chisel library missing: ' + path )
352355 return False
353356
354357 module = fb .evaluateExpressionValue ('(void*)dlopen("{}", 2)' .format (path ))
@@ -361,17 +364,17 @@ def loadChiselIfNecessary(self):
361364 error = fb .evaluateExpressionValue ('(char*)dlerror()' )
362365 if errno == 50 :
363366 # KERN_CODESIGN_ERROR from <mach/kern_return.h>
364- print 'Error loading Chisel: Code signing failure; Must re-run codesign'
367+ print ( 'Error loading Chisel: Code signing failure; Must re-run codesign' )
365368 elif error .unsigned != 0 :
366- print 'Error loading Chisel: ' + error .summary
369+ print ( 'Error loading Chisel: ' + error .summary )
367370 elif errno != 0 :
368371 error = fb .evaluateExpressionValue ('(char*)strerror({})' .format (errno ))
369372 if error .unsigned != 0 :
370- print 'Error loading Chisel: ' + error .summary
373+ print ( 'Error loading Chisel: ' + error .summary )
371374 else :
372- print 'Error loading Chisel (errno {})' .format (errno )
375+ print ( 'Error loading Chisel (errno {})' .format (errno ) )
373376 else :
374- print 'Unknown error loading Chisel'
377+ print ( 'Unknown error loading Chisel' )
375378
376379 return False
377380
@@ -428,9 +431,9 @@ def isHeap(addr):
428431
429432 allocations = (addr for addr in pointers if isHeap (addr ))
430433 for addr in allocations :
431- print >> self . result , '0x{addr:x} {path}' .format (addr = addr , path = pointers [addr ])
434+ print ( '0x{addr:x} {path}' .format (addr = addr , path = pointers [addr ]), file = self . result )
432435 if not allocations :
433- print >> self . result , "No heap addresses found"
436+ print ( "No heap addresses found" , file = self . result )
434437
435438
436439class FBSequenceCommand (fb .FBCommand ):
@@ -453,17 +456,17 @@ def run(self, arguments, options):
453456
454457 # Complete one command before running the next one in the sequence. Disable
455458 # async to do this. Also, save the current async value to restore it later.
456- async = lldb .debugger .GetAsync ()
459+ asyncFlag = lldb .debugger .GetAsync ()
457460 lldb .debugger .SetAsync (False )
458461
459462 for command in commands [:- 1 ]:
460463 success = self .run_command (interpreter , command )
461464 if not success :
462- lldb .debugger .SetAsync (async )
465+ lldb .debugger .SetAsync (asyncFlag )
463466 return
464467
465468 # Restore original async value.
466- lldb .debugger .SetAsync (async )
469+ lldb .debugger .SetAsync (asyncFlag )
467470
468471 # If the last command is `continue`, call Continue() on the process
469472 # instead. This is done because HandleCommand('continue') has strange
@@ -478,7 +481,7 @@ def run_command(self, interpreter, command):
478481 ret = lldb .SBCommandReturnObject ()
479482 interpreter .HandleCommand (command , ret )
480483 if ret .GetOutput ():
481- print >> self . result , ret .GetOutput ().strip ()
484+ print ( ret .GetOutput ().strip (), file = self . result )
482485
483486 if ret .Succeeded ():
484487 return True
0 commit comments