sponsor Vim development Vim logo Vim Book Ad

DBGPavim : An improved Python/PHP debugger

 script karma  Rating 80/22, Downloaded by 5215  Comments, bugs, improvements  Vim wiki

created by
brook hong
script type
This is a plugin to enable php debug in VIM with Xdebug, which originates from http://www.vim.org/scripts/script.php?script_id=1152.
But most of the code, especially the debugger backend has been rewritten.


Screencast --

Tested with --
* XDebug 2.2 - PHP 5.4 - GVIM 7.3 - Python 2.7 @ Windows 7
* XDebug 2.0 - PHP 5.2 - VIM 7.3  - Python 2.7@ Linux
* XDebug 2.0 - PHP 5.2 - VIM 7.3  - Python 2.3@ Linux
* XDebug 2.2 - PHP 5.2 - VIM 7.3  - Python 2.7@ Linux

The source code is hosted at https://github.com/brookhong/DBGPavim.
Some screenshots (under windows) are here at http://sharing-from-brook.16002.n6.nabble.com/Debug-php-in-VIM-with-Xdebug-and-DBGPavim-td4930670.html.

## The enhancements are --

### Non blocking debugger backend.
So that VIM users do not need to wait for connection from apache server. No timeout things, users press F5 to start debugger backend, and uses his/her VIM normally. Debug backend won't stop users to interact with VIM. Users can press F6 to stop debugger backend anytime.

### Catch all connections from apache server.
This is very important for a large website, especially for thoes pages who contain AJAX requests. In that case, one reload of a page may trigger dozens of http request, each of them goes to a different URL. The new debugger backend will catch all connections from apache server. Users can debug all of them without missing anyone.

### Break only at breakpoints

    let g:dbgPavimBreakAtEntry = 0

    The setting will cause debugger backend to break only at breakpoints. Default value is 1, which means it works like before, the debugger backend breaks at entry.

### New commands and function keys

In normal mode

    <F5>      => start debugger backend
    <F6>      => stop debugger backend
    <F8>      => toggle dbgPavimBreakAtEntry, when g:dbgPavimBreakAtEntry=0, debugger backend breaks only at breakpoints.

    :Bl        => to list all breakpoints
    :Bp        => toggle breakpoint on current line

In debuggin mode

    <F1>      => toggle help window
    <F2>      => step into
    <F3>      => step over
    <F4>      => step out
    <F5>      => start debugging / run
    <F6>      => stop debugging
    <F7>      => evalute expression and display result. cursor is automatically move to watch window. type line and just press enter.
    <F9>      => toggle layout
    <F11>     => shows all variables
    <F12>     => shows variable on current cursor

    :Pg        => to print value of complex variables like $this->savings[3]
    :Up        => goto upper level of stack
    :Dn        => goto lower level of stack

In Watch window

    If you press Enter key at a line which ends with --
    (object)  => to get value of an object.
    (array)   => to get value of an array.

    If you press Enter key at a line of output from command :Bl, that breakpoint will be located.

In Stack window

    If you press Enter key at a line, stack level will be set.

### Windows Support

### Status line for debugger backend

    After user press <F5> to start debugger backend, a string like "PHP-bae-LISN" will show up at the right side of status line.

    The status string looks like --


    bae       => means Break At Entry
    bap       => means Break only At breakPoints

    LISN      => means the debugger backend is listening.
    PENDn     => means there are n connections waiting for debugging.
    CONN      => means debug session has been established, and being debugged.
    CLSD      => means the debugger backend has stopped.

### New layout of windows

### Remote debugging

In case that you need run VIM on a different machine from server where apache httpd runs, configuration for DBGPavim --

    let g:dbgPavimPathMap = [['D:/works/php','/var/www'],]

Some change for Apache configuration is also necessary --

    php_value xdebug.remote_host <ip_address_where_you_run_vim>

## Usage

* Make sure your vim has python(at least 2.3) supported, in vim with command


    In case of your VIM don't support python, download VIM source package from http://www.vim.org/download.php, then build your own VIM with commands --

    ./configure --prefix=/opt/vim --enable-pythoninterp --with-python-config-dir=/usr/lib/python2.4/config
    make install

* Install xdebug for php, and edit php.ini


* Edit your ~/.vimrc

    let g:dbgPavimPort = 9009
    let g:dbgPavimBreakAtEntry = 0

* Edit your apche configure file

    In your VirtualHost section, set debugger port same as the one in your vimrc

    php_value xdebug.remote_port 9009

* Save debugger.py and debugger.vim to your ~/.vim/plugin

* Open your php file, use :Bp to set breakpoints

* Now, press F5 to start debugger backend

* Back to your browser, add XDEBUG_SESSION_START=1 to your URL, for example, http://localhost/index.php?XDEBUG_SESSION_START=1. If you would like to debug from CLI, start your php script like

    php -dxdebug.remote_autostart=1 -dxdebug.remote_port=9009 test.php

If you are tied of adding XDEBUG_SESSION_START=1 in query string, there is a XDEBUG_SESSION helper at http://userscripts.org/scripts/review/132695, a user script for Google Chrome. It also works for Firefox with help of GreaseMonkey.
install details
Just unzip the zip file to your VIM file path, usually to be ~/.vim.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
DBGPavim.zip 1.07 2014-04-29 7.2 brook hong 1. Disable all breakpoints with :Bc & Enable all breakpoints with :Bu
2. load dbgpavim.py on demand to speed up vim startup
3. fix some bugs
DBGPavim.zip 1.06 2013-06-22 7.2 brook hong 1. fix error for getting value in array whose key name contains space
2. avoid accidental hangs when exiting
3. fix bug to remove breakpoint in debugging
4. show classname when debugging php
5. g:dbgPavimOnce=1 to let your site accessible when debugging
6. ratio for windows width/height
7. enable customization of mapping for windows resize and highlight settings
DBGPavim.zip 1.05 2013-01-14 7.2 brook hong 1. object/array expansion inline in watch window
2. list breakpoints to location list
3. some bug fixes
DBGPavim.zip 1.04 2012-11-23 7.2 brook hong 1. pretty output in watch window for python debugging
2. user friendly notice of exception
3. :We [foo]  => to eval expression `foo` automatically after each step
DBGPavim.zip 1.03 2012-10-15 7.2 brook hong 1. :Wc $foo to toggle watch on variable $foo, :Wl to list watched variables
2. customizable key mappings
3. keep other tabs intact after debugging completed
4. bug fix for windows
DBGPavim.zip 1.02 2012-09-26 7.2 brook hong 1. dbgPavimBreakAtEntry default as 0, so it will not break at entry by default.
2. doc for python debugging
3. :Dp command to debug current file from CLI
DBGPavim.zip 1.01 2012-05-16 7.2 brook hong 1. remote debugging support
2. doc embeded
3. rename all global parameters from g:debuggerXXXX to g:dbgPavimXXXX
DBGPavim.zip 1.0 2012-05-10 7.2 brook hong Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Vim at Github