Vim plugin for XDebug

http://www.vim.org/scripts/script.php?script_id=1929

What should we add to php.ini?

zend_extension=/usr/lib/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.show_local_vars=1

How can we set permanent break-point in the code?

if (function_exists("xdebug_break")) {
    xdebug_break();
}

How can we start the debugging process?

  1. Launch Vim
  2. Open the file that you want to debug
  3. Set breakpoints
  4. Press F5
  5. Switch to the browser and refresh the page
  6. Go back to vim. It should have accepted the connection.

How can we debug a command line php script?

To debug a command line php script, you need:

export XDEBUG_CONFIG=""

See https://stackoverflow.com/questions/8254386/php-debugger-for-vim-debug-commandline-scripts?lq=1

What are the hotkeys?

Hot key Description
F1 resize
F2 step into
F3 step over
F4 step out
F5 run
F6 quit debugging
F11 get all context
F12 get property at cursor

How can we eval an expression?

To eval an expression, use ,e command (there is a comma in-front of e).

How can we set break point?

Using :e to open the desired file, go to the line you suspect, set a break point using :Bp

How can we run until the next breakpoint?

Hit F5 to run until the break point

How can we allow multiple developers to debug at the same time?

To allow multiple developers to debug at the same time, add to .bashrc:

export XDEBUG_CONFIG='remote_enable=1 remote_handler=dbgp remote_mode=req remote_host=localhost remote_port=9001'

and add to .vimrc:

let g:debuggerPort = 9001

On Fedora Core X11 Windows, the F11 key is also the hot key for going to full screen. To get back the screen with toolbar menu press F11

What are my wishlist?

  • Permanent break-point. We already know how to set permanent break-point in the code. Perhaps we can combine this with xdebug.remote_mode=jit (so that debugging starts on the line that has xdebug_break() instead of the beginning of index.php. The difference is one keystroke (F5, minor). Being able to set up a personal profile in my home directory or in the current working directory. I should be able to store permanent break points. I was in an environment where all the scripts are processed through index.php, which load loadsection.php which does a bunch of things before loading the file I want to debug. So I don't want to break on the first line all the time.
  • Ability to ignore ajax requests that are run by a timer (setTimeout / setInterval). I should be able to say, I don't want to debug these requests because they are ajax requests that happen on a timer. I was in an environment using AJAX IM, which ping the server once every 30 seconds. These ajax requests got in my way when I needed to debug some other script.

http://tech.blog.box.net/2007/06/20/how-to-debug-php-with-vim-and-xdebug-on-linux/
http://2bits.com/articles/using-vim-and-xdebug-dbgp-for-debugging-drupal-or-any-php-application.html

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License