@@ -153,16 +153,16 @@ pass them to the Python print function:
153
153
154
154
(lldb) script
155
155
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
156
- >>> print lldb.debugger
156
+ >>> print( lldb.debugger)
157
157
Debugger (instance: "debugger_1", id: 1)
158
- >>> print lldb.target
158
+ >>> print( lldb.target)
159
159
a.out
160
- >>> print lldb.process
161
- SBProcess: pid = 59289 , state = stopped, threads = 1, executable = a.out
162
- >>> print lldb.thread
163
- SBThread : tid = 0x1f03
164
- >>> print lldb.frame
165
- frame #0: 0x0000000100000bb6 a.out main + 54 at main .c:16
160
+ >>> print( lldb.process)
161
+ SBProcess: pid = 58842 , state = stopped, threads = 1, executable = a.out
162
+ >>> print( lldb.thread)
163
+ thread #1 : tid = 0x2265ce3, 0x0000000100000334 a.out`main at t.c:2:3, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
164
+ >>> print( lldb.frame)
165
+ frame #0: 0x0000000100000334 a.out` main at t .c:2:3
166
166
167
167
168
168
Running a python script when a breakpoint gets hit
@@ -252,7 +252,7 @@ Here is the code:
252
252
> # Get the name of the function
253
253
> name = frame.GetFunctionName()
254
254
> # Print the order and the function name
255
- > print '[%i] %s' % (counter, name)
255
+ > print( '[%i] %s' % (counter, name) )
256
256
> # Disable the current breakpoint location so it doesn't get hit again
257
257
> bp_loc.SetEnabled(False)
258
258
> # No need to stop here
588
588
589
589
.. code- block:: python
590
590
591
- print >> result, " my command does lots of cool stuff"
591
+ print ( " my command does lots of cool stuff" , file = result)
592
592
593
593
SBCommandReturnObject and SBStream both support this file - like behavior by
594
594
providing write() and flush() calls at the Python layer.
@@ -712,7 +712,7 @@ your lldb.ParsedCommand subclass should implement:
712
712
"""
713
713
714
714
And to handle the completion of arguments:
715
-
715
+
716
716
.. code-block :: python
717
717
718
718
def handle_argument_completion (self , args , arg_pos , cursor_pos ):
@@ -826,7 +826,7 @@ a function that can be used by LLDB's python command code:
826
826
# And the initialization code to add your commands
827
827
def __lldb_init_module (debugger , internal_dict ):
828
828
debugger.HandleCommand(' command script add -f ls.ls ls' )
829
- print ' The "ls" python command has been installed and is ready for use.'
829
+ print ( ' The "ls" python command has been installed and is ready for use.' )
830
830
831
831
Now we can load the module into LLDB and use it
832
832
@@ -964,16 +964,18 @@ script that will launch a program from the current working directory called
964
964
"a.out", set a breakpoint at "main", and then run and hit the breakpoint, and
965
965
print the process, thread and frame objects if the process stopped:
966
966
967
- ::
967
+ .. code-block :: python
968
968
969
- #!/usr/bin/env python
969
+ # !/usr/bin/env python3
970
970
971
971
import lldb
972
972
import os
973
973
974
+
974
975
def disassemble_instructions (insts ):
975
976
for i in insts:
976
- print i
977
+ print (i)
978
+
977
979
978
980
# Set the path to the executable to debug
979
981
exe = " ./a.out"
@@ -983,54 +985,56 @@ print the process, thread and frame objects if the process stopped:
983
985
984
986
# When we step or continue, don't return from the function until the process
985
987
# stops. Otherwise we would have to handle the process events ourselves which, while doable is
986
- #a little tricky. We do this by setting the async mode to false.
987
- debugger.SetAsync (False)
988
+ # a little tricky. We do this by setting the async mode to false.
989
+ debugger.SetAsync(False )
988
990
989
991
# Create a target from a file and arch
990
- print "Creating a target for '%s'" % exe
992
+ print ( " Creating a target for '%s '" % exe)
991
993
992
- target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)
994
+ target = debugger.CreateTargetWithFileAndArch(exe, lldb.LLDB_ARCH_DEFAULT )
993
995
994
996
if target:
995
997
# If the target is valid set a breakpoint at main
996
- main_bp = target.BreakpointCreateByName ("main", target.GetExecutable().GetFilename());
998
+ main_bp = target.BreakpointCreateByName(
999
+ " main" , target.GetExecutable().GetFilename()
1000
+ )
997
1001
998
- print main_bp
1002
+ print ( main_bp)
999
1003
1000
1004
# Launch the process. Since we specified synchronous mode, we won't return
1001
1005
# from this function until we hit the breakpoint at main
1002
- process = target.LaunchSimple (None, None, os.getcwd())
1006
+ process = target.LaunchSimple(None , None , os.getcwd())
1003
1007
1004
1008
# Make sure the launch went ok
1005
1009
if process:
1006
1010
# Print some simple process info
1007
- state = process.GetState ()
1008
- print process
1011
+ state = process.GetState()
1012
+ print ( process)
1009
1013
if state == lldb.eStateStopped:
1010
1014
# Get the first thread
1011
- thread = process.GetThreadAtIndex (0)
1015
+ thread = process.GetThreadAtIndex(0 )
1012
1016
if thread:
1013
1017
# Print some simple thread info
1014
- print thread
1018
+ print ( thread)
1015
1019
# Get the first frame
1016
- frame = thread.GetFrameAtIndex (0)
1020
+ frame = thread.GetFrameAtIndex(0 )
1017
1021
if frame:
1018
1022
# Print some simple frame info
1019
- print frame
1023
+ print ( frame)
1020
1024
function = frame.GetFunction()
1021
1025
# See if we have debug info (a function)
1022
1026
if function:
1023
1027
# We do have a function, print some info for the function
1024
- print function
1028
+ print ( function)
1025
1029
# Now get all instructions for this function and print them
1026
1030
insts = function.GetInstructions(target)
1027
- disassemble_instructions (insts)
1031
+ disassemble_instructions(insts)
1028
1032
else :
1029
1033
# See if we have a symbol in the symbol table for where we stopped
1030
- symbol = frame.GetSymbol();
1034
+ symbol = frame.GetSymbol()
1031
1035
if symbol:
1032
1036
# We do have a symbol, print some info for the symbol
1033
- print symbol
1037
+ print ( symbol)
1034
1038
1035
1039
Writing lldb frame recognizers in Python
1036
1040
----------------------------------------
0 commit comments