Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

php - VSCode + Lando: Xdebug doesn't stop

I'm trying to setup Xdebug with Lando (v. 3.0.24) with VSCode without success. I've already read official guide plus other on internet, and different topics with problem similar to mine but alas I couldn't get it working.

My lando file, which is inside the docroot folder, is:

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

The php.ini file is:

[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

And finally the launch.json file is:

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

BTW, I am not sure how set the pathMappings, so I've tried different combination such as

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

Anyway, the problem is that Xdebug doesn't stop at the breakpoint.

If I tail the xdebug.log I see:

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', poll success, 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

So maybe Xdebug can't still connect to the correct IP? Anyway any idea how solvecould get this working? Thank you

EDIT: If I move the lando.yml file from the doocroot folder to the folder above I can get a somewhat working situation, with Xdebug actually stopping in VSCode. However there are two other problems:

  1. Cannot use lando drush anymore. A workaround for this is lando composer require drush/drush but no idea why the "global" drush of lando doesn't work.
  2. terminal commands - e.g. drush - doesn't seems to work with xdebug (a very minor problem at least for me), as they returns

Xdebug: [Step Debug] Could not connect to debugging client. Tried: 172.31.206.147:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(

Below the updated php.ini and lando.yml files, launch.json is the same of above.

[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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...