cmdtemplate.py revision 47fdb0f9cc01d79ed15cb8c80ea5c4c2f381490d
1#!/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" just 7# import it with the full path using the "command script import" 8# command 9# (lldb) command script import /path/to/cmdtemplate.py 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: 36 result.PutCString(commands.getoutput('/bin/ls "%s"' % arg)) 37 else: 38 result.PutCString(commands.getoutput('/bin/ls -lAF "%s"' % arg)) 39 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) 45 46def __lldb_init_module (debugger, dict): 47 # This initializer is being run from LLDB in the embedded command interpreter 48 # Add any commands contained in this module to LLDB 49 debugger.HandleCommand('command script add -f cmdtemplate.ls ls') 50 print '"ls" command installed, type "ls --help" for detailed help' 51