Vimでxdebugを使ってphpをトレース実行する
環境準備
xdebugの設定
/etc/php5/conf.d/xdebug.ini に
xdebug.remote_enable=On
xdebug.remote_host=localhost
を書き足す。
zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so xdebug.remote_enable=On xdebug.remote_host=localhost
apacheは再起動すること。
vimの準備
NeoBundle を使ってインストールします。
(NeoBundleについては、http://vim-users.jp/2011/10/hack238/ こちらで)
.vimrcに
NeoBundle 'git://github.com/joonty/vim-xdebug.git'
を記載して、
:NeoBundleInstall
を実行するだけ。
トレース実行
ブレークポイント設定およびリモートデバッグ待ち受けの開始
vimでphpのソースコードを開く
ブレイクしたいところで
:Bp
するとブレークポイントとして行の色が反転する
その[F5]を押してから、
Waiting for a connection (this message will self-destruct in 30 seconds...)
と表示されるので、その間にブラウザで対象ページに
パラメータ「XDEBUG_SESSION_START」を付けて開く
http://localhost/test.php?XDEBUG_SESSION_START
操作方法
phpページを上記のようなURLでアクセスすると、vimがデバッグモードになる。
操作方法は下の通り
[ Function Keys ] | <F1> resize | [ Normal Mode ] <F2> step into | ,e eval <F3> step over | <F4> step out | <F5> run | [ Command Mode ] <F6> quit debugging | :Bp toggle breakpoint | :Up stack up <F11> get all context | :Dn stack down <F12> get property at cursor |