[xdebug-general] Win32 Exceptions (Possible Solutions)

From: Jason Riffel <jason[@]cipreporting.com>
Date: Tue, 24 Feb 2009 23:29:30 -0500

Hello, I wanted to report some problems I had with xdebug on windows and
how I solved them. I think others are seeing these issues depending on
their configuration. My system is a full WAMP stack built from sources
on a Windows XP SP2 machine using Visual Studio 2009 with the entire
WAMP stack build in debug mode with full debug symbols.

As soon as I would try and make a web request with xdebug loaded it
would throw an exception in the function 'xdebug_init_oparray'. I did
notice that if I built the system in release mode I could load pages
without an exception, but as soon as I enabled the remote debugger it
would throw an exception. I returned to the debug mode version and
using the debugger I was able to see that this line (in
xdebug_init_oparray):

    op_array->reserved[XG(reserved_offset)] = 0;

was throwing an exception - specifically the part 'XG(reserved_offset)'
returns an out of range index for 'op_array->reserved'. It looked to me
like the value reserved_offset was uninitialized, most likely only
uninitialized on debug builds?. My lack of experience with Zend / PHP
internals stopped me from figuring out more. I patched this function to
validate the index and this exception went away, here's the patch:

diff -Naur xdebug-2.0.4/xdebug.c xdebug-2.0.4.fixed/xdebug.c
--- xdebug-2.0.4/xdebug.c 2009-02-24 22:54:21.359375000 -0500
+++ xdebug-2.0.4.fixed/xdebug.c 2009-02-24 22:32:18.453125000 -0500
@@ -3151,8 +3151,11 @@
 
 ZEND_DLEXPORT void xdebug_init_oparray(zend_op_array *op_array)
 {
+ int offset;
     TSRMLS_FETCH();
- op_array->reserved[XG(reserved_offset)] = 0;
+ offset = XG(reserved_offset);
+ if (offset < 0 || offset > (ZEND_MAX_RESERVED_RESOURCES-1)) return;
+ op_array->reserved[offset] = 0;
 }
 
 #ifndef ZEND_EXT_API

This seems to be an exception thrown on debug builds for any page loaded
even if remote debugging is disabled, once past this exception I was
able to enable the remote debugger and I was getting another
exception... Using the debugger I could see there were problems with
xdebug calling back to php5ts.dll, specifically calling into
php_setcookie was throwing an exception. I was able to see that upon
calling into php_setcookie, the thread safety context in PHP (tsrmls)
was NULL. This value is passed from function to function with a macro
system in the Zend code and I was able to see it was passed into xdebug
just fine, but got lost calling out from xdebug back to php5ts. I was
able to finally discover that in my case the type 'time_t' was 32 bit in
the PHP dll, but 64 bit in the xdebug dll, thus throwing off my parameters.

This happens because on Win32 time_t is moving (or moved) to a 64 bit
value, but it can be switched back to 32 bits. Apparently PHP is
switching it down to 32 bits either through the the _WIN32_WINNT macro
or the _USE_32BIT_TIME_T macro. Either way, I had to rebuild xdebug
using these macros to control the size of the time_t type so that my
calls back into php5ts.dll were proper. Here's the macros I added to
the Win32 build for xdebug:

/D _USE_32BIT_TIME_T /D _WIN32_WINNT=0x501

After applying the above patch and adding these build macros I was able
to build and run my own xdebug.dll against my own PHP. I hope this
helps others!

--Jason Riffel
Received on Wed Feb 25 2009 - 05:47:57 GMT

This archive was generated by hypermail 2.2.0 : Mon Jun 25 2018 - 06:00:04 BST