Greg Clayton | f9ab5ea | 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 | # |
| 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 | |
| 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: |
| 36 | print commands.getoutput('/bin/ls "%s"' % arg) |
| 37 | else: |
| 38 | print commands.getoutput('/bin/ls -lAF "%s"' % arg) |
| 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) |
| 45 | elif lldb.debugger: |
| 46 | # This script is being run from LLDB in the emabedded command interpreter |
| 47 | # Add any commands contained in this module to LLDB |
| 48 | lldb.debugger.HandleCommand('command script add -f cmdtemplate.ls ls') |
| 49 | print '"ls" command installed, type "ls --help" for detailed help' |