| Greg Clayton | d879a63 | 2012-01-22 02:55:08 +0000 | [diff] [blame] | 1 | #!/usr/bin/python | 
|  | 2 |  | 
|  | 3 | #---------------------------------------------------------------------- | 
|  | 4 | # Be sure to add the python path that points to the LLDB shared library. | 
|  | 5 | # | 
| Greg Clayton | e284163 | 2012-01-26 02:56:24 +0000 | [diff] [blame] | 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 | 
| Greg Clayton | d879a63 | 2012-01-22 02:55:08 +0000 | [diff] [blame] | 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 |  | 
|  | 18 | import lldb | 
|  | 19 | import commands | 
|  | 20 | import optparse | 
|  | 21 | import shlex | 
|  | 22 |  | 
|  | 23 | def 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 Ingham | 87a5936 | 2012-01-24 02:40:42 +0000 | [diff] [blame] | 36 | result.PutCString(commands.getoutput('/bin/ls "%s"' % arg)) | 
| Greg Clayton | d879a63 | 2012-01-22 02:55:08 +0000 | [diff] [blame] | 37 | else: | 
| Jim Ingham | 87a5936 | 2012-01-24 02:40:42 +0000 | [diff] [blame] | 38 | result.PutCString(commands.getoutput('/bin/ls -lAF "%s"' % arg)) | 
| Greg Clayton | d879a63 | 2012-01-22 02:55:08 +0000 | [diff] [blame] | 39 |  | 
|  | 40 | if __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 Ingham | 87a5936 | 2012-01-24 02:40:42 +0000 | [diff] [blame] | 45 |  | 
|  | 46 | def __lldb_init_module (debugger, dict): | 
|  | 47 | # This initializer is being run from LLDB in the embedded command interpreter | 
| Greg Clayton | d879a63 | 2012-01-22 02:55:08 +0000 | [diff] [blame] | 48 | # Add any commands contained in this module to LLDB | 
| Jim Ingham | 87a5936 | 2012-01-24 02:40:42 +0000 | [diff] [blame] | 49 | debugger.HandleCommand('command script add -f cmdtemplate.ls ls') | 
| Greg Clayton | d879a63 | 2012-01-22 02:55:08 +0000 | [diff] [blame] | 50 | print '"ls" command installed, type "ls --help" for detailed help' |