Xdebug V3 不会在 VSCode 中停止断点

Xdebug V3 doesn't stop breakpoints in VSCode

我正在尝试使用 VSCode 在我的 XAMPP 上进行调试,但没有成功。我知道有很多关于此的问题,我已尽我所能,但仍然无法正常工作。

关于我的 xdebug extension.I 我目前使用的是 PHP v7.4.12 和 Xdebug 版本 3。

我知道我的 Xdebug 在 PHP 上工作,因为我查看了 phpinfo(),它显示了我的设置方式。奇怪的部分是在许多教程中,通常 zend_extension = path..xdebug.remote_enable = 1xdebug.remote_autostart = 1 应该足够了,但是当我查看 phpinfo 时,它如下所示:

我尝试用 xdebug.remote_port = 9000xdebug.remote_host = "localhost" 设置它,但仍然不起作用。我什至读过有关将 localhost 更改为 127.0.0.1 的信息,但仍然没有用。

如有任何帮助,我们将不胜感激。这是我的 launch.json 文件和 php ini 文件。

php.ini

zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_log = "C:\xampp\tmp\xdebug\xdebug.log"
xdebug.remote_port = 9000
xdebug.remote_host = "127.0.0.1"
xdebug.idekey=VSCODE

launch.json

{
    // 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": "Launch current script in console",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "port": 9000
        },
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        }
    ]
}

如果是因为没有设置“pathMappings”造成的,谁能教我怎么用?

顺便说一下,xdebug.log 也不起作用

您正在使用 Xdebug v3,但继续使用 Xdebug v2 配置参数。您需要完成 Upgrading from Xdebug 2 to 3 Guide 并调整您的设置。

Xdebug v3 使用与 Xdebug v2 不同的 配置参数(你的 phpinfo() 输出在你的屏幕截图上准确地告诉你 ) . 6 个“xdebug”中的 5 个。当前 php.ini 的参数在 Xdebug v3.

中做 nothing

对于 Xdebug 3 它应该是这样的(基于你原来的配置):

zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.client_host = "127.0.0.1"
xdebug.log = "C:\xampp\tmp\xdebug\xdebug.log"
xdebug.idekey = VSCODE

OS: Windows 10

VS Code 将断点标记为“未验证断点”。

就我而言,我必须添加“pathMappings”:

"configurations": [{
    ...,
    "pathMappings": {
        "remote/path/to/webroot/": "${workspaceFolder}",
    }
}]

使用 docker 时的旁注:远程路径是 docker 容器内的路径。