Skip to content

Commit 46d9089

Browse files
committed
Import from the LLDB repo
0 parents  commit 46d9089

File tree

9 files changed

+1834
-0
lines changed

9 files changed

+1834
-0
lines changed

README

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
=================
3+
LLDB Vim Frontend
4+
=================
5+
6+
Prerequisites
7+
-------------
8+
9+
This plugin is known to work with the following flavours of Vim:
10+
11+
* Linux (tested on Ubuntu 12.04/12.10):
12+
* vim/gvim (from vim-gnome package version 7.3)
13+
14+
* Mac OS X (tested on Mountain Lion)
15+
* Vim command-line (7.3 from Xcode)
16+
* MacVim 7.3
17+
18+
To install the plugin, ensure you have
19+
* a working version of lldb on your path, or the environment variable LLDB
20+
pointing to the lldb binary you would like to use.
21+
* a python-enabled vim (check with ":python print 2")
22+
23+
24+
Installation
25+
------------
26+
27+
1) Install the Vim pathogen plugin (it keeps installed plugins organized):
28+
29+
https://github.com/tpope/vim-pathogen
30+
31+
Or, for the impatient:
32+
33+
mkdir -p ~/.vim/autoload ~/.vim/bundle; \
34+
curl -Sso ~/.vim/autoload/pathogen.vim \
35+
https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
36+
37+
2) Symlink (or copy) ~/.vim/bundle/vim-lldb to this directory:
38+
39+
ln -sf <lldb-dir>/utils/vim-lldb ~/.vim/bundle/vim-lldb
40+
41+
3) Update your help-tags. Start vim, do:
42+
43+
:Helptags
44+
45+
4) Have fun!
46+
47+
48+
Usage/Getting Help
49+
------------------
50+
All LLDB commands (with tab-completion) can be accessed in Vim's
51+
command mode. Try it out by typing:
52+
53+
:L<tab>
54+
55+
There are several sources of help available:
56+
57+
:help lldb -- Documentation for this plugin
58+
:Lhelp -- LLDB's built-in help system (i.e lldb 'help' command)
59+
:Lscript help (lldb) -- Complete LLDB Python API reference

doc/lldb.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
*lldb.txt* A plugin that enables debugging from your favourite editor
2+
3+
Author: Daniel Malea <daniel.malea@intel.com>
4+
License: Same terms as Vim itself (see |license|)
5+
6+
INTRODUCTION *lldb*
7+
8+
Installing this plugin enables a set of commands in Vim to control the
9+
LLDB (http://lldb.llvm.org) debugger.
10+
11+
COMMANDS *lldb-commands*
12+
13+
The LLDB command interpreter is exposed to Vim's command mode using the
14+
':L' prefix. Tab-completion is available and will cycle through commands.
15+
Some commands have modified behaviour in Vim; for example, :Lbreakpoint
16+
with no arguments will set a breakpoint at the current cursor, rather than
17+
printing the standard help information for the LLDB command 'breakpoint'.
18+
19+
*lldb-windows*
20+
21+
In addition to the standard commands available under the LLDB interpreter,
22+
there are also commands to display or hide informational debugger panes.
23+
24+
Windows can be shown or hidden using the ':Lhide <name>' or ':Lshow <name>'
25+
commands.
26+
*lldb-:Lhide*
27+
:Lhide [windowname] Hide informational debugger pane named 'windowname'.
28+
29+
*lldb-:Lshow*
30+
:Lshow [windowname] Show informational debugger pane named 'windowname'.
31+
32+
Possible window name arguments to the Lhide and Lshow commands include:
33+
34+
* backtrace
35+
* breakpoints
36+
* disassembly
37+
* locals
38+
* registers
39+
* threads
40+
*lldb-:Lattach*
41+
:Lattach <process-name> Attach to a process by name.
42+
43+
*lldb-:Ldetach*
44+
:Ldetach Detach from the current process.
45+
46+
*lldb-:Ltarget*
47+
:Ltarget [[create] executable]
48+
Create a target with the specified executable. If
49+
run with a single argument, that argument is assumed
50+
to be a path to the executable to be debugged.
51+
Otherwise, all arguments are passed into LLDB's command
52+
interpreter.
53+
54+
*lldb-:Lstart*
55+
:Lstart Create a process by executing the current target
56+
and wait for LLDB to attach.
57+
58+
*lldb-:Lrun*
59+
:Lrun Create a process by executing the current target
60+
without waiting for LLDB to attach.
61+
62+
*lldb-:Lcontinue*
63+
:Lcontinue Continue execution of the process until the next
64+
breakpoint is hit or the process exits.
65+
66+
*lldb-:Lthread*
67+
:Lthread <args> Passes through to LLDB. See :Lhelp thread.
68+
69+
*lldb-:Lstep*
70+
:Lstep Step into the current function call.
71+
72+
*lldb-:Lstepin*
73+
:Lstepin Step into the current function call.
74+
75+
*lldb-:Lstepinst*
76+
:Lstepinst Step one instruction.
77+
78+
*lldb-:Lstepinstover*
79+
:Lstepinstover Step one instruction, but skip over jump or call
80+
instructions.
81+
82+
*lldb-:Lnext*
83+
:Lnext Step to the next line.
84+
85+
*lldb-:Lfinish*
86+
:Lfinish Step out of the current function.
87+
88+
*lldb-:Lbreakpoint*
89+
:Lbreakpoint [args] When arguments are provided, the lldb breakpoint
90+
command is invoked. If no arguments are provided,
91+
a breakpoint at the location under the cursor.
92+
93+
*lldb-:Lprint*
94+
*lldb-:Lpo*
95+
*lldb-:LpO*
96+
:Lprint <expr> Aliases to the lldb print and po commands. Cursor
97+
:Lpo <expr> word (cursor WORD for LpO) will be used when
98+
:LpO <expr> expression omitted.
99+
100+
MAPPINGS *lldb-mappings*
101+
102+
On Mac OS X (under MacVim) , the following key mappings are available:
103+
104+
<Command-B> Insert a breakpoint at the line under cursor
105+
106+
107+
ABOUT *lldb-about*
108+
109+
Grab the latest version of this plugin (and LLDB sources) with:
110+
git clone https://github.com/llvm/llvm-project.git
111+
112+
File any bugs at:
113+
http://llvm.org/bugs/enter_bug.cgi?product=lldb
114+
115+
vim:tw=78:et:ft=help:norl:

plugin/lldb.vim

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
2+
" Vim script glue code for LLDB integration
3+
4+
function! s:FindPythonScriptDir()
5+
for dir in pathogen#split(&runtimepath)
6+
let searchstr = "python-vim-lldb"
7+
let candidates = pathogen#glob_directories(dir . "/" . searchstr)
8+
if len(candidates) > 0
9+
return candidates[0]
10+
endif
11+
endfor
12+
return
13+
endfunction()
14+
15+
function! s:InitLldbPlugin()
16+
if has('python') == 0
17+
call confirm('ERROR: This Vim installation does not have python support. lldb.vim will not work.')
18+
return
19+
endif
20+
21+
" Key-Bindings
22+
" FIXME: choose sensible keybindings for:
23+
" - process: start, interrupt, continue, continue-to-cursor
24+
" - step: instruction, in, over, out
25+
"
26+
if has('gui_macvim')
27+
" Apple-B toggles breakpoint on cursor
28+
map <D-B> :Lbreakpoint<CR>
29+
endif
30+
31+
"
32+
" Setup the python interpreter path
33+
"
34+
let vim_lldb_pydir = s:FindPythonScriptDir()
35+
execute 'python import sys; sys.path.append("' . vim_lldb_pydir . '")'
36+
37+
"
38+
" Register :L<Command>
39+
" The LLDB CommandInterpreter provides tab-completion in Vim's command mode.
40+
" FIXME: this list of commands, at least partially should be auto-generated
41+
"
42+
43+
" Window show/hide commands
44+
command -complete=custom,s:CompleteWindow -nargs=1 Lhide python ctrl.doHide('<args>')
45+
command -complete=custom,s:CompleteWindow -nargs=0 Lshow python ctrl.doShow('<args>')
46+
47+
" Launching convenience commands (no autocompletion)
48+
command -nargs=* Lstart python ctrl.doLaunch(True, '<args>')
49+
command -nargs=* Lrun python ctrl.doLaunch(False, '<args>')
50+
command -nargs=1 Lattach python ctrl.doAttach('<args>')
51+
command -nargs=0 Ldetach python ctrl.doDetach()
52+
53+
" Regexp-commands: because vim's command mode does not support '_' or '-'
54+
" characters in command names, we omit them when creating the :L<cmd>
55+
" equivalents.
56+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpattach python ctrl.doCommand('_regexp-attach', '<args>')
57+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpbreak python ctrl.doCommand('_regexp-break', '<args>')
58+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpbt python ctrl.doCommand('_regexp-bt', '<args>')
59+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpdown python ctrl.doCommand('_regexp-down', '<args>')
60+
command -complete=custom,s:CompleteCommand -nargs=* Lregexptbreak python ctrl.doCommand('_regexp-tbreak', '<args>')
61+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpdisplay python ctrl.doCommand('_regexp-display', '<args>')
62+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpundisplay python ctrl.doCommand('_regexp-undisplay', '<args>')
63+
command -complete=custom,s:CompleteCommand -nargs=* Lregexpup python ctrl.doCommand('_regexp-up', '<args>')
64+
65+
command -complete=custom,s:CompleteCommand -nargs=* Lapropos python ctrl.doCommand('apropos', '<args>')
66+
command -complete=custom,s:CompleteCommand -nargs=* Lbacktrace python ctrl.doCommand('bt', '<args>')
67+
command -complete=custom,s:CompleteCommand -nargs=* Lbreakpoint python ctrl.doBreakpoint('<args>')
68+
command -complete=custom,s:CompleteCommand -nargs=* Lcommand python ctrl.doCommand('command', '<args>')
69+
command -complete=custom,s:CompleteCommand -nargs=* Ldisassemble python ctrl.doCommand('disassemble', '<args>')
70+
command -complete=custom,s:CompleteCommand -nargs=* Lexpression python ctrl.doCommand('expression', '<args>')
71+
command -complete=custom,s:CompleteCommand -nargs=* Lhelp python ctrl.doCommand('help', '<args>')
72+
command -complete=custom,s:CompleteCommand -nargs=* Llog python ctrl.doCommand('log', '<args>')
73+
command -complete=custom,s:CompleteCommand -nargs=* Lplatform python ctrl.doCommand('platform','<args>')
74+
command -complete=custom,s:CompleteCommand -nargs=* Lplugin python ctrl.doCommand('plugin', '<args>')
75+
command -complete=custom,s:CompleteCommand -nargs=* Lprocess python ctrl.doProcess('<args>')
76+
command -complete=custom,s:CompleteCommand -nargs=* Lregister python ctrl.doCommand('register', '<args>')
77+
command -complete=custom,s:CompleteCommand -nargs=* Lscript python ctrl.doCommand('script', '<args>')
78+
command -complete=custom,s:CompleteCommand -nargs=* Lsettings python ctrl.doCommand('settings','<args>')
79+
command -complete=custom,s:CompleteCommand -nargs=* Lsource python ctrl.doCommand('source', '<args>')
80+
command -complete=custom,s:CompleteCommand -nargs=* Ltype python ctrl.doCommand('type', '<args>')
81+
command -complete=custom,s:CompleteCommand -nargs=* Lversion python ctrl.doCommand('version', '<args>')
82+
command -complete=custom,s:CompleteCommand -nargs=* Lwatchpoint python ctrl.doCommand('watchpoint', '<args>')
83+
84+
" Convenience (shortcut) LLDB commands
85+
command -complete=custom,s:CompleteCommand -nargs=* Lprint python ctrl.doCommand('print', vim.eval("s:CursorWord('<args>')"))
86+
command -complete=custom,s:CompleteCommand -nargs=* Lpo python ctrl.doCommand('po', vim.eval("s:CursorWord('<args>')"))
87+
command -complete=custom,s:CompleteCommand -nargs=* LpO python ctrl.doCommand('po', vim.eval("s:CursorWORD('<args>')"))
88+
command -complete=custom,s:CompleteCommand -nargs=* Lbt python ctrl.doCommand('bt', '<args>')
89+
90+
" Frame/Thread-Selection (commands that also do an Uupdate but do not
91+
" generate events in LLDB)
92+
command -complete=custom,s:CompleteCommand -nargs=* Lframe python ctrl.doSelect('frame', '<args>')
93+
command -complete=custom,s:CompleteCommand -nargs=? Lup python ctrl.doCommand('up', '<args>', print_on_success=False, goto_file=True)
94+
command -complete=custom,s:CompleteCommand -nargs=? Ldown python ctrl.doCommand('down', '<args>', print_on_success=False, goto_file=True)
95+
command -complete=custom,s:CompleteCommand -nargs=* Lthread python ctrl.doSelect('thread', '<args>')
96+
97+
command -complete=custom,s:CompleteCommand -nargs=* Ltarget python ctrl.doTarget('<args>')
98+
99+
" Continue
100+
command -complete=custom,s:CompleteCommand -nargs=* Lcontinue python ctrl.doContinue()
101+
102+
" Thread-Stepping (no autocompletion)
103+
command -nargs=0 Lstepinst python ctrl.doStep(StepType.INSTRUCTION)
104+
command -nargs=0 Lstepinstover python ctrl.doStep(StepType.INSTRUCTION_OVER)
105+
command -nargs=0 Lstepin python ctrl.doStep(StepType.INTO)
106+
command -nargs=0 Lstep python ctrl.doStep(StepType.INTO)
107+
command -nargs=0 Lnext python ctrl.doStep(StepType.OVER)
108+
command -nargs=0 Lfinish python ctrl.doStep(StepType.OUT)
109+
110+
" hack: service the LLDB event-queue when the cursor moves
111+
" FIXME: some threaded solution would be better...but it
112+
" would have to be designed carefully because Vim's APIs are non threadsafe;
113+
" use of the vim module **MUST** be restricted to the main thread.
114+
command -nargs=0 Lrefresh python ctrl.doRefresh()
115+
autocmd CursorMoved * :Lrefresh
116+
autocmd CursorHold * :Lrefresh
117+
autocmd VimLeavePre * python ctrl.doExit()
118+
119+
execute 'pyfile ' . vim_lldb_pydir . '/plugin.py'
120+
endfunction()
121+
122+
function! s:CompleteCommand(A, L, P)
123+
python << EOF
124+
a = vim.eval("a:A")
125+
l = vim.eval("a:L")
126+
p = vim.eval("a:P")
127+
returnCompleteCommand(a, l, p)
128+
EOF
129+
endfunction()
130+
131+
function! s:CompleteWindow(A, L, P)
132+
python << EOF
133+
a = vim.eval("a:A")
134+
l = vim.eval("a:L")
135+
p = vim.eval("a:P")
136+
returnCompleteWindow(a, l, p)
137+
EOF
138+
endfunction()
139+
140+
" Returns cword if search term is empty
141+
function! s:CursorWord(term)
142+
return empty(a:term) ? expand('<cword>') : a:term
143+
endfunction()
144+
145+
" Returns cleaned cWORD if search term is empty
146+
function! s:CursorWORD(term)
147+
" Will strip all non-alphabetic characters from both sides
148+
return empty(a:term) ? substitute(expand('<cWORD>'), '^\A*\(.\{-}\)\A*$', '\1', '') : a:term
149+
endfunction()
150+
151+
call s:InitLldbPlugin()

python-vim-lldb/import_lldb.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
# Locate and load the lldb python module
3+
4+
import os
5+
import sys
6+
7+
8+
def import_lldb():
9+
""" Find and import the lldb modules. This function tries to find the lldb module by:
10+
1. Simply by doing "import lldb" in case the system python installation is aware of lldb. If that fails,
11+
2. Executes the lldb executable pointed to by the LLDB environment variable (or if unset, the first lldb
12+
on PATH") with the -P flag to determine the PYTHONPATH to set. If the lldb executable returns a valid
13+
path, it is added to sys.path and the import is attempted again. If that fails, 3. On Mac OS X the
14+
default Xcode 4.5 installation path.
15+
"""
16+
17+
# Try simple 'import lldb', in case of a system-wide install or a
18+
# pre-configured PYTHONPATH
19+
try:
20+
import lldb
21+
return True
22+
except ImportError:
23+
pass
24+
25+
# Allow overriding default path to lldb executable with the LLDB
26+
# environment variable
27+
lldb_executable = 'lldb'
28+
if 'LLDB' in os.environ and os.path.exists(os.environ['LLDB']):
29+
lldb_executable = os.environ['LLDB']
30+
31+
# Try using builtin module location support ('lldb -P')
32+
from subprocess import check_output, CalledProcessError
33+
try:
34+
with open(os.devnull, 'w') as fnull:
35+
lldb_minus_p_path = check_output(
36+
"%s -P" %
37+
lldb_executable,
38+
shell=True,
39+
stderr=fnull).strip()
40+
if not os.path.exists(lldb_minus_p_path):
41+
# lldb -P returned invalid path, probably too old
42+
pass
43+
else:
44+
sys.path.append(lldb_minus_p_path)
45+
import lldb
46+
return True
47+
except CalledProcessError:
48+
# Cannot run 'lldb -P' to determine location of lldb python module
49+
pass
50+
except ImportError:
51+
# Unable to import lldb module from path returned by `lldb -P`
52+
pass
53+
54+
# On Mac OS X, use the try the default path to XCode lldb module
55+
if "darwin" in sys.platform:
56+
xcode_python_path = "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/Current/Resources/Python/"
57+
sys.path.append(xcode_python_path)
58+
try:
59+
import lldb
60+
return True
61+
except ImportError:
62+
# Unable to import lldb module from default Xcode python path
63+
pass
64+
65+
return False
66+
67+
if not import_lldb():
68+
import vim
69+
vim.command(
70+
'redraw | echo "%s"' %
71+
" Error loading lldb module; vim-lldb will be disabled. Check LLDB installation or set LLDB environment variable.")

0 commit comments

Comments
 (0)