在vim 下debug php (use xdebug)

May 14, 2008

1.VIM 的部份
在你的vim 下
:version
看看有沒有+python 和+sign
沒的話….
把vim 重裝…
#make install WITH_PYTHON
這樣應該就會有了…

2.安裝Script
去這個地方抓

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

放到/usr/local/share/vim/vim71/plugin/底下…

3.安裝xdebug
#cd /usr/ports/devel/php-xdebug
#make install
#vim /usr/local/etc/php.ini
[sourcecode language='text']
[Zend]
zend_extension = /full/path/to/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_host = localhost
[/sourcecode]
加入上面這幾行..
看一下phpinfo 有沒有出現xdebug

4.
然後開browser run你的url 後面的?XDEBUG_SESSION_START=1 這是重點..
例如 http://example.com/index.php?XDEBUG_SESSION_START=1

5.
#vim xxx.php
然後按F5
下面就會出現
waiting for a new connection on port 9000 for 5 seconds
然後這時後你有五秒去開你的url
例如

http://example.com/xxx.php

再回去看你的vim 就開始在debug ……….

到這邊就差不多了…

PS
1.
如果phpinfo 告訴你
XDEBUG NOT LOADED AS ZEND EXTENSION
那這樣是沒辦法…..去debug 的雖然可以F5 去跑..
不過step over 之類的都不能用…

2.
因為…我在vim 下按 F2 F3 會轉換大小寫…和他的function key 有衝到…
去看debugger.vim 下..
他有這段
map <Leader>dr :python debugger_resize()<cr>
map <Leader>di :python debugger_command(‘step_into’)<cr>
map <Leader>do :python debugger_command(‘step_over’)<cr>
map <Leader>dt :python debugger_command(‘step_out’)<cr>

<Leader> = \
所以我step over 是用 \do
以此類推..

希望對有用vim 的同好有幫助 。
^^
我終於可以脫離”print 大法”了…..

Ref.
http://2bits.com/articles/using-vim-and-xdebug-dbgp-for-debugging-drupal-or-any-php-application.html
How do debug php with vim and xdebug on linux

tags: , ,
posted in 有的沒的 by johnpupu

Follow comments via the RSS Feed | Leave a comment | Trackback URL

3 Comments to "在vim 下debug php (use xdebug)"

  1. gala4th wrote:

    嘗試了好一段時間,如果有這樣的設定:

    map :python debugger_command(‘step_into’)

    那麼,直接用 vim ,然後按 F2 是正常的

    但是,如果是 GNU screen + vim ,按 F2 則會會變成 “轉換大小寫” 的功能

    另個解決方法是:
    map ^[[12~ :python debugger_command(‘step_into’)

    注意,輸入的方式是 press the key followed by F2 key

    Reference: http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_2%29

  2. gala4th wrote:

    系統會把 tag 吃掉,重貼一次

    嘗試了好一段時間,如果有這樣的設定:

    map <F2>:python debugger_command(’step_into’)<cr>

    那麼,直接用 vim ,然後按 F2 是正常的

    但是,如果是 GNU screen + vim ,按 F2 則會會變成 “轉換大小寫” 的功能

    另個解決方法是:
    map ^[[12~ :python debugger_command(’step_into’)<cr>

    注意,輸入的方式是 press the key followed by F2 key

  3. johnpupu wrote:

    gala4th :

    系統會把 tag 吃掉,重貼一次

    嘗試了好一段時間,如果有這樣的設定:

    map <F2>:python debugger_command(’step_into’)<cr>

    那麼,直接用 vim ,然後按 F2 是正常的

    但是,如果是 GNU screen + vim ,按 F2 則會會變成 “轉換大小寫” 的功能

    另個解決方法是:
    map ^[[12~ :python debugger_command(’step_into’)<cr>

    注意,輸入的方式是 press the key followed by F2 key

    感謝你的提醒^^

Leave Your Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org