diff options
author | Daniel Malea <daniel.malea@intel.com> | 2013-02-11 17:18:14 +0000 |
---|---|---|
committer | Daniel Malea <daniel.malea@intel.com> | 2013-02-11 17:18:14 +0000 |
commit | ac4ce0cd4a5562faf71fd88d8c72dbb0edf312e8 (patch) | |
tree | 327008ce2d06c3bbee826bd5e3d31b8c260e3a52 /lldb/utils/vim-lldb/python-vim-lldb/import_lldb.py | |
parent | 09995ac0693adaa899015dec8fff528a278099c1 (diff) | |
download | bcm5719-llvm-ac4ce0cd4a5562faf71fd88d8c72dbb0edf312e8.tar.gz bcm5719-llvm-ac4ce0cd4a5562faf71fd88d8c72dbb0edf312e8.zip |
Add Vim frontend to LLDB.
- Access any LLDB CLI command in Vim by typing ":L<command>". Tab-completion
works too!
- See source locations for breakpoints and the current PC with vim "marks"
and highlights.
- Examine backtraces, locals, disassembly, registers, and breakpoints in
dedicated Vim windows.
- See when in-scope variables and registers change by watching for (red)
highlights.
This plugin opens multiple Vim "windows" to display debugger information.
To quit all windows at the same time use ":qa". The alternative would be
":q" to close each window separately.
This plugin is known to work on Mac OS X (Mountain Lion) with MacVim and
the system-provided terminal Vim, and on Linux (Ubuntu 12.04 and 12.10)
with GVim and the terminal Vim from the "vim-gnome" package.
llvm-svn: 174892
Diffstat (limited to 'lldb/utils/vim-lldb/python-vim-lldb/import_lldb.py')
-rw-r--r-- | lldb/utils/vim-lldb/python-vim-lldb/import_lldb.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lldb/utils/vim-lldb/python-vim-lldb/import_lldb.py b/lldb/utils/vim-lldb/python-vim-lldb/import_lldb.py new file mode 100644 index 00000000000..a2145d50466 --- /dev/null +++ b/lldb/utils/vim-lldb/python-vim-lldb/import_lldb.py @@ -0,0 +1,61 @@ + +# Locate and load the lldb python module + +import os, sys + +def import_lldb(): + """ Find and import the lldb modules. This function tries to find the lldb module by: + 1. Simply by doing "import lldb" in case the system python installation is aware of lldb. If that fails, + 2. Executes the lldb executable pointed to by the LLDB environment variable (or if unset, the first lldb + on PATH") with the -P flag to determine the PYTHONPATH to set. If the lldb executable returns a valid + path, it is added to sys.path and the import is attempted again. If that fails, 3. On Mac OS X the + default Xcode 4.5 installation path. + """ + + # Try simple 'import lldb', in case of a system-wide install or a pre-configured PYTHONPATH + try: + import lldb + return True + except ImportError: + pass + + # Allow overriding default path to lldb executable with the LLDB environment variable + lldb_executable = 'lldb' + if 'LLDB' in os.environ and os.path.exists(os.environ['LLDB']): + lldb_executable = os.environ['LLDB'] + + # Try using builtin module location support ('lldb -P') + from subprocess import check_output, CalledProcessError + try: + with open(os.devnull, 'w') as fnull: + lldb_minus_p_path = check_output("%s -P" % lldb_executable, shell=True, stderr=fnull).strip() + if not os.path.exists(lldb_minus_p_path): + #lldb -P returned invalid path, probably too old + pass + else: + sys.path.append(lldb_minus_p_path) + import lldb + return True + except CalledProcessError: + # Cannot run 'lldb -P' to determine location of lldb python module + pass + except ImportError: + # Unable to import lldb module from path returned by `lldb -P` + pass + + # On Mac OS X, use the try the default path to XCode lldb module + if "darwin" in sys.platform: + xcode_python_path = "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/Current/Resources/Python/" + sys.path.append(xcode_python_path) + try: + import lldb + return True + except ImportError: + # Unable to import lldb module from default Xcode python path + pass + + return False + +if not import_lldb(): + import vim + vim.command('redraw | echo "%s"' % " Error loading lldb module; vim-lldb will be disabled. Check LLDB installation or set LLDB environment variable.") |