2010-04-11 04:49 阅读 68


I would like to use GDB to step though the C++ code that makes up the Apache extension. I want to see what PHP is doing while it's running a PHP application. Preferably I would use an IDE like Netbeans or Eclipse on a LAMP system.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongyong9224 dongyong9224 2010-04-11 05:27
    1. You want to get your hands on a debug build of mod_php (with symbols) or build your own (configure --enable-debug)
    2. You should configure your Apache to always keep exactly one worker process instance up (which will be the instance you debug), that is, set MinSpareServers, MaxSpareServers and StartServers all to 1. Also make sure any timeout parameters are generously set
    3. Use gdb or any graphical interface to gdb (such as ddd or Eclipse CDT) to attach to the one and only Apache worker process. Stick a breakpoint in one of the PHP sources etc. and continue.
    4. Point your browser to your webserver and access a PHP page. Your breakpoint will trigger. If you want to wake the debugger at a particular point in your PHP script execution, generate a SIGTRAP from PHP and gdb will normally oblige you.

    Have fun!

    点赞 评论 复制链接分享
  • duanlei2458 duanlei2458 2010-04-11 05:28

    Maybe you could do that on windows.

    However, your best bet is to do this on a Unix box. You will have to compile everything with debugging enabled. GDB will need access to those directories for source.

    Then you will have to run apache and then run the process.

    In order to give yourself time to attache while you are hitting the PHP/Apache with a browser, add a sleep call in the PHP script. If you ps, you will see the process in the sleep state. Or you could just have it write its process id to a file in tmp before it does the sleep.

    点赞 评论 复制链接分享