Giter Club home page Giter Club logo

vimpdb's Introduction

VIM Pdb integration

This package provides an integration of the Python debugger pdb into the VIM editor.

https://secure.travis-ci.org/gotcha/vimpdb.png

Using vimpdb is easy -- just insert a call to set_trace in your code almost as usual:

import vimpdb; vimpdb.set_trace()

Then start your python application/script.

When the python interpreter hits that line, vimpdb will launch a VIM instance. VIM should get the focus; it loads the source file at the right line.

In VIM, you may now use the following commands:

vimpdb commands
Ex Command Key binding Details
:PDBNext n pdb (n)ext
:PDBStep s pdb (s)tep
:PDBArgs a pdb (a)rgs
:PDBUp u pdb (u)p
:PDBDown d pdb (d)own
:PDBReturn r pdb (r)eturn
:PDBContinue c pdb (c)ontinue
:PDBBreak b Sets a breakpoint at the line on which the cursor is sitting; similar to pdb b(reak)
:PDBClear B Clears a breakpoint at the line on which the cursor is sitting; similar to pdb cl(ear)
:PDBWord w Evaluates the value of the identifier on which the cursor is sitting.
:PDBEval ? Evaluates a Python expression after having asked for it.
:PDBReset x Switch back to normal debugging in shell with standard pdb.
N/A v(im) Switch back to vimpdb; only in plain pdb.

If you find it hard to change habits and keep on typing

import pdb; pdb.set_trace()

you can add the following line to the .pdbrc file sitting in your home folder:

import vimpdb; vimpdb.hookPdb()

This way, the command v(im) mentioned above is added to your standard pdb and you can switch to vimpdb at any time.

vimpdb has been used successfully under Linux, Mac OSX and Windows.

It is compatible with Python 2.7, 2.6, 2.5 and 2.4. It is not compatible with Python 3.1 (it should be the same for 3.0).

vimpdb requires an installation of VIM that supports both python and clientserver options.

Find out if it is the case by issuing the following command at the VIM prompt:

:version

If the options are supported, you will see +clientserver and +python in the output. In the opposite case, you will see -clientserver or -python.

On Linux and Windows, the default VIM build should already be server-enabled.

On Windows, the python option compiled in VIM depends on a specific Python version. Find out if that specific version is installed and works in VIM by issuing the following command at the VIM prompt:

:python import sys; print sys.version

On Mac OSX, you'll want to use MacVIM. MacVIM also has the python option compiled in by default.

Standard installation with easy_install

$ easy_install vimpdb

You can obviously also use pip.

If you look inside the package, you will see a VIM script file: vimpdb.vim. Do not move it to VIM configuration directory (like ~/.vim/plugin). vimpdb knows how to make the script available to VIM.

vimpdb tries to avoid depending on any user configuration. If it cannot detect the right configuration by itself, it will ask a few questions which you should be able to answer easily.

When launched, vimpdb looks for its RC file : ~/.vimpdbrc. If it does not find it, vimpdb creates that file for you from default values.

vimpdb tries a set of default values that should work. It checks if those default values are appropriate. If the default values do not work, vimpdb asks for other values interactively until it has checked that the values provided actually work.

The default values per OS are listed hereunder.

For Linux:

[vimpdb]
vim_client_script = vim
vim_server_script = gvim
server_name = GVIM
port = 6666

For MacOSX:

[vimpdb]
vim_client_script = mvim
vim_server_script = mvim
server_name = VIM
port = 6666

For Windows:

[vimpdb]
vim_client_script = vim.exe
vim_server_script = gvim.exe
server_name = VIM
port = 6666

See below for details about each option.

You are obviously allowed to create and tune that RC file. Nevertheless, the RC file should hold values for all 4 options. If one of them is missing, vimpdb breaks and complains accordingly.

To communicate with the VIM instance where debugging happens, vimpdb needs to launch another VIM instance in client mode.

vim_client_script option holds the script used to launch that VIM instance with clientserver support.

On Windows, it should hold vim.exe, not gvim.exe. Furthermore, do not include quotes in the value to take care of whitespace in the path.

In case no VIM instance is running, vimpdb launches a VIM instance in server mode.

vim_server_script option holds the script used to launch that VIM instance with clientserver support. As debugging in the VIM instance is written with python, that instance must have python support.

On MacOSX and Linux, vim_server_script and vim_client_script can hold the same value.

On Windows, only the graphical VIM can be used as server, reason for the two separate default values as seen above.

The VIM instance in server mode has a name.

By default, vimpdb speaks to the server named VIM, which is the default servername used by VIM.

If you want vimpdb to use another server name, modify the server_name option. It should hold the name of the VIM server you want to be used for debugging.

You may list the currently running VIM servers using:

$ vim --serverlist
VIM

Or, on a Mac:

$ /Applications/MacVim.app/Contents/MacOS/Vim --serverlist
VIM

When a VIM instance with clientserver support is running, you can find its name by issuing the following command at the VIM prompt:

:echo v:servername

VIM communicates to vimpdb through a UDP socket. By default, the socket is opened on port 6666.

If that socket is not available in your system, you can specify an available port number with the port option.

None for now.

Before version 0.4.1, vimpdb RC file (~/.vimpdbrc) had a single script option. That option has been turned into the vim_client_script option. The upgrade should be transparent.

Before version 0.4.0, vimpdb was configured through environment variables. If you had a working configuration, upgrade should be transparent. The values of VIMPDB_SERVERNAME and VIMPDB_VIMSCRIPT environment variables are setup in the RC file (~/.vimpdbrc). They are put respectively in server_name and script options.

See changelog

vimpdb's People

Contributors

gotcha avatar jcavallo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vimpdb's Issues

AttributeError: 'Detector' object has no attribute 'vim_client_script'

When installing the script via python setup.py develop --user (on 78dc1af) and then running it one another script (via import vimpdb; vimpdb.set_trace()):

matej@mitmanek: qa-tools-apps (fixes *)$ ./status-report --debug --since=2014-10-01
Traceback (most recent call last):
  File "./status-report", line 21, in <module>
    from reports.base import Date, Stats, StatsGroup
  File "/home/matej/archiv/knihovna/repos/qa-tools-apps/reports/base.py", line 14, in <module>
    vimpdb.set_trace()
  File "/home/matej/archiv/knihovna/repos/vimpdb/src/vimpdb/debugger.py", line 229, in set_trace
    instance = make_instance()
  File "/home/matej/archiv/knihovna/repos/vimpdb/src/vimpdb/debugger.py", line 218, in make_instance
    communicator = proxy.Communicator(configuration.vim_client_script,
AttributeError: 'Detector' object has no attribute 'vim_client_script'
matej@mitmanek: qa-tools-apps (fixes *)$ 

Error detected while processing function PDB_init_controller:

When I execute a script containing import vimpdb; vimpdb.set_trace() it returns the following error:

Error detected while processing function PDB_init_controller:
line 5:
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/vimpdb/controller.py", line 84, in
@vim_bridge.bridged
File "/Library/Python/2.7/site-packages/vim_bridge/init.py", line 56, in bridged
prefix = 'vim_brdg_%d_' % _rand()
File "/Library/Python/2.7/site-packages/vim_bridge/__init
.py", line 10, in _rand
import random
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
random.py", line 47, in
from os import urandom as _urandom
ImportError: cannot import name urandom

I have googled quite a bit, and cannot see what the issue is. I am using macvim installed via homebrew on OSX 10.7.4

No module named 'StringIO'

Hello. Many thanks for writing and maintaining vimpdb which I would very interested to inste. I just installed with pip and tried the following script (named test3.py:

from io import StringIO
import vimpdb

with: vimpdb==0.4.5 and Python 3.8.7 on Macos 11.2.2

I get the followin error:

Traceback (most recent call last):
  File "test3.py", line 2, in <module>
    import vimpdb
  File "/Users/path_to/env/lib/python3.8/site-packages/vimpdb/__init__.py", line 1, in <module>
    from vimpdb.debugger import set_trace
  File "/Users/path_to/env/lib/python3.8/site-packages/vimpdb/debugger.py", line 4, in <module>
    import StringIO
ModuleNotFoundError: No module named 'StringIO'

What shall I do?

Many thanks in advance

Error crashes out the first time I hit "N"

It appears to start up OK. But the first time I hit "N"
I get the exact same error (with both my Ubuntu and Windows 7 x64 machines):

On the console running VIM, I get:
Error detected while processing function PDB_send_command:
line 4:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'vim' is not defined

In the Console running the python script I get:
File "/usr/local/lib/python2.6/dist-packages/vimpdb-0.3.7-py2.6.egg/vimpdb/proxy.py", line 96,
in bindSocket
self.socket.bind(('', self.PORT))
File "", line 1, in bind
socket.error: [Errno 98] Address already in use
Can you help me out with this one?

"continue" command is broken after a breakpoint has been set

Version: 0.3.5

Reported by Cedric Macquat :

command: b c:\view\RAK\workspace\Offerator\src\Offerator.py:3555
sent: :call PDB_display_feedback(['Breakpoint 1 at c:\view\rak\workspace\off
erator\src\offerator.py:3555'])

command: c
sent: :call PDB_display_feedback(['> c:\view\rak\workspace\offerator\src\o
fferator.py(3555)()', '-> parameters = [myfloat(x) for x in row]'])
sent: :call PDB_show_file_at_line("c:/view/rak/workspace/offerator/src/offerator
.py", "3555")

Traceback (most recent call last):
File "Offerator.py", line 3555, in
parameters = [myfloat(x) for x in row]
File "Offerator.py", line 3555, in
parameters = [myfloat(x) for x in row]
File "c:\python25\lib\site-packages\vimpdb-0.3.5-py2.5.egg\vimpdb\debugger.py"
, line 76, in trace_dispatch
return Pdb.trace_dispatch(self, frame, event, arg)
File "C:\Python25\lib\bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "C:\Python25\lib\bdb.py", line 66, in dispatch_line
self.user_line(frame)
File "C:\Python25\lib\pdb.py", line 144, in user_line
self.interaction(frame, None)
File "C:\Python25\lib\pdb.py", line 187, in interaction
self.cmdloop()
File "c:\python25\lib\site-packages\vimpdb-0.3.5-py2.5.egg\vimpdb\debugger.py"
, line 85, in cmdloop
line = self.vim.waitFor(self)
File "c:\python25\lib\site-packages\vimpdb-0.3.5-py2.5.egg\vimpdb\proxy.py", l
ine 51, in waitFor
(message, address) = self.server.recvfrom(self.BUFLEN)
File "C:\Python25\lib\socket.py", line 141, in _dummy
raise error(EBADF, 'Bad file descriptor')
socket.error: (9, 'Bad file descriptor')

get_serverlist returns error

When my code hits import vimpdb;vimpdb.set_trace(), I get the following output:

File "/usr/local/lib/python2.7/dist-packages/vimpdb/config.py", line 251, in get_serverlist
    raise ValueError(RETURN_CODE % (command, return_code))
ValueError: 'vim --serverlist' returned exit code '1'.

and vim --serverlist gives me:

vim --serverlist
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 13 2020 16:04:38)
Unknown option argument: "--serverlist"
More info with: "vim -h"

What am I missing to get vimpdb up and running correctly in my environment?

Lots of undefined function errors upon startup

On windows xp, when I do

>python manual_test.py

a GVIM windows opens but there are lots of errors like:

Unknown function PDB_append_watch

What am I doing wrong here? Any ideas?

Thanks!

Using "vim_server_script = vim" doesn't work correctly

I try to use vimpdb on remote system through ssh connection . My ~/.vimpdbrc:
[vimpdb]
vim_client_script = vim
vim_server_script = vim
server_name = VIM
port = 6666

I set breakpoint in one of my project files and run project main file, when execution hit breakpoint new vim was launched but there is no code to debugging only vim welcome screen. When I try to quit vim using :q after short delay I got this python trace (I changed paths):

Runtime Exception caugth 'VIM' server name not available in server list:

Traceback (most recent call last):
File "src/main.py", line 62, in
exitStatus = app.RunApp(sys.argv)
File "/path/to/my/project/src/application.py", line 308, in RunApp
import vimpdb; vimpdb.set_trace()
File "/path/to/home/dir/lib/python2.7/site-packages/vimpdb-0.4.5-py2.7.egg/vimpdb/debugger.py", line 213, in set_trace
instance = make_instance()
File "/path/to/home/dir/lib/python2.7/site-packages/vimpdb-0.4.5-py2.7.egg/vimpdb/debugger.py", line 201, in make_instance
configuration = config.getConfiguration()
File "/path/to/home/dir/lib/python2.7/site-packages/vimpdb-0.4.5-py2.7.egg/vimpdb/config.py", line 105, in getConfiguration
Detector(config).check_serverlist()
File "/path/to/home/dir/lib/python2.7/site-packages/vimpdb-0.4.5-py2.7.egg/vimpdb/config.py", line 285, in check_serverlist
raise ValueError(msg % (self.server_name, serverlist))
ValueError: 'VIM' server name not available in server list:

Looks like server didn't start correctly. Is it possible to use vim editor (not gvim) as client and server with vimpdb module ?
My vimpdb module was installed in my $HOME directory /path/to/home/dir.

Key Mappings persist after uninstall of Python module

Hi,

even after the uninstall of vimpdb and vim-bridge via pip, everytime I load a python-file into the buffer, the pdb-mappings overwrite my local settings in vim. I would like to know, where are those mappings defined. I searched through /usr/share/vim and ~/.vim/, but to no avail. Any hints ?

Thanks

vimpdb does not accept commands

I installed vimpdb with pip and after that it gave me the error described here, I also cloned the repository from (https://github.com/gotcha/vimpdb) and used the easy_install method but it keeps giving me the same troubles:

When I get to a breakpoint (vimpdb.set_trace()) I see the screen showing the source code with the cursor sitting at the right position but any time I try to enter commands as indexed on https://github.com/gotcha/vimpdb#vim-commands , for example :PDBStep, I get an error E117: Unknown function: PDBSendCommand while autocomplete (for :PDBStep) seems to work fine. I'm obviously missing something (PDBSendCommand)but am not sure how get it setup correctly? Can you help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.