View Issue Details

IDProjectCategoryView StatusLast Update
0001772XdebugUncategorizedpublic2020-04-04 11:08
Reporterbag64 Assigned Toderick  
PriorityhighSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Product Version2.9.4 
Target Version2.9.5Fixed in Version2.9.5 
Summary0001772: Crash with exception thrown inside a destructor
Description

PHP crashes when XDebug is enabled.
And this only happens when code is wrapped in a PHPunit test for some reason, here's a snipet of the code:

class X
{
public function __destruct(){
throw new \Exception('eee');
}
}

class InstanceTest extends \PHPUnit\Framework\TestCase
{

// This part is important, and is what's causing the crash:
private ?X $x = null;
function get_instance():X{return $this->x = $this->get_new_instance();}
function get_new_instance():X{return new X();}

public function test_instance()
{
    $this->get_instance();
    $this->assertTrue(true);
}

}

Result = Process finished with exit code -1073741819 (0xC0000005)

Steps To Reproduce

just run phpunit with instanceTest.php (file attached)

Additional Information

Tested on both: (same error)

php_xdebug-2.9.2-7.4-vc15-x86_64.dll
php_xdebug-2.9.4-7.4-vc15-x86_64.dll

PHPUnit version: 8.4.3

TagsNo tags attached.
Attached Files
InstanceTest.php (514 bytes)   
<?php


class X
{
    public function __destruct(){
        throw new \Exception('eee');
    }
}


class InstanceTest extends \PHPUnit\Framework\TestCase
{

    // This part is important, and is what's causing the crash:
    private ?X $x = null;
    function get_instance():X{return $this->x = $this->get_new_instance();}
    function get_new_instance():X{return new X();}


    public function test_instance()
    {
        $this->get_instance();
        $this->assertTrue(true);
    }
}
InstanceTest.php (514 bytes)   
php_crash.png (39,743 bytes)   
php_crash.png (39,743 bytes)   
windows.zip (2,530,352 bytes)
derick_phperrorerror.log (867 bytes)   
[03-Apr-2020 09:54:12 UTC] PHP Fatal error:  Uncaught Exception: eee in C:\Users\Pc\Desktop\24h_del\windows\CrashTest.php:9
Stack trace:
#0 [internal function]: X->__destruct()
#1 {main}
  thrown in C:\Users\Pc\Desktop\24h_del\windows\CrashTest.php on line 9
[03-Apr-2020 09:54:12 UTC] PHP Stack trace:
[03-Apr-2020 09:54:12 UTC] PHP   1. {main}() C:\Users\Pc\Desktop\24h_del\windows\vendor\phpunit\phpunit\phpunit:0
[03-Apr-2020 09:54:12 UTC] PHP   2. PHPUnit\TextUI\Command::main() C:\Users\Pc\Desktop\24h_del\windows\vendor\phpunit\phpunit\phpunit:61
[03-Apr-2020 09:54:12 UTC] PHP   3. PHPUnit\TextUI\Command->run() C:\Users\Pc\Desktop\24h_del\windows\vendor\phpunit\phpunit\src\TextUI\Command.php:160
[03-Apr-2020 09:54:12 UTC] PHP   4. PHPUnit\TextUI\TestRunner->run() C:\Users\Pc\Desktop\24h_del\windows\vendor\phpunit\phpunit\src\TextUI\Command.php:200
derick_phperrorerror.log (867 bytes)   
derick_phpinfo.log (3,111 bytes)   
phpinfo()
PHP Version => 7.4.4

...

display_errors => STDOUT => STDOUT
display_startup_errors => On => On
error_reporting => 32767 => 32767
html_errors => Off => Off

...

xdebug

xdebug support => enabled
Version => 2.9.4
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support

Debugger => enabled
IDE Key => xdebug

Directive => Local Value => Master Value
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => C:\Windows\Temp => C:\Windows\Temp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => xdebug => xdebug
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => On => On
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => c:/wamp64/tmp => c:/wamp64/tmp
xdebug.profiler_output_name => cachegrind.out.%t.%p => cachegrind.out.%t.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_host => 127.0.0.1 => 127.0.0.1
xdebug.remote_log => c:/wamp64/tmp/xdebug/xdebug_remot.log => c:/wamp64/tmp/xdebug/xdebug_remot.log
xdebug.remote_log_level => 7 => 7
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => On => On
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => C:\Windows\Temp => C:\Windows\Temp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

...
derick_phpinfo.log (3,111 bytes)   
derick_phpxdebug.ini (1,039 bytes)   
#
#	My php.ini
#


[xdebug]

zend_extension = "c:/wamp64/bin/php/php7.4.4/zend_ext/php_xdebug-2.9.4-7.4-vc15-x86_64.dll"


xdebug.remote_enable = off
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0

; fd dbg etc:

xdebug.remote_port = 9001
xdebug.remote_enable = On
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = On
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "c:/wamp64/tmp"

; call: XDEBUG_SESSION_START
; For notepad++:

xdebug.profiler_enable = 0
xdebug.profiler_append=0
xdebug.extended_info=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=xdebug
xdebug.remote_log="c:/wamp64/tmp/xdebug/xdebug_remot.log"
xdebug.show_exception_trace=0
xdebug.show_local_vars=9
xdebug.show_mem_delta=0
xdebug.trace_format=0


derick_phpxdebug.ini (1,039 bytes)   
xdebug_crash.rar (2,263,738 bytes)
Operating SystemWindows 7
PHP Version7.4.0-7.4.4

Activities

bag64

2020-04-02 17:47

reporter   ~0005362

I attached a complete workspace example (nothing to setup)
Just double click "crash_test_windows.bat" on Windows and see the crash in action.

I don't know about linux, but "crash_test_linux.sh" should also work in theory.

I hope this could help.

derick

2020-04-03 00:03

administrator   ~0005363

I can't reproduce this (on Linux). I had to do "rm -rf vendor" and "composer install" to make the code run, but I am not getting a crash (or a valgrind memory checking warning). Which settings do you have enabled for PHP/Xdebug? Can you check the html_errors, display_errors, and error_reporting settings, as well as the phpinfo section of Xdebug, and attach these as a file? You can get these by running "php -i" (but please leave out the things I didn't ask for).

bag64

2020-04-03 10:10

reporter   ~0005365

Would you like me to setup and attach a Standalone test environement (that includes php binaries) and upload it here for you to test and execute ?
In the meanwhile I will try to setup this and test it in linux and report back if I find anything.

derick

2020-04-03 10:18

administrator   ~0005366

Happy to test a specific set-up that you can make and share. I'm not quite sure what that would include though? I don't think this bug system wants really large files :-)

bag64

2020-04-03 11:32

reporter   ~0005367

Hi Derick. Yes I'm aware of the 5MB limit :( This is why I made this batch script for you,
and it is (x86) 32bits compatible so you can run in any Win7+ Virtual Machine painlessly.

You need to download: https://windows.php.net/downloads/releases/php-7.4.4-nts-Win32-vc15-x86.zip
And extract it in "./php" folder, WITHOUT overriding the exisiting files.

Also, you need to extract this in "C:\xdebug_crash" for it to work properly.

Once you setup the workspace, you will notice a curios phenomenon:
If you double click "crash_test.bat" it will crash, but if you edit "CrashTest.php" and replace

public function test_crash()
{
$this->get_instance();
$this->assertTrue(true);
}

by

public function test_crash()
{
$this->get_new_instance(); // <-- notice "new"
$this->assertTrue(true);
}

It will NOT crash ! weird huh..
Let me know if the workspace works for you and if you were able to see it crash.

bag64

2020-04-03 11:41

reporter   ~0005368

for sake of clarity here's the steps again:

1) Download "xdebug_crash.rar" above and extract content in "c:\xdebug_crash\"
2) Download "php-7.4.4-nts-Win32-vc15-x86.zip" above and extract content in "c:\xdebug_crash\php\"
3) Run "crash_test.bat" (Expecting crash)
4) Edit "CrashTest.php" and replace "get_instance" by "get_new_instance()" as explained above
5) Run "crash_test.bat" (Expecting NO crash this time)

derick

2020-04-03 12:14

administrator   ~0005370

I don't have Windows at all, so that makes testing on it hard...

bag64

2020-04-03 12:31

reporter   ~0005371

Oh. I could setup a temporary VNC for you if it could help.
Either VNC, RDP, TeamViewer or whatever would work and help you, would that be ok ?

derick

2020-04-03 14:15

administrator   ~0005372

Hey,

thanks for setting that up. I've managed to find where the problem is, and I can now reproduce this locally on Linux. I also have a fix already, but I would like to come up with a small reproducible case before I commit this.

cheers,
Derick

bag64

2020-04-03 14:27

reporter   ~0005373

Happy to hear that :-) And sorry for making you go through that VS registration pain.
I'll make sure it's up to date next time
Thank you !

derick

2020-04-04 10:01

administrator   ~0005375

This is now fixed in Git. Once AppVeyor finishes building the binaries, you can find your right configuration at https://ci.appveyor.com/project/derickr/xdebug/builds/31949378 . Click on the configuration, and then the artifacts tab. I did not manage to make a small reproducible case unfortunately.

bag64

2020-04-04 11:08

reporter   ~0005376

Great ! Problem seems to be solved, no more crashes :)

Issue History

Date Modified Username Field Change
2020-04-02 15:48 bag64 New Issue
2020-04-02 15:48 bag64 File Added: InstanceTest.php
2020-04-02 15:48 bag64 File Added: php_crash.png
2020-04-02 17:47 bag64 File Added: windows.zip
2020-04-02 17:47 bag64 Note Added: 0005362
2020-04-03 00:03 derick Assigned To => derick
2020-04-03 00:03 derick Status new => feedback
2020-04-03 00:03 derick Note Added: 0005363
2020-04-03 10:04 bag64 File Added: derick_phperrorerror.log
2020-04-03 10:04 bag64 File Added: derick_phpinfo.log
2020-04-03 10:04 bag64 File Added: derick_phpxdebug.ini
2020-04-03 10:10 bag64 Note Added: 0005365
2020-04-03 10:10 bag64 Status feedback => assigned
2020-04-03 10:18 derick Note Added: 0005366
2020-04-03 11:32 bag64 File Added: xdebug_crash.rar
2020-04-03 11:32 bag64 Note Added: 0005367
2020-04-03 11:41 bag64 Note Added: 0005368
2020-04-03 12:14 derick Note Added: 0005370
2020-04-03 12:31 bag64 Note Added: 0005371
2020-04-03 14:15 derick Note Added: 0005372
2020-04-03 14:27 bag64 Note Added: 0005373
2020-04-04 09:34 derick Target Version => 2.9.5
2020-04-04 09:34 derick Summary PHP/XDebug crash whenever Exception thrown inside a destructor, in PHPUnit => Crash with exception thrown inside a destructor
2020-04-04 09:34 derick Description Updated
2020-04-04 09:34 derick Additional Information Updated
2020-04-04 10:01 derick Status assigned => closed
2020-04-04 10:01 derick Resolution open => fixed
2020-04-04 10:01 derick Fixed in Version => 2.9.5
2020-04-04 10:01 derick Note Added: 0005375
2020-04-04 11:08 bag64 Note Added: 0005376