# Mysterious (to me) Xdebug issue with PHP 7.3

- Thread: https://externals.io/message/103128
- Original archive: https://news-web.php.net/php.internals/103128
- Started by Derick Rethans on 2018-09-04T16:26:49+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #103128 — Derick Rethans — 2018-09-04T16:26:49+00:00

URL: https://externals.io/message/103128#103128

Hi,

I'm finalizing Xdebug support for PHP 7.3, and although I have fixed 
many things, there is one thing that is (currently) eluding me.

The branch I'm working on is 
https://github.com/derickr/xdebug/tree/PHP-7.3-support

With Xdebug (just) loaded, the following script:

        $ cat /tmp/bug01471.php
        <?php
        $c = "aa" == $ff ? 1 : 0;
        ?>

Fails to run with:

        $ php -n -dzend_extension=xdebug.so /tmp/bug01471.php

        Fatal error: Invalid opcode 17/1/8. in /tmp/bug01471.php on line 2

        Call Stack:
            0.0002          0   1. {main}() /tmp/bug01471.php:0

I also see others, like when running with a Composer library:

        $ vendor/bin/phpunit --debug

        Fatal error: Invalid opcode 16/1/2. in /home/derick/dev/php/derickr-mongo-php-library/vendor/composer/autoload_real.php on line 18

        Call Stack:
            0.0003     431424   1. {main}() /home/derick/dev/php/derickr-mongo-php-library/vendor/phpunit/phpunit/phpunit:0
            0.0005     433616   2. require('/home/derick/dev/php/derickr-mongo-php-library/vendor/autoload.php') /home/derick/dev/php/derickr-mongo-php-library/vendor/phpunit/phpunit/phpunit:51
            0.0008     450432   3. ComposerAutoloaderInit96731179a4aab6838b54de3a71995ee1::getLoader() /home/derick/dev/php/derickr-mongo-php-library/vendor/autoload.php:7

And I can't figure out why. The backtrace isn't particularly useful 
either. I got similar issues with get_zval_ptr [1], as it changed, but I 
can't track this specific one down. Would you mind having a look?

cheers,
Derick

[1] https://github.com/derickr/xdebug/commit/70d9189700d57707d842020493a3df23e0c76098
-- 


-- 
https://derickrethans.nl | https://xdebug.org | https://dram.io
Like Xdebug? Consider a donation: https://xdebug.org/donate.php,
or become my Patron: https://www.patreon.com/derickr
twitter: @derickr and @xdebug

---

## #103130 — Dmitry Stogov — 2018-09-05T06:21:18+00:00

URL: https://externals.io/message/103128#103130 · In reply to: #103128

Hi Derick,


The message "Invalid opcode 17/1/8" means that PHP doesn't have handler for opcode 17 (ZEND_IS_EQUAL) where first operand IS_CONST and second operand IS_CV.


ZEND_IS_EQUAL is a commutative operator. zend_vm_gen.php doesn't generate code for ZEND_IS_EQUAL_SPEC_CONST_CV_HANDLER, but PHP code-generator swaps operands, if necessary, to use ZEND_IS_EQUAL_SPEC_CV_CONST_HANDLER.


ZEND_API void ZEND_FASTCALL zend_vm_set_opcode_handler(zend_op* op)
{
    zend_uchar opcode = zend_user_opcodes[op->opcode];
    uint32_t spec = zend_spec_handlers[opcode];

    if (spec & SPEC_RULE_COMMUTATIVE) {
        if (op->op1_type < op->op2_type) {
            zend_swap_operands(op);
        }
    }
    op->handler = zend_vm_get_opcode_handler_ex(spec, op);
}


I have no idea, why PHP with xdebug doen't swap operands.


Thanks. Dmitry.

---

## #103131 — Derick Rethans — 2018-09-05T09:27:56+00:00

URL: https://externals.io/message/103128#103131 · In reply to: #103130

Hi,

in Xdebug, I do supply my own opcode handlers for quite a few opcodes, 
including ZEND_IS_EQUAL, and a whole bunch of others. Is it possible 
that when you use zend_set_user_opcode_handler[1][2] that this swap 
isn't done with zend_swap_operands? My opcode handler basically just 
does some code and then uses ZEND_VM_DISPATCH[3].

[1] https://github.com/derickr/xdebug/blob/PHP-7.3-support/xdebug_code_coverage.h#L47-L48
[2] https://github.com/derickr/xdebug/blob/PHP-7.3-support/xdebug.c#L781
[3] https://github.com/derickr/xdebug/blob/PHP-7.3-support/xdebug_code_coverage.c#L125-L142

cheers,
Derick



> Hi Derick,
> 
> 
> The message "Invalid opcode 17/1/8" means that PHP doesn't have handler for opcode 17 (ZEND_IS_EQUAL) where first operand IS_CONST and second operand IS_CV.
> 
> 
> ZEND_IS_EQUAL is a commutative operator. zend_vm_gen.php doesn't generate code for ZEND_IS_EQUAL_SPEC_CONST_CV_HANDLER, but PHP code-generator swaps operands, if necessary, to use ZEND_IS_EQUAL_SPEC_CV_CONST_HANDLER.
> 
> 
> ZEND_API void ZEND_FASTCALL zend_vm_set_opcode_handler(zend_op* op)
> {
>     zend_uchar opcode = zend_user_opcodes[op->opcode];
>     uint32_t spec = zend_spec_handlers[opcode];
> 
>     if (spec & SPEC_RULE_COMMUTATIVE) {
>         if (op->op1_type < op->op2_type) {
>             zend_swap_operands(op);
>         }
>     }
>     op->handler = zend_vm_get_opcode_handler_ex(spec, op);
> }
> 
> 
> I have no idea, why PHP with xdebug doen't swap operands.
> 
> 
> Thanks. Dmitry.
> 
> ________________________________
> From: Derick Rethans <derick@php.net>
> Sent: Tuesday, September 4, 2018 7:26:49 PM
> To: Dmitry Stogov
> Cc: PHP Developers Mailing List
> Subject: Mysterious (to me) Xdebug issue with PHP 7.3
> 
> Hi,
> 
> I'm finalizing Xdebug support for PHP 7.3, and although I have fixed
> many things, there is one thing that is (currently) eluding me.
> 
> The branch I'm working on is
> https://github.com/derickr/xdebug/tree/PHP-7.3-support
> 
> With Xdebug (just) loaded, the following script:
> 
>         $ cat /tmp/bug01471.php
>         <?php
>         $c = "aa" == $ff ? 1 : 0;
>         ?>
> 
> Fails to run with:
> 
>         $ php -n -dzend_extension=xdebug.so /tmp/bug01471.php
> 
>         Fatal error: Invalid opcode 17/1/8. in /tmp/bug01471.php on line 2
> 
>         Call Stack:
>             0.0002          0   1. {main}() /tmp/bug01471.php:0
> 
> I also see others, like when running with a Composer library:
> 
>         $ vendor/bin/phpunit --debug
> 
>         Fatal error: Invalid opcode 16/1/2. in /home/derick/dev/php/derickr-mongo-php-library/vendor/composer/autoload_real.php on line 18
> 
>         Call Stack:
>             0.0003     431424   1. {main}() /home/derick/dev/php/derickr-mongo-php-library/vendor/phpunit/phpunit/phpunit:0
>             0.0005     433616   2. require('/home/derick/dev/php/derickr-mongo-php-library/vendor/autoload.php') /home/derick/dev/php/derickr-mongo-php-library/vendor/phpunit/phpunit/phpunit:51
>             0.0008     450432   3. ComposerAutoloaderInit96731179a4aab6838b54de3a71995ee1::getLoader() /home/derick/dev/php/derickr-mongo-php-library/vendor/autoload.php:7
> 
> And I can't figure out why. The backtrace isn't particularly useful
> either. I got similar issues with get_zval_ptr [1], as it changed, but I
> can't track this specific one down. Would you mind having a look?
> 
> cheers,
> Derick
> 
> [1] https://github.com/derickr/xdebug/commit/70d9189700d57707d842020493a3df23e0c76098
> --
> 
> 
> --
> https://derickrethans.nl | https://xdebug.org | https://dram.io
> Like Xdebug? Consider a donation: https://xdebug.org/donate.php,
> or become my Patron: https://www.patreon.com/derickr
> twitter: @derickr and @xdebug
> 

-- 
https://derickrethans.nl | https://xdebug.org | https://dram.io
Like Xdebug? Consider a donation: https://xdebug.org/donate.php,
or become my Patron: https://www.patreon.com/derickr
twitter: @derickr and @xdebug

---

## #103132 — Dmitry Stogov — 2018-09-05T10:36:33+00:00

URL: https://externals.io/message/103128#103132

I see the problem, and most probably, it has to be fixed in PHP sources.

I'll try to take a deeper look today evening.


Thanks. Dmitry.

---

## #103134 — Dmitry Stogov — 2018-09-05T19:12:45+00:00

URL: https://externals.io/message/103128#103134

I hope, it's fixed now.

Please verify.


Dmitry.

---

## #103135 — Derick Rethans — 2018-09-06T13:22:21+00:00

URL: https://externals.io/message/103128#103135 · In reply to: #103134

Hi Dmitry,

this indeed seems to fix the problem — thanks!

cheers,
Derick




> I hope, it's fixed now.
> 
> Please verify.
> 
> 
> Dmitry.
> 
> ________________________________
> From: Dmitry Stogov <dmitry@zend.com>
> Sent: Wednesday, September 5, 2018 1:36:33 PM
> To: Derick Rethans
> Cc: PHP Developers Mailing List
> Subject: Re: [PHP-DEV] Re: Mysterious (to me) Xdebug issue with PHP 7.3
> 
> I see the problem, and most probably, it has to be fixed in PHP sources.
> 
> I'll try to take a deeper look today evening.
> 
> 
> Thanks. Dmitry.
> 
> ________________________________
> From: Derick Rethans <derick@php.net>
> Sent: Wednesday, September 5, 2018 12:27:56 PM
> To: Dmitry Stogov
> Cc: PHP Developers Mailing List
> Subject: [PHP-DEV] Re: Mysterious (to me) Xdebug issue with PHP 7.3
> 
> Hi,
> 
> in Xdebug, I do supply my own opcode handlers for quite a few opcodes,
> including ZEND_IS_EQUAL, and a whole bunch of others. Is it possible
> that when you use zend_set_user_opcode_handler[1][2] that this swap
> isn't done with zend_swap_operands? My opcode handler basically just
> does some code and then uses ZEND_VM_DISPATCH[3].
> 
> [1] https://github.com/derickr/xdebug/blob/PHP-7.3-support/xdebug_code_coverage.h#L47-L48
> [2] https://github.com/derickr/xdebug/blob/PHP-7.3-support/xdebug.c#L781
> [3] https://github.com/derickr/xdebug/blob/PHP-7.3-support/xdebug_code_coverage.c#L125-L142
> 
> cheers,
> Derick
> 
> 
> 
> > […]
> 
> --
> https://derickrethans.nl | https://xdebug.org | https://dram.io
> Like Xdebug? Consider a donation: https://xdebug.org/donate.php,
> or become my Patron: https://www.patreon.com/derickr
> twitter: @derickr and @xdebug
> 
> --
> 
> 
> 
> 

-- 
https://derickrethans.nl | https://xdebug.org | https://dram.io
Like Xdebug? Consider a donation: https://xdebug.org/donate.php,
or become my Patron: https://www.patreon.com/derickr
twitter: @derickr and @xdebug
