Vim でプラグインの Vdebug をインストールしてデバッグします。
Contents
まずは Vundle をインストール
1 2 |
$ cd ~ $ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim |
Vim の Plugin 設定
編集ファイル
1 |
$ vim ~/.vimrc |
編集内容
1 2 3 4 5 6 7 8 9 10 |
" Vundleの設定 set rtp+=~/.vim/bundle/Vundle.vim " 開始 call vundle#begin() Plugin 'gmarik/Vundle.vim' call vundle#end() " 終了 " プラグイン追加 Plugin 'joonty/vdebug.git' |
Vdebugのインストール
プラグインを追加
1 |
$ vim +BundleInstall +qall |
PECLのインストール
1 |
sudo apt-get install php-pear |
xdebugのインストール
1 |
sudo pecl install xdebug |
xdebugの設定
1 |
$ vim /etc/php.d/xdebug.ini |
編集内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
zend_extension=/usr/lib64/php/modules/xdebug.so [debug] xdebug.auto_trace=0 xdebug.cli_color=0 xdebug.collect_assignments=0 xdebug.collect_includes=1 xdebug.collect_params=0 xdebug.collect_return=0 xdebug.collect_vars=0 xdebug.coverage_enable=1 xdebug.default_enable=1 xdebug.dump.*= xdebug.dump_globals=1 xdebug.dump_once=1 xdebug.dump_undefined=0 xdebug.extended_info=1 xdebug.file_link_format= xdebug.force_display_errors=0 xdebug.force_error_reporting=0 xdebug.halt_level=0 xdebug.idekey= xdebug.manual_url="http://www.php.net" xdebug.max_nesting_level=100 xdebug.overload_var_dump=1 xdebug.profiler_append=0 xdebug.profiler_enable=0 xdebug.profiler_enable_trigger=0 xdebug.profiler_output_dir="/tmp" xdebug.profiler_output_name="cachegrind.out.%p" xdebug.remote_autostart=0 xdebug.remote_connect_back=0 xdebug.remote_cookie_expire_time=3600 ;xdebug.remote_enable=0 xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host="localhost" xdebug.remote_log= xdebug.remote_mode="req" xdebug.remote_port=9000 xdebug.scream=0 xdebug.show_exception_trace=0 xdebug.show_local_vars=0 xdebug.show_mem_delta=0 xdebug.trace_enable_trigger=0 xdebug.trace_format=0 xdebug.trace_options=0 xdebug.trace_output_dir="/tmp" xdebug.trace_output_name="trace.%c" xdebug.var_display_max_children=128 xdebug.var_display_max_data=512 xdebug.var_display_max_depth=3 |
debug用
編集ファイル
1 |
$ vim php-xdebug |
編集内容
1 |
#!/bin/bash export XDEBUG_CONFIG="idekey=xdebug" /usr/bin/php "$@" |
実行権限付与
1 |
$ chmod +x php-xdebug |
デバッグ状態にする
1 |
$ vim /var/www/html/Welcome.php |
F10でブレークポイントを指定
F5で実行
となります。
別ウィンドウでPHP実行
1 |
$ ./php-xdebug /var/www/html/index.php Welcom |
操作
- <F5>: デバッガの起動 / 次のブレイクポイントまで移動
- <F2>: ステップオーバー
- <F3>: ステップイン
- <F4>: ステップアウト
- <F6>: デバッガの停止
- <F7>: デバッガーからデタッチ
- <F9>: カーソル行まで実行
- <F10>: ブレイクポイントの設定
- <F11>: show context variables (e.g. after "eval")
- <F12>: カーソル行の変数を評価
- :Breakpoint <type> <args>: 色んな種類のブレイクポイントが打てる。 (see :help VdebugBreakpoints)
- :VdebugEval <code>: <code>の変数を評価
- <Leader>e: evaluate the expression under visual highlight and display the result
まとめ
操作は簡単なので手軽にVimでブレイクしたいときにおすすめです。
参考
joonty/vdebug: Multi-language DBGP debugger client for Vim (PHP, Python, Perl, Ruby, etc.)
何も考えず~/.vimrcにこれを書くんだ! 〜vim初心者によるvim初心者のためのvim入門〜
Vagrant上のPHPを Xdebug + NetBeans(おまけでVisual Studio Codeでも)でリモートデバッグする