Vim and python debug

1431995421460 » Tagged as: vim , python , django , debug


This is the first VIM based debug connection that I managed to setup. Vebugger will stop at break points and you can use it's commands to inspect variables. But it's somewhat tedious because it doesn't seem have an interactive shell like pdb does.  Vebugger is a frontend that can be used with many different languages. In case of  python what this actually does is connect to pdb, so I am left wondering if it would be better off to just use pdb by itself.

Having said that this project looks like it's been actively maintained and hopefully in a few months time we might see some more functionality and it will become more usefull..


I tried to install it by adding Plugin 'jaredly/vim-debug' without any luck. Well the installation did happen by the :Dbg command wan't enabled. Then I uninstalled it with :PluginClean and tried a manual install with better results. In fact I could quite easily start the debugger after restarting vim just by  :Dbg . and hey presto all sorts of splits appeared with stacks, variables etc. Impressive. And just to think this software hasn't been updated for 2 years!

Now for the acid test, can it debug Django? unfortunately not. :Dbg runserver yields

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/virtual-django-15/lib/python2.7/site-packages/vim_debug/", line 19, in debugger_cmd
    return start(*shlex.split(plain))
TypeError: start() takes at most 1 argument (3 given) 

But I am hopefull that I will be able to make something out this for example you can just create another script than invokes with the set of arguments that you need. Clunky but usable. The code is in python and looks really good if you ignore the fact that it conflicts with many keymaps including Command-T. This conflict  can apparently be fixed by adding let g:vim_debug_disable_mappings = 1 to .vimrc . However in my case it didn't happen and I had no choice than to uninstall it.


It can be setup with Vundle but you need to download pydbgp from Komodo afterwards start the debug server by hitting <F5> in vim and run your script from the terminal python -S ~/bin/pydbgp -d localhost:9000 for me it didn't quite work out in the first attempt.

Traceback (most recent call last):
  File "/home/raditha/bin/pydbgp", line 71, in 
    import getopt
ImportError: No module named getopt

Turns out this is caused by the -S option for python which says don't imply 'import site' on initialization whatever that means! I am guessing it has something to do with site-packages in a virtualenv but at any rate running the script without the -S option worked! So let's leave it at that

Now the acid test. Does it work with Django? Typed python ~/bin/pydbgp -d localhost:9000 runserver and was quite pleased to see it stop at the first line inside and then hit again to goto the browser and load a url. At that stage gvim stopped responding completely. However the following message could be seen in one of the debug windows Debugger engine says it is in interactive mode,"+\ "which is not supported: closing connection"

I tracked it down to in vdebug but didn't have the time to dig any deeper. If nothing else works out I will come back here


Like Vdebug, has the Komodo remote debug client listed as a dependency. Unfortunately I couldn't elicit any response from it by pressesing or any other keys. (The fact that the plugin has been activated could be seen b typing :map)


Nextup was vimpdb. According to the documentation this shouldn't be installed as a plugin but using pip. Then you need to add import vimpdb; vimpdb.set_trace() to your code and start the script. This is similar to adding import pdb; pdb.set_trace() for use with pdb. The difference here is that a new instance of vim will be launched instead of pdb when you run the script. It doesn't seem to be able to reuse an already started vim session. The basic script could be debugged wtihout any trouble and it didn't freeze or thrown an error message when django runserver eas exectued! Now the bad news, it didn't stop at a break point when a url was loaded in the browser.


And finally vim-addon-python-pdb but not much luck with that either.

Error detected while processing function python_pdb#Setup..python_pdb#RubyBuffer:
line   11:
E117: Unknown function: async_porcelaine#LogToBuffer
Error detected while processing function python_pdb#Setup..python_pdb#UpdateBreakPoints..python_pdb#BreakPointsBuffer:
line    2:
E117: Unknown function: buf_utils#GotoBuf
E15: Invalid expression: buf_utils#GotoBuf(buf_name, {'create_cmd':'sp'} )
line    3:
E121: Undefined variable: cmd
E15: Invalid expression: cmd == 'e'
Error detected while processing function python_pdb#Setup..python_pdb#UpdateBreakPoints:
line   37:
E117: Unknown function: vim_addon_signs#Push
line   43:
E716: Key not present in Dictionary: write

comments powered by Disqus