blob: b7ad0a373de2098da691347ed1545696aede4579 [file] [log] [blame]
Greg Claytonf9ab5ea2012-01-22 02:55:08 +00001#!/usr/bin/python
2
3#----------------------------------------------------------------------
4# Be sure to add the python path that points to the LLDB shared library.
5#
6# To use this in the embedded python interpreter using "lldb":
7# % cd /path/containing/cmdtemplate.py
8# % lldb
9# (lldb) script import cmdtemplate
10#
11# For the shells csh, tcsh:
12# ( setenv PYTHONPATH /path/to/LLDB.framework/Resources/Python ; ./cmdtemplate.py )
13#
14# For the shells sh, bash:
15# PYTHONPATH=/path/to/LLDB.framework/Resources/Python ./cmdtemplate.py
16#----------------------------------------------------------------------
17
18import lldb
19import commands
20import optparse
21import shlex
22
23def ls(debugger, command, result, dict):
24 command_args = shlex.split(command)
25 usage = "usage: %prog [options] <PATH> [PATH ...]"
26 description='''This command lets you run the /bin/ls command from within lldb as a quick and easy example.'''
27 parser = optparse.OptionParser(description=description, prog='ls',usage=usage)
28 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', help='display verbose debug info', default=False)
29 try:
30 (options, args) = parser.parse_args(command_args)
31 except:
32 return
33
34 for arg in args:
35 if options.verbose:
Jim Ingham062a8362012-01-24 02:40:42 +000036 result.PutCString(commands.getoutput('/bin/ls "%s"' % arg))
Greg Claytonf9ab5ea2012-01-22 02:55:08 +000037 else:
Jim Ingham062a8362012-01-24 02:40:42 +000038 result.PutCString(commands.getoutput('/bin/ls -lAF "%s"' % arg))
Greg Claytonf9ab5ea2012-01-22 02:55:08 +000039
40if __name__ == '__main__':
41 # This script is being run from the command line, create a debugger in case we are
42 # going to use any debugger functions in our function.
43 lldb.debugger = lldb.SBDebugger.Create()
44 ls (sys.argv)
Jim Ingham062a8362012-01-24 02:40:42 +000045
46def __lldb_init_module (debugger, dict):
47 # This initializer is being run from LLDB in the embedded command interpreter
Greg Claytonf9ab5ea2012-01-22 02:55:08 +000048 # Add any commands contained in this module to LLDB
Jim Ingham062a8362012-01-24 02:40:42 +000049 debugger.HandleCommand('command script add -f cmdtemplate.ls ls')
Greg Claytonf9ab5ea2012-01-22 02:55:08 +000050 print '"ls" command installed, type "ls --help" for detailed help'