Zend Engine question

php.internals

Wojtek Meler

22 years ago
Are there any tools for debugging ZE? I've got a problem with huge script that at some point behave like all variables were reference to single variable. I suspect that there is something wrong with EG(uninitialized_zval). Any hints how to fight it? I've compiled it with ZEND_INTENSIVE_DEBUGGING and it found nothing. When I debug it with simple debugger I can see that all ZEND_FETCH_W opcodes receives the same zval address and ZEND_ASSIGN doesn't change it. I don't know how it should work yet, but I'll learn it soon. Maybe someone could give me a piece of advice? Regards, Wojtek

Moriyoshi Koizumi

22 years ago
Hi, First, maybe you want to see bug #22836 (http://bugs.php.net/22836), that appears to describe the very problem you have. Secondly, you can use various custom gdb macros like printzv, printzn which are defined in .gdbinit on top of the php source tree. Moriyoshi Wojtek Meler <wmeler@wp-sa.pl> wrote:

Wojtek Meler

22 years ago
Moriyoshi Koizumi wrote:
>Hi, > >First, maybe you want to see bug #22836 (http://bugs.php.net/22836), that appears to describe the very problem you have. >
Probably yes. I assume that it won't be fixed in ZE1, will it? Is there any way to fix it for own risk? I saw something in zend_execute.c with comment "too dengerous for ZE1"
>Secondly, you can use various custom gdb macros like printzv, printzn >which are defined in .gdbinit on top of the php source tree. > >
Cool!!! I used my own gdb script, but this one is great. regards, Wojtek

Moriyoshi Koizumi

22 years ago
Wojtek Meler <wmeler@wp-sa.pl> wrote:
> Moriyoshi Koizumi wrote: > > >Hi, > > > >First, maybe you want to see bug #22836 (http://bugs.php.net/22836), that appears to describe the very problem you have. > > > Probably yes. I assume that it won't be fixed in ZE1, will it? > Is there any way to fix it for own risk? I saw something in > zend_execute.c with comment "too dengerous for ZE1"
Nope, it was decided long ago that the bug won't be fixed in ZE1. AFAIC there's been no definite cure so far, but perhaps it can be fixed somehow though I didn't managed to conceive anything reasonable.
> >Secondly, you can use various custom gdb macros like printzv, printzn > >which are defined in .gdbinit on top of the php source tree. > > > > > Cool!!! I used my own gdb script, but this one is great.
Thanks. Actually most of those are my work :) Moriyoshi

Wojtek Meler

22 years ago
Moriyoshi Koizumi wrote:
>>Moriyoshi Koizumi wrote: >>>First, maybe you want to see bug #22836 (http://bugs.php.net/22836), that appears to describe the very problem you have. >>> >> >>Probably yes. I assume that it won't be fixed in ZE1, will it? >>Is there any way to fix it for own risk? I saw something in >>zend_execute.c with comment "too dengerous for ZE1" > > > Nope, it was decided long ago that the bug won't be fixed in ZE1. > AFAIC there's been no definite cure so far, but perhaps it can be fixed > somehow though I didn't managed to conceive anything reasonable.
OK, so the reason for this bug is referencing EG(uninitialized_zval) ? I can't find place in code where it is (really big script). Is it possible to add some code to execute loop to check if this happens and bailout with zend_error ? I could locate this piece of code and workaround it then. I tried to watch if EG(uninitialized_zval).refcount>2 but it doesn't work. Any suggestions ? Regards, Wojtek

Moriyoshi Koizumi

22 years ago
Wojtek Meler <wmeler@wp-sa.pl> wrote:
> OK, so the reason for this bug is referencing EG(uninitialized_zval) ? > I can't find place in code where it is (really big script). > Is it possible to add some code to execute loop to check if this > happens and bailout with zend_error ? I could locate this piece of code > and workaround it then. > I tried to watch if EG(uninitialized_zval).refcount>2 but it doesn't work. > Any suggestions ?
Hmm, EG(uninitialized_zval) is not the only player within this issue. The basic problem is caused by malfunction of return-by-reference that occurs when the returnee is a zval that has been originated from a non-variable scalar. - bug #22367 (http://bugs.php.net/22367) http://cvs.php.net/cvs.php/php-src/tests/lang/bug22367.phpt - bug #22510 (http://bugs.php.net/22510) http://cvs.php.net/cvs.php/php-src/tests/lang/bug22510.phpt - bug #22592 (http://bugs.php.net/22592) http://cvs.php.net/cvs.php/php-src/tests/lang/bug22592.phpt Those bugs are also involved. Regards, Moriyoshi

Wojtek Meler

22 years ago
Moriyoshi Koizumi wrote:
> Nope, it was decided long ago that the bug won't be fixed in ZE1. > AFAIC there's been no definite cure so far, but perhaps it can be fixed > somehow though I didn't managed to conceive anything reasonable.
It seams that enabling this helps: #if 0 /* Will be fixed in ZE2, too dangerous to touch in the context of ZE1 */ if (*retval_ptr_ptr == EG(uninitialized_zval_ptr) && PZVAL_IS_REF(*retval_ptr_ptr)) { zend_error(E_ERROR, "Cannot modify a reference to NULL"); } #endif Do you know why it is dengerous? BC? This of course doesn't solve prolbem with assigning reference from return value of function which doesn't return reference, but it can be supported with additional opcode. How about it? Regards, Wojtek