View Issue Details

IDProjectCategoryView StatusLast Update
0001771XdebugStep Debuggingpublic2020-03-25 15:59
Reportersamuel.nogueira Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
OSLinux 
Product Version2.9.4 
Summary0001771: Cannot step debug fork child processes
Description

While debugging a script which forks, I expected step-debugging to be available in child processes, but only works in the parent process instead (xdebug log in attachment).

Steps To Reproduce

Debug the following script, with 2 breakpoints:

<code php>
<?php

echo "started\n";
if ($child = pcntl_fork()) {
sleep(5);
echo "hello from parent\n"; //breakpoint no. 1 here
pcntl_waitpid($child, $status);
echo "finished\n";
} else {
echo "hello from child\n"; //breakpoint no. 2 here
}
</code>

Expected execution to immediately stop at breakpoint no. 2
Execution stops after 5 seconds at breakpoint no. 1 instead

Additional Information

PHP 7.4.0 (cli) (built: Nov 28 2019 20:31:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.9.4, Copyright (c) 2002-2020, by Derick Rethans

PhpStorm 2019.3.4
Build #PS-193.6911.26, built on March 18, 2020

Docker version 19.03.3, build a872fc2f86

TagsNo tags attached.
Operating SystemLinux
PHP Version7.4.0-7.4.4

Activities

samuel.nogueira

2020-03-24 18:58

reporter   ~0005346

Seems this wasn't an issue in versions prior to 2.7.0, could be related to https://bugs.xdebug.org/view.php?id=938

derick

2020-03-25 11:09

administrator   ~0005347

Hi,

Prior to 2.7.0 this didn't work at all :-)

I think the problem here is that Xdebug only checks whether to make a debug connection when a function is called, otherwise it would be way too slow. (It's already too slow, but there is 0001755, with a PR: https://github.com/xdebug/xdebug/pull/556). I think that if you put the "echo" in a function, and call that function in your "} else {" case, you will see that the forked process will make a separate connection to your IDE.

cheers,
Derick

samuel.nogueira

2020-03-25 11:58

reporter   ~0005348

Couldn't test with newer PHP versions, but at least with PHP 7.2.29 + Xdebug 2.6.1, it was working, execution stopped in each breakpoint, even without changes to the script (still using echo). Kindly see attached Xdebug remote log, Dockerfile and screen cast:

derick

2020-03-25 12:06

administrator   ~0005349

Did you not see/read my second paragraph?

I think the problem here is that Xdebug only checks whether to make a debug connection when a function is called, otherwise it would be way too slow. (It's already too slow, but there is 0001755, with a PR: https://github.com/xdebug/xdebug/pull/556). I think that if you put the "echo" in a function, and call that function in your "} else {" case, you will see that the forked process will make a separate connection to your IDE.

samuel.nogueira

2020-03-25 15:13

reporter   ~0005350

I did, and I did try it out first, but it didn't made a difference, sorry I didn't mention that in the note.
Attached updated script with function calls instead of echo + screen cast + xdebug log.
Please let me know if there's anything I can do to help you replicate the issue.

derick

2020-03-25 15:25

administrator   ~0005351

It works here, see the attached video. Do you have PhpStorm's "Max. simultaneous connections" set to something higher than "1"?

samuel.nogueira

2020-03-25 15:46

reporter   ~0005352

Yup, during both tests 'Max. simultaneous connections' was set to 3.
However, your video showed what I was doing wrong, my PhpStorm was not listening for new connections, so it refused the incoming connection from the child process, and that is why I wasn't able to step-debug the forked process.
My confusing came from the fact that this wasn't needed in versions 2.6.1 and below.
Apologies for taking your time to make me see this, I hope at least someone finds this useful, I know my team will.

For me, issue can be closed, there is no problem after all.

Thank you!

derick

2020-03-25 15:59

administrator   ~0005353

Ah, I see that in your log now:


[1] <- run -i 12
[9] Log closed at 2020-03-25 15:10:37

[9] Log opened at 2020-03-25 15:10:37
[9] I: Connecting to configured address/port: 172.17.0.1:9000.
[9] W: Creating socket for '172.17.0.1:9000', poll success, but error: Operation now in progress (29).
[9] E: Could not connect to client. :-(
[9] Log closed at 2020-03-25 15:10:37

Before Xdebug 2.7, it only worked by chance. Both parent and child would share the same connection, and if data got out of sync in any way, which was quite easy to occur, the debugger would get mega confused. With the fixing of 0000938, it now makes a new connection per child.

If you and your team like it, perhaps you can support me working on Xdebug ;-) -> https://xdebug.org/support