VSCode + Lando:Xdebug 不会停止

问题描述

我正在尝试使用 VSCode 使用 Lando (v. 3.0.24) 设置 Xdebug,但没有成功。我已经阅读了官方指南和互联网上的其他指南,以及与我的问题类似的不同主题,但可惜我无法使其正常工作。

我在 docroot 文件夹中的lando 文件是:

name: mysite
recipe: drupal9
services:
  appserver:
    webroot: .
    xdebug: debug
    config:
      PHP: ../.vscode/PHP.ini

PHP.ini 文件为:

[PHP]

; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.log = /tmp/xdebug.log

; Remote settings
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = ${LANDO_HOST_IP}
; xdebug.remote_connect_back = 1
xdebug.remote_log = /tmp/xdebug_remote.log

最后的launch.json文件是:

{
  "version": "0.2.0","configurations": [
    {
      "name": "Listen for XDebug (9003)","type": "PHP","request": "launch","port": 9003,"log": true,"pathMappings": {
        "/app/": "${workspaceRoot}/",}
    }
  ]
}

顺便说一句,我不确定如何设置 pathMappings,所以我尝试了不同的组合,例如

  • "/app/": "${workspaceRoot}/",
  • "/app/": "${workspaceRoot}/docroot",
  • "/app/": "${workspaceFolder}/",
  • "/app/": "${workspaceFolder}/docroot",

无论如何,问题是 Xdebug 并没有停在断点处。

如果我跟踪 xdebug.log,我会看到:

www-data@6137da628b8c:/app$ tail -f /tmp/xdebug.log                                         [186] [Step Debug] INFO: Checking remote connect back address.
[186] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[186] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[186] [Step Debug] INFO: Client host discovered through HTTP header,connecting to 172.20.0.1:9003.
[186] [Step Debug] WARN: Creating socket for '172.20.0.1:9003',poll success,but error: Operation Now in progress (29).
[186] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers,connecting to configured address/port: 172.24.0.1:9003. :-|
[186] [Step Debug] WARN: Creating socket for '172.24.0.1:9003',but error: Operation Now in progress (29).
[186] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.20.0.1:9003 (from REMOTE_ADDR HTTP header),172.24.0.1:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
[186] Log closed at 2021-01-05 17:11:27.454926

[192] Log opened at 2021-01-05 17:12:03.777860
[192] [Step Debug] INFO: Checking remote connect back address.
[192] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[192] [Step Debug] INFO: Client host discovered through HTTP header,connecting to 172.20.0.1:9003.
[192] [Step Debug] INFO: Connected to debugging client: 172.20.0.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header). :-)
[192] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///app/index.PHP" language="PHP" xdebug:language_version="7.4.13" protocol_version="1.0" appid="192"><engine version="3.0.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[copyright (c) 2002-2020 by Derick Rethans]]></copyright></init>

[192] [Step Debug] <- breakpoint_list -i 1
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

[192] [Step Debug] <- breakpoint_list -i 2
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="2"></response>

[192] [Step Debug] <- breakpoint_set -i 3 -t line -f file:///app/docroot/sites/default/settings.local.PHP -n 873
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="1920001"></response>

[192] [Step Debug] <- breakpoint_set -i 4 -t line -f file:///app/docroot/test.PHP -n 3
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="1920002"></response>

[192] [Step Debug] <- breakpoint_list -i 5
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="5"><breakpoint type="line" filename="file:///app/docroot/test.PHP" lineno="3" state="enabled" hit_count="0" hit_value="0" id="1920002"></breakpoint><breakpoint type="line" filename="file:///app/docroot/sites/default/settings.local.PHP" lineno="873" state="enabled" hit_count="0" hit_value="0" id="1920001"></breakpoint></response>

[192] [Step Debug] <- breakpoint_list -i 6
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="6"><breakpoint type="line" filename="file:///app/docroot/test.PHP" lineno="3" state="enabled" hit_count="0" hit_value="0" id="1920002"></breakpoint><breakpoint type="line" filename="file:///app/docroot/sites/default/settings.local.PHP" lineno="873" state="enabled" hit_count="0" hit_value="0" id="1920001"></breakpoint></response>

[192] [Step Debug] <- run -i 7
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="7" status="stopping" reason="ok"></response>

[192] [Step Debug] <- stop -i 8
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="8" status="stopped" reason="ok"></response>

[192] Log closed at 2021-01-05 17:12:21.963742

那么也许 Xdebug 仍然无法连接到正确的 IP? 无论如何知道如何解决\可以让这个工作吗?谢谢

编辑: 如果我将 lando.yml 文件从 doocroot 文件夹移动到上面的文件夹,我会遇到一些工作情况,Xdebug 实际上在 VSCode 中停止了。 但是还有另外两个问题:

  1. 不能再使用 lando drush。对此的解决方法lando composer require drush/drush,但不知道为什么lando 的“全球”冲击不起作用。
  2. 终端命令 - 例如drush - 似乎不适用于 xdebug(至少对我来说是一个非常小的问题),因为它们返回

Xdebug: [Step Debug] 无法连接到调试客户端。尝试: 172.31.206.147:9003(通过 xdebug.client_host/xdebug.client_port 回退):-(

在更新后的 PHP.ini 和 lando.yml 文件下面,launch.json 与上面相同。

[PHP]

; Xdebug
xdebug.max_nesting_level = 512
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.log = /tmp/xdebug.log
xdebug.remote_log = /tmp/xdebug_remote.log

name: myproject
recipe: drupal9
services:
  appserver:
    webroot: docroot
    xdebug: debug
    config:
      PHP: .vscode/PHP.ini

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...