summaryrefslogtreecommitdiffstats
path: root/lldb/examples/python/disasm.py
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2010-10-06 03:53:16 +0000
committerGreg Clayton <gclayton@apple.com>2010-10-06 03:53:16 +0000
commit5d5028b54eba2d6a0c0b7b0abbb2af40977a53a4 (patch)
tree57991d7749b54ecf3d30f9b175729921c4e9d6fa /lldb/examples/python/disasm.py
parent964f521e859423bbfb66e329e6d487f799588039 (diff)
downloadbcm5719-llvm-5d5028b54eba2d6a0c0b7b0abbb2af40977a53a4.tar.gz
bcm5719-llvm-5d5028b54eba2d6a0c0b7b0abbb2af40977a53a4.zip
Added the first of hopefully many python example scripts that show how to
use the python API that is exposed through SWIG to do some cool stuff. Also fixed synchronous debugging so that all process control APIs exposed through the python API will now wait for the process to stop if you set the async mode to false (see disasm.py). llvm-svn: 115738
Diffstat (limited to 'lldb/examples/python/disasm.py')
-rwxr-xr-xlldb/examples/python/disasm.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/lldb/examples/python/disasm.py b/lldb/examples/python/disasm.py
new file mode 100755
index 00000000000..f6868e6e4ea
--- /dev/null
+++ b/lldb/examples/python/disasm.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+
+#----------------------------------------------------------------------
+# Be sure to add the python path that points to the LLDB shared library.
+# On MacOSX csh, tcsh:
+# setenv PYTHONPATH /Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
+# On MacOSX sh, bash:
+# export PYTHONPATH=/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
+#----------------------------------------------------------------------
+
+import lldb
+import os
+import sys
+import time
+
+def disassemble_instructions (insts):
+ for i in range(0, insts.GetSize()):
+ print insts.GetInstructionAtIndex(i)
+
+# Initialize LLDB so we can use it
+lldb.SBDebugger.Initialize()
+
+# Create a new debugger instance
+debugger = lldb.SBDebugger.Create()
+
+# When we step or continue, don't return from the function until the process
+# stops. We do this by setting the async mode to false.
+debugger.SetAsync (False)
+
+# Create a target from a file and arch
+target = debugger.CreateTargetWithFileAndArch (sys.argv[1], "x86_64")
+
+if target.IsValid():
+ # If the target is valid set a breakpoint at main
+ main_bp = target.BreakpointCreateByName ("main", "a.out");
+
+ # Launch the process. Since we specified synchronous mode, we won't return
+ # from this function until we hit the breakpoint at main
+ process = target.LaunchProcess (sys.argv[2:], [''], "dev/stdout", 0, False)
+
+ # Make sure the launch went ok
+ if process.IsValid():
+ # Print some simple process info
+ print "process:", process, "\n"
+ # Get the first thread
+ thread = process.GetThreadAtIndex (0)
+ if thread.IsValid():
+ # Print some simple thread info
+ print "thread: ", thread
+ # Get the first frame
+ frame = thread.GetFrameAtIndex (0)
+ if frame.IsValid():
+ # Print some simple frame info
+ print "frame: ", frame
+ function = frame.GetFunction()
+ # See if we have debug info (a function)
+ if function.IsValid():
+ # We do have a function, print some info for the function
+ print "function: ", function, "\n"
+ # Now get all instructions for this function and print them
+ insts = function.GetInstructions(target)
+ disassemble_instructions (insts)
+ else:
+ # See if we have a symbol in the symbol table for where we stopped
+ symbol = frame.GetSymbol();
+ if symbol.IsValid():
+ # We do have a symbol, print some info for the symbol
+ print "symbol: ", symbol, "\n"
+ # Now get all instructions for this symbol and print them
+ insts = symbol.GetInstructions(target)
+ disassemble_instructions (insts)
+ # Now continue to the program exit
+ process.Continue()
+ # When we return from the above function we will hopefully be at the
+ # program exit. Print out some process info
+ print "process:", process, "\n"
+
+
+lldb.SBDebugger.Terminate()
OpenPOWER on IntegriCloud