跳转到主要内容
言域 提交于 31 March 2012
pre{ background-color:#EEEEEE; border: 1px dotted #EADEDE; } p{ text-indent: 3em; }

Xdebug 调试器

对于开发者开说,一个调试器可以帮助你跟踪程序每一步是怎样执行的,以及它每一步的效果(就是说产生什么变量,有什么值等),观察函数是怎么调来调去的(学过编程的人应该了解,函数是是栈的形式调用的), 在任何执行时间点查看有什么变量,以及它里面有放什么内容.

说下我的见解,一般看了解别人的程序都是看它们的代码,步骤是按照程序的流程来看。但现在的问题,一个Drupal上万行的代码,要人工地看它每一步是怎么执行的非把人给迫疯不可^_^,

所以有有程序帮助我们,干嘛不用呢,对不?这个程序就是xdebug.

大概原理是:xdebug(php的扩展)会把调试信息发送到远程的9000端口,然后再用komodo客户端监听9000端口,查看调试信息

首先说明,xdebu g只是php的一个扩展

在里面,Xdebug 是一个标准的(就是说官方指定的)工具.

下面是它的官网:

http://xdebug.org/

下面是一些关于配置与使用的文章(没看过,你时间可以看下)

http://devzone.zend.com/article/2803-Introducing-xdebug

http://community.activestate.com/faq/how-do-i-get-php-debuggin

下面那个Drupal的模块有些工具是可以在图形界面查看Xdebug的那个函数调用的

http://drupal.org/project/visualize_backtrace

编译 xdebug.so


其实,在win的环境下那个文件是xdebug.dll,如果你是用的是xampp调试环境,你可以指定在配置文件中加载,因为它己经帮你编译好啦,开心吧)

下面讲的是在Unix-like机器上的。

I downloaded the php package from php.net at http://www.php.net/downloads.php#v5 For Mac 10.4 and 10.5 I have Xcode installed, which includes gcc and other necessary comilation-related packages.

作者在是从 http://www.php.net/downloads.php#v5 上下载的。他的环境是Mac 10.4 和10.5,并且安装好Xcode, 它里面有gcc和其它编译的依赖包(英文的思维跟中文的思维有些逆过来的,哈哈!!!)

To build xdebug.so I went to the directory (assuming you unpack the PHP source code archive in your home dir):

为了编译xdebug.so,到下面的目录(默认你己经解压PHP的源码包到你的家目录啦)

~/php-5.2.5/bin/bin

and ran:

然后运行:

$ ./pecl install xdebug

this built xdebug.so and placed it in the direcrtory:

这样会编译xdebug.so, 然后会把它放到下面的目录啦:

~/php-5.2.5/bin/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so

整合MAMP+Komodo IDE(For the particular combination of MAMP + Komodo IDE)

For my version of MAMP I copied xdebug.so to the following dir (final dir name may vary by PHP version):

对于我的MAMP版本,我复制xdebug.so到下面的目录:

/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/

make sure Zend optimizer is OFF in MAMP preferences.

应先确实Zend optimizer 己经关闭了啦

Make sure to restart apache after making these changes to php.ini. After verifying the location of xdebug.so, add the following to your php.ini file (or perhaps /etc/php5/conf.d/xdebug.ini, depending on your operating system):

改变配置环境后,必须要重启apache加载配置php.ini.

zend_extension=/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000

OR, you can add this to .htaccess in your Drupal root or a parent dir:

php_value xdebug.remote_enable on

These (among others) may also be useful to add to .htaccess if you want to profile memory usage:

php_value xdebug.auto_trace On
php_value xdebug.show_mem_delta On

To debug in Komodo, make sure Debug >> Listen for Debug Connections is enabled. In Drupal, add the query string: ?XDEBUG_SESSION_START=1 .

为了在Komodo中接受调试,应Komodo监听9000端口,然后再url后面加上?XDEBUG_SESSION_START=1 ,后php会发送信息到9000端口,这时再查看komodo就知道是怎么加事啦

Alternatively, using the "easy Xdebug" extension for Firefox or the Xdebug helper for Chrome, you can initiate an Xdebug session with one click, instead of having to add the query string.

下面是我找到的非常好的两个视频

橡皮树作品:PHP调试,使用Komodo和Xdebug进行PHP程序的调试 - 1

橡皮树作品:PHP调试,使用Komodo和Xdebug进行PHP程序的调试 - 2