Xdebug 2.0.3 - Stealth Patch

August 4th, 2008 | by Stefan Esser |

On PHP conferences or user group meetings one question that pops up again and again is why Xdebug and some other commercial PHP extensions e.g. Zend Debugger cannot be loaded at the same time. Those asking usually can understand why running two debuggers at the same time will lead to problems, but they don’t understand why problems should arise when only one is used at a time. They want to be able to load Zend Debugger and Xdebug with the same php.ini without the need to restart the whole server just to change the debugger. Because of this people requested repeatedly that I port the stealth magic that I perfom in Suhosin to Xdebug to be able to load both debuggers at the same time.

You can download the patch against Xdebug 2.0.3 at:

http://www.suspekt.org/downloads/xdebug-2.0.3-stealth.diff.gz

Keep in mind that in order to become stealth you must load xdebug like a normal PHP extension with:

extension=xdebug.so

You cannot load it as zend_extension because otherwise the “protection” of the commercial tools will kick in. However when loaded as normal PHP extension Xdebug will register itself as Zend Extension and should function normally.

Attention: I don’t use this patch myself so if you encounter any problem contact me so that I can fix it.

Update: The patch was updated because there was a crash on process termination when stealth mode was not needed. In the comments it is reported that Xdebug still works partially while Zend Debugger is activated.

  1. 8 Responses to “Xdebug 2.0.3 - Stealth Patch”

  2. By Ingo on Aug 4, 2008 | Reply

    So wouldthis in fact make it possible to run Zend debugger and Xdebug side by side?
    The point is that Zend Debugger plays more nice with Eclipse than xdebug does, but xdebug has better output of error messages and also brings in profilling support…

  3. By Stefan Esser on Aug 4, 2008 | Reply

    Because Zend Debugger is closed source and only Zend knows exactly what it does under the hood noone knows if this is possible until you try it.

    The stealth patch does only bypass the “protection” within Zend Debugger against unknown zend extensions. It depends strongly on the coding style of Zend Debugger and Xdebug if you can use them at the same time. From what I know Xdebug tries to always play nice and don’t use dirty tricks. So it is very well possible that both extensions can live together.

  4. By Trevan on Aug 4, 2008 | Reply

    I patched xdebug-2.0.3 and I’m seeing a segfault at the very end of the process. Happens when I run “php -m”, “php -i”, and a script. The backtrace is:

    #0 0xb787761a in ?? ()
    #1 0×082d4d29 in zend_llist_apply ()
    #2 0×082e59c1 in zend_shutdown_extensions ()
    #3 0×082de0a5 in zend_shutdown ()
    #4 0×082a748b in php_module_shutdown ()
    #5 0×08358e43 in main ()

  5. By Trevan on Aug 4, 2008 | Reply

    Oh, and some more information. I have PHP 5.2.4. php -m shows:

    [PHP Modules]
    bcmath
    ctype
    curl
    date
    dom
    filter
    ftp
    gd
    hash
    iconv
    json
    libxml
    mc_hash
    mysql
    mysqli
    openssl
    pcre
    PDO
    pdo_sqlite
    posix
    Reflection
    session
    SimpleXML
    soap
    SPL
    SQLite
    standard
    tokenizer
    trie
    wddx
    xdebug
    xml
    xmlreader
    xmlwriter
    zlib

    [Zend Modules]
    Xdebug

  6. By Trevan on Aug 4, 2008 | Reply

    It looks like you can’t debug using Xdebug when Zend Debugger is enabled. But profiling, tracing, pretty error messages are all working fine.

  7. By Stefan Esser on Aug 4, 2008 | Reply

    Hmmm, I might look into this later. Most probably Zend Debugger grabs some stuff that Xdebug needs ;)

  8. By Gaspar on Aug 26, 2008 | Reply

    I have done the same thing with the Xdebug 2.1-DEV version and its working fine.

    You can grap the file diff here.

    http://www.shortText.com/crkdnu

  1. 1 Trackback(s)

  2. Aug 23, 2008: Recent Faves Tagged With "xdebug" : MyNetFaves

Post a Comment