summaryrefslogtreecommitdiffstats
path: root/lldb/examples/python
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-01-22 02:55:08 +0000
committerGreg Clayton <gclayton@apple.com>2012-01-22 02:55:08 +0000
commitd879a6305ba6990e678ac7d00323a8416c70cd80 (patch)
tree1304d16cd0ed3386724b32c4cbe7717da9952a12 /lldb/examples/python
parente476f979ca2614775ea8454c10983011da68ed33 (diff)
downloadbcm5719-llvm-d879a6305ba6990e678ac7d00323a8416c70cd80.tar.gz
bcm5719-llvm-d879a6305ba6990e678ac7d00323a8416c70cd80.zip
Added a python FAQ page with detailed examples of how to add python functions
to breakpoints, creating new LLDB commands using python modules and also how to run scripts from the command line. llvm-svn: 148650
Diffstat (limited to 'lldb/examples/python')
-rw-r--r--lldb/examples/python/cmdtemplate.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/lldb/examples/python/cmdtemplate.py b/lldb/examples/python/cmdtemplate.py
new file mode 100644
index 00000000000..12192e9b916
--- /dev/null
+++ b/lldb/examples/python/cmdtemplate.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+
+#----------------------------------------------------------------------
+# Be sure to add the python path that points to the LLDB shared library.
+#
+# To use this in the embedded python interpreter using "lldb":
+# % cd /path/containing/cmdtemplate.py
+# % lldb
+# (lldb) script import cmdtemplate
+#
+# For the shells csh, tcsh:
+# ( setenv PYTHONPATH /path/to/LLDB.framework/Resources/Python ; ./cmdtemplate.py )
+#
+# For the shells sh, bash:
+# PYTHONPATH=/path/to/LLDB.framework/Resources/Python ./cmdtemplate.py
+#----------------------------------------------------------------------
+
+import lldb
+import commands
+import optparse
+import shlex
+
+def ls(debugger, command, result, dict):
+ command_args = shlex.split(command)
+ usage = "usage: %prog [options] <PATH> [PATH ...]"
+ description='''This command lets you run the /bin/ls command from within lldb as a quick and easy example.'''
+ parser = optparse.OptionParser(description=description, prog='ls',usage=usage)
+ parser.add_option('-v', '--verbose', action='store_true', dest='verbose', help='display verbose debug info', default=False)
+ try:
+ (options, args) = parser.parse_args(command_args)
+ except:
+ return
+
+ for arg in args:
+ if options.verbose:
+ print commands.getoutput('/bin/ls "%s"' % arg)
+ else:
+ print commands.getoutput('/bin/ls -lAF "%s"' % arg)
+
+if __name__ == '__main__':
+ # This script is being run from the command line, create a debugger in case we are
+ # going to use any debugger functions in our function.
+ lldb.debugger = lldb.SBDebugger.Create()
+ ls (sys.argv)
+elif lldb.debugger:
+ # This script is being run from LLDB in the emabedded command interpreter
+ # Add any commands contained in this module to LLDB
+ lldb.debugger.HandleCommand('command script add -f cmdtemplate.ls ls')
+ print '"ls" command installed, type "ls --help" for detailed help'
OpenPOWER on IntegriCloud