Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to use python3 #4

Merged
merged 1 commit into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ This plugin is known to work with the following flavours of Vim:
* Linux (tested on Ubuntu 12.04/12.10):
* vim/gvim (from vim-gnome package version 7.3)

* Mac OS X (tested on Mountain Lion)
* Vim command-line (7.3 from Xcode)
* macOS (tested on Monterey)
* Vim command-line (8.2 from homebrew)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really true because of #2

I was able to get this working with neovim pointing at system python on macOS, but that isn't really up to this plugin

* MacVim 7.3

To install the plugin, ensure you have
* a working version of lldb on your path, or the environment variable LLDB
pointing to the lldb binary you would like to use.
* a python-enabled vim (check with ":python print 2")
* a python3-enabled vim (check with "vim --version | grep python3")


Installation
Expand Down
122 changes: 61 additions & 61 deletions plugin/lldb.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function! s:FindPythonScriptDir()
endfunction()

function! s:InitLldbPlugin()
if has('python') == 0
call confirm('ERROR: This Vim installation does not have python support. lldb.vim will not work.')
if !has('python3')
call confirm('ERROR: This Vim installation does not have python3 support. lldb.vim will not work.')
return
endif

" Key-Bindings
" FIXME: choose sensible keybindings for:
" - process: start, interrupt, continue, continue-to-cursor
Expand All @@ -29,10 +29,10 @@ function! s:InitLldbPlugin()
endif

"
" Setup the python interpreter path
" Setup the python3 interpreter path
"
let vim_lldb_pydir = s:FindPythonScriptDir()
execute 'python import sys; sys.path.append("' . vim_lldb_pydir . '")'
execute 'python3 import sys; sys.path.append("' . vim_lldb_pydir . '")'

"
" Register :L<Command>
Expand All @@ -41,86 +41,86 @@ function! s:InitLldbPlugin()
"

" Window show/hide commands
command -complete=custom,s:CompleteWindow -nargs=1 Lhide python ctrl.doHide('<args>')
command -complete=custom,s:CompleteWindow -nargs=0 Lshow python ctrl.doShow('<args>')
command -complete=custom,s:CompleteWindow -nargs=1 Lhide python3 ctrl.doHide('<args>')
command -nargs=0 Lshow python3 ctrl.doShow('<args>')

" Launching convenience commands (no autocompletion)
command -nargs=* Lstart python ctrl.doLaunch(True, '<args>')
command -nargs=* Lrun python ctrl.doLaunch(False, '<args>')
command -nargs=1 Lattach python ctrl.doAttach('<args>')
command -nargs=0 Ldetach python ctrl.doDetach()
command -nargs=* Lstart python3 ctrl.doLaunch(True, '<args>')
command -nargs=* Lrun python3 ctrl.doLaunch(False, '<args>')
command -nargs=1 Lattach python3 ctrl.doAttach('<args>')
command -nargs=0 Ldetach python3 ctrl.doDetach()

" Regexp-commands: because vim's command mode does not support '_' or '-'
" characters in command names, we omit them when creating the :L<cmd>
" equivalents.
command -complete=custom,s:CompleteCommand -nargs=* Lregexpattach python ctrl.doCommand('_regexp-attach', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpbreak python ctrl.doCommand('_regexp-break', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpbt python ctrl.doCommand('_regexp-bt', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpdown python ctrl.doCommand('_regexp-down', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexptbreak python ctrl.doCommand('_regexp-tbreak', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpdisplay python ctrl.doCommand('_regexp-display', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpundisplay python ctrl.doCommand('_regexp-undisplay', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpup python ctrl.doCommand('_regexp-up', '<args>')

command -complete=custom,s:CompleteCommand -nargs=* Lapropos python ctrl.doCommand('apropos', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lbacktrace python ctrl.doCommand('bt', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lbreakpoint python ctrl.doBreakpoint('<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lcommand python ctrl.doCommand('command', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Ldisassemble python ctrl.doCommand('disassemble', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lexpression python ctrl.doCommand('expression', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lhelp python ctrl.doCommand('help', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Llog python ctrl.doCommand('log', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lplatform python ctrl.doCommand('platform','<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lplugin python ctrl.doCommand('plugin', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lprocess python ctrl.doProcess('<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregister python ctrl.doCommand('register', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lscript python ctrl.doCommand('script', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lsettings python ctrl.doCommand('settings','<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lsource python ctrl.doCommand('source', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Ltype python ctrl.doCommand('type', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lversion python ctrl.doCommand('version', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lwatchpoint python ctrl.doCommand('watchpoint', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpattach python3 ctrl.doCommand('_regexp-attach', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpbreak python3 ctrl.doCommand('_regexp-break', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpbt python3 ctrl.doCommand('_regexp-bt', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpdown python3 ctrl.doCommand('_regexp-down', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexptbreak python3 ctrl.doCommand('_regexp-tbreak', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpdisplay python3 ctrl.doCommand('_regexp-display', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpundisplay python3 ctrl.doCommand('_regexp-undisplay', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregexpup python3 ctrl.doCommand('_regexp-up', '<args>')

command -complete=custom,s:CompleteCommand -nargs=* Lapropos python3 ctrl.doCommand('apropos', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lbacktrace python3 ctrl.doCommand('bt', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lbreakpoint python3 ctrl.doBreakpoint('<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lcommand python3 ctrl.doCommand('command', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Ldisassemble python3 ctrl.doCommand('disassemble', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lexpression python3 ctrl.doCommand('expression', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lhelp python3 ctrl.doCommand('help', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Llog python3 ctrl.doCommand('log', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lplatform python3 ctrl.doCommand('platform','<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lplugin python3 ctrl.doCommand('plugin', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lprocess python3 ctrl.doProcess('<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lregister python3 ctrl.doCommand('register', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lscript python3 ctrl.doCommand('script', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lsettings python3 ctrl.doCommand('settings','<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lsource python3 ctrl.doCommand('source', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Ltype python3 ctrl.doCommand('type', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lversion python3 ctrl.doCommand('version', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lwatchpoint python3 ctrl.doCommand('watchpoint', '<args>')

" Convenience (shortcut) LLDB commands
command -complete=custom,s:CompleteCommand -nargs=* Lprint python ctrl.doCommand('print', vim.eval("s:CursorWord('<args>')"))
command -complete=custom,s:CompleteCommand -nargs=* Lpo python ctrl.doCommand('po', vim.eval("s:CursorWord('<args>')"))
command -complete=custom,s:CompleteCommand -nargs=* LpO python ctrl.doCommand('po', vim.eval("s:CursorWORD('<args>')"))
command -complete=custom,s:CompleteCommand -nargs=* Lbt python ctrl.doCommand('bt', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lprint python3 ctrl.doCommand('print', vim.eval("s:CursorWord('<args>')"))
command -complete=custom,s:CompleteCommand -nargs=* Lpo python3 ctrl.doCommand('po', vim.eval("s:CursorWord('<args>')"))
command -complete=custom,s:CompleteCommand -nargs=* LpO python3 ctrl.doCommand('po', vim.eval("s:CursorWORD('<args>')"))
command -complete=custom,s:CompleteCommand -nargs=* Lbt python3 ctrl.doCommand('bt', '<args>')

" Frame/Thread-Selection (commands that also do an Uupdate but do not
" generate events in LLDB)
command -complete=custom,s:CompleteCommand -nargs=* Lframe python ctrl.doSelect('frame', '<args>')
command -complete=custom,s:CompleteCommand -nargs=? Lup python ctrl.doCommand('up', '<args>', print_on_success=False, goto_file=True)
command -complete=custom,s:CompleteCommand -nargs=? Ldown python ctrl.doCommand('down', '<args>', print_on_success=False, goto_file=True)
command -complete=custom,s:CompleteCommand -nargs=* Lthread python ctrl.doSelect('thread', '<args>')
command -complete=custom,s:CompleteCommand -nargs=* Lframe python3 ctrl.doSelect('frame', '<args>')
command -complete=custom,s:CompleteCommand -nargs=? Lup python3 ctrl.doCommand('up', '<args>', print_on_success=False, goto_file=True)
command -complete=custom,s:CompleteCommand -nargs=? Ldown python3 ctrl.doCommand('down', '<args>', print_on_success=False, goto_file=True)
command -complete=custom,s:CompleteCommand -nargs=* Lthread python3 ctrl.doSelect('thread', '<args>')

command -complete=custom,s:CompleteCommand -nargs=* Ltarget python ctrl.doTarget('<args>')
command -complete=custom,s:CompleteCommand -nargs=* Ltarget python3 ctrl.doTarget('<args>')

" Continue
command -complete=custom,s:CompleteCommand -nargs=* Lcontinue python ctrl.doContinue()
command -complete=custom,s:CompleteCommand -nargs=* Lcontinue python3 ctrl.doContinue()

" Thread-Stepping (no autocompletion)
command -nargs=0 Lstepinst python ctrl.doStep(StepType.INSTRUCTION)
command -nargs=0 Lstepinstover python ctrl.doStep(StepType.INSTRUCTION_OVER)
command -nargs=0 Lstepin python ctrl.doStep(StepType.INTO)
command -nargs=0 Lstep python ctrl.doStep(StepType.INTO)
command -nargs=0 Lnext python ctrl.doStep(StepType.OVER)
command -nargs=0 Lfinish python ctrl.doStep(StepType.OUT)
command -nargs=0 Lstepinst python3 ctrl.doStep(StepType.INSTRUCTION)
command -nargs=0 Lstepinstover python3 ctrl.doStep(StepType.INSTRUCTION_OVER)
command -nargs=0 Lstepin python3 ctrl.doStep(StepType.INTO)
command -nargs=0 Lstep python3 ctrl.doStep(StepType.INTO)
command -nargs=0 Lnext python3 ctrl.doStep(StepType.OVER)
command -nargs=0 Lfinish python3 ctrl.doStep(StepType.OUT)

" hack: service the LLDB event-queue when the cursor moves
" FIXME: some threaded solution would be better...but it
" would have to be designed carefully because Vim's APIs are non threadsafe;
" use of the vim module **MUST** be restricted to the main thread.
command -nargs=0 Lrefresh python ctrl.doRefresh()
command -nargs=0 Lrefresh python3 ctrl.doRefresh()
autocmd CursorMoved * :Lrefresh
autocmd CursorHold * :Lrefresh
autocmd VimLeavePre * python ctrl.doExit()
autocmd VimLeavePre * python3 ctrl.doExit()

execute 'pyfile ' . vim_lldb_pydir . '/plugin.py'
execute 'py3file ' . vim_lldb_pydir . '/plugin.py'
endfunction()

function! s:CompleteCommand(A, L, P)
python << EOF
python3 << EOF
a = vim.eval("a:A")
l = vim.eval("a:L")
p = vim.eval("a:P")
Expand All @@ -129,7 +129,7 @@ EOF
endfunction()

function! s:CompleteWindow(A, L, P)
python << EOF
python3 << EOF
a = vim.eval("a:A")
l = vim.eval("a:L")
p = vim.eval("a:P")
Expand Down
2 changes: 1 addition & 1 deletion python-vim-lldb/import_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def import_lldb():
"%s -P" %
lldb_executable,
shell=True,
stderr=fnull).strip()
stderr=fnull).strip().decode()
if not os.path.exists(lldb_minus_p_path):
# lldb -P returned invalid path, probably too old
pass
Expand Down
3 changes: 1 addition & 2 deletions python-vim-lldb/vim_panes.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ def write(self, msg):
""" replace buffer with msg"""
self.prepare()

msg = str(msg.encode("utf-8", "replace")).split('\n')
try:
self.buffer.append(msg)
self.buffer.append(msg.splitlines())
vim.command("execute \"normal ggdd\"")
except vim.error:
# cannot update window; happens when vim is exiting.
Expand Down