XDebug breakpoint giving errors with PHP in Visual Studio Code

Viewed 845

I'm trying to set a breakpoint in PHP code using XDebug with Visual Studio Code, which is all installed on an Ubuntu Hyper-V virtual machine. I'm on PHP 7.2.

Whenever I set a breakpoint in my PHP code and refresh a page which should hit the breakpoint, I get the errors "command is not available" and "no such breakpoint" shown in popups in Visual Studio Code. I also get the following error in the Debug Console.

XDebugError: command is not available
    at new Response (/home/ben/.vscode/extensions/felixfbecker.php-debug- 
1.13.0/out/xdebugConnection.js:56:19)
    at new BreakpointSetResponse (/home/ben/.vscode/extensions/felixfbecker.php-debug- 
1.13.0/out/xdebugConnection.js:207:9)
    at Connection.<anonymous> (/home/ben/.vscode/extensions/felixfbecker.php-debug 
1.13.0/out/xdebugConnection.js:599:20)
    at Generator.next (<anonymous>)
    at fulfilled (/home/ben/.vscode/extensions/felixfbecker.php-debug-1.13.0/out/xdebugConnection.js:4:58) {
  code: 5,
  name: 'XDebugError'
}

Based on my research, I think the problem is because XDebug doesn't work with IPv6, but the debugger is listening on v6. If I do netstat -an | grep 9000, I get

tcp6       0      0 :::9000                 :::*                    LISTEN  

Here are the contents of /etc/php/7.2/fpm/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.var_display_max_depth=-1
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1

How do I fix this problem and get my breakpoint to work?

2 Answers

I debug using these extensions:

  • PHP Debug (by Robert Lu)
  • PHP Intelephense (by Ben Mewburn)

Please check the XDebug configuration for your project. It is a launch.json in a .vscode folder in you projec root directoryt. If it is missing, then you must created in the Debug settings of Visual Studio Code (The gear wheel button).

It should look like this:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for Xdebug",
        "type": "php",
        "request": "launch",
        "port": 9000
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}"
    }
]

}

This was fixed a while back in PHP Debug extension. Here is an issue that talks about it and a linked pull request.

Due to the "synchronous" nature of Xdebug/DBGp and the "asynchronous" one of VS Code it happened a lot that when multiple PHP processes connected to PHP Debug an overlapping of "add add", "remove remove", "add add" process of adding and removing of breakpoints would happen. Due to this conflict the extension ended up trying to remove a breakpoint that was already removed, and such - not very helpful - exception was presented.

I'm continuing development of PHP Debug so if you have problems or bugs file them there please.

Related