VSCode 命中断点然后停止

VSCode hits breakpoints then stops

所以首先,自 10 月以来,出于某种原因,我之前用于 VSCode + Docker 的 Xdebug 配置停止工作。

我切换到 Xdebug 3 配置进行试用,因为 2.9 似乎已停止为我工作。可能是因为 VSCode 或 PHP 调试插件更新?

但是到目前为止我一直无法让它工作或者只让它工作一半?

VSCode launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "externalConsole": false,
            "pathMappings": {
                "/var/www/html/backend": "${workspaceRoot}",
            },
            "xdebugSettings": {
                "resolved_breakpoints": "0",
                "max_data": -1,
                "max_children": -1,
                "max_depth": -1
            },
            "ignore": [
                "**/vendor/**/*.php"
            ]
        }
    ]
}

xdebug.ini 在 Docker (LAMP):

zend_extension=xdebug.so
xdebug.idekey = VSCODE
xdebug.mode = debug,profile,trace
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.client_host=host.docker.internal

xdebug.profiler_enable_trigger = 1
xdebug.profiler_enable = 0
xdebug.remote_enable = 1
xdebug.profiler_output_dir = "/tmp"

xdebug.log:

我的断点在module.class.php:209

[17] Log opened at 2021-12-16 15:36:39.557066
[17] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[17] [Step Debug] INFO: Connected to debugging client: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port). :-)
[17] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/company_v2_backend/index.php" language="PHP" xdebug:language_version="7.2.34" protocol_version="1.0" appid="17" idekey="VSCODE"><engine version="3.1.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>

[17] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

[17] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>

[17] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>

[17] [Step Debug] <- feature_set -i 4 -n resolved_breakpoints -v 0
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="resolved_breakpoints" success="1"></response>

[17] [Step Debug] <- feature_set -i 5 -n max_data -v -1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="max_data" success="1"></response>

[17] [Step Debug] <- feature_set -i 6 -n max_children -v -1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" feature="max_children" success="1"></response>

[17] [Step Debug] <- feature_set -i 7 -n max_depth -v -1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="7" feature="max_depth" success="1"></response>

[17] [Step Debug] <- breakpoint_set -i 8 -t line -f file:///var/www/html/backend/classes/data/module.class.php -n 209
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="170001"></response>

[17] [Step Debug] <- run -i 9
[17] [Step Debug] DEBUG: Checking whether to break on /var/www/html/backend/classes/data/module.class.php:209.
[17] [Step Debug] DEBUG: I: Current location: /var/www/html/company_v2_backend/index.php:10.
[17] [Step Debug] DEBUG: I: Matching breakpoint '/var/www/html/backend/classes/data/module.class.php:209' against location '/var/www/html/company_v2_backend/index.php:10'.
[17] [Step Debug] DEBUG: R: File name length (41) doesn't match with breakpoint (51).
[17] [Step Debug] DEBUG: Checking whether to break on /var/www/html/backend/classes/data/module.class.php:209.
[17] [Step Debug] DEBUG: I: Current location: /var/www/html/company_v2_backend/index.php:11.
[17] [Step Debug] DEBUG: I: Matching breakpoint '/var/www/html/backend/classes/data/module.class.php:209' against location '/var/www/html/company_v2_backend/index.php:11'.
[17] [Step Debug] DEBUG: R: File name length (41) doesn't match with breakpoint (51).
[17] [Step Debug] DEBUG: Checking whether to break on /var/www/html/backend/classes/data/module.class.php:209.
[17] [Step Debug] DEBUG: I: Current location: /var/www/html/company_v2_backend/index.php:12.
[17] [Step Debug] DEBUG: I: Matching breakpoint '/var/www/html/backend/classes/data/module.class.php:209' against location '/var/www/html/company_v2_backend/index.php:12'.
[17] [Step Debug] DEBUG: R: File name length (41) doesn't match with breakpoint (51).
[17] [Step Debug] DEBUG: Checking whether to break on /var/www/html/backend/classes/data/module.class.php:209.
[17] [Step Debug] DEBUG: I: Current location: /var/www/html/company_v2_backend/index.php:15.
[17] [Step Debug] DEBUG: I: Matching breakpoint '/var/www/html/backend/classes/data/module.class.php:209' against location '/var/www/html/company_v2_backend/index.php:15'.
[17] [Step Debug] DEBUG: R: File name length (41) doesn't match with breakpoint (51).
[17] [Step Debug] DEBUG: Checking whether to break on /var/www/html/backend/classes/data/module.class.php:209.
[17] [Step Debug] DEBUG: I: Current location: /var/www/html/company_v2_backend/index.php:16.
[17] [Step Debug] DEBUG: I: Matching breakpoint '/var/www/html/backend/classes/data/module.class.php:209' against location '/var/www/html/company_v2_backend/index.php:16'.
[17] [Step Debug] DEBUG: R: File name length (41) doesn't match with breakpoint (51).
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="9" status="stopping" reason="ok"></response>

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

[17] Log closed at 2021-12-16 15:36:39.656857

[17] Log opened at 2021-12-16 15:36:39.676911
[17] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[17] [Step Debug] INFO: Connected to debugging client: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port). :-)
[17] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/company_v2_backend/index.php" language="PHP" xdebug:language_version="7.2.34" protocol_version="1.0" appid="17" idekey="VSCODE"><engine version="3.1.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>

[17] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

[17] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>

[17] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>

[17] [Step Debug] <- feature_set -i 4 -n resolved_breakpoints -v 0
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="resolved_breakpoints" success="1"></response>

[17] [Step Debug] <- feature_set -i 5 -n max_data -v -1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="max_data" success="1"></response>

[17] [Step Debug] <- feature_set -i 6 -n max_children -v -1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" feature="max_children" success="1"></response>

[17] [Step Debug] <- feature_set -i 7 -n max_depth -v -1
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="7" feature="max_depth" success="1"></response>

[17] [Step Debug] <- breakpoint_set -i 8 -t line -f file:///var/www/html/backend/classes/data/module.class.php -n 209
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="170002"></response>

[17] [Step Debug] <- run -i 9
[17] [Step Debug] DEBUG: Checking whether to break on /var/www/html/backend/classes/data/module.class.php:209.
[17] [Step Debug] DEBUG: I: Current location: /var/www/html/company_v2_backend/index.php:10.
[17] [Step Debug] DEBUG: I: Matching breakpoint '/var/www/html/backend/classes/data/module.class.php:209' against location '/var/www/html/company_v2_backend/index.php:10'.
[17] [Step Debug] DEBUG: R: File name length (41) doesn't match with breakpoint (51).

...从现在开始都是一样的

编辑: phpinfo xdebug 向导说明是:

Download xdebug-3.1.2.tgz
Install the pre-requisites for compiling PHP extensions. These packages are often called 'php-dev', or 'php-devel', 'automake' and 'autoconf'.
Unpack the downloaded file with tar -xvzf xdebug-3.1.2.tgz
Run: cd xdebug-3.1.2
Run: phpize (See the FAQ if you don't have phpize).

As part of its output it should show:

Configuring for:
...
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.

Run: ./configure
Run: make
Run: cp modules/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718
Update /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini to have the line:
zend_extension = xdebug
Restart the Apache Webserver

按照这些说明进行操作,但似乎没有帮助。

如果您使用的是 vscode IDE,请检查 launch.json 文件中的端口。保持 9000 并重新启动你的 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": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9000,
            "serverReadyAction": {
                "pattern": "Development Server \(http://localhost:([0-9]+)\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}

我怀疑这是因为您 xdebug.ini 中的 zend.extension 行不是完整路径。

尝试重新下载 xdebug。 然后像这样设置你的xdebug.ini:

[xdebug]
zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000

如您所见,您可能需要在 zend_extension 中设置完整路径。 (为 docker 输入任何其他需要的配置,也使用端口 9000)

然后像这样设置你的launch.json:

{
  "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}",
          "port": 9000
      }
  ]
}

重要 尝试 sudo apt-get install php7.2-xdebug 而不是向导建议的 tar,然后按照向导的后续步骤进行操作。

可能是内存问题。你能尝试减少 max_... 参数吗,像这样:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "externalConsole": false,
            "pathMappings": {
                "/var/www/html/backend": "${workspaceRoot}",
            },
            "xdebugSettings": {
                "resolved_breakpoints": "0",
                "max_data": 65536,
                "max_children": 100,
                "max_depth": 5
            },
            "ignore": [
                "**/vendor/**/*.php"
            ]
        }
    ]
}

在此 post 中存在相同的错误:Getting Xdebug to work properly with Docker and PhpStorm (it connects) 行不匹配,这似乎是内存问题。

更新 2022/03/01:1300 - 成功了!

我们通过 WSL 从 Docker for Windows 切换到 运行(请参阅下面的旧评论),看来我已经在 VSCode 中安装了远程 wsl 扩展我认为这是必需的。

结论是,要么 Docker 得到了更新,它停止在我们的特定环境中工作,要么环境一开始就没有正确设置(即,可能有一些错误 'fixed'它以前对我们有用)。

我现在使用的配置非常相似:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": true,
            "pathMappings": {
                "/var/www/php": "\\wsl$\Ubuntu\code\company\myapp-backend"
            }
        },
    ]
}

docker撰写

version: "3.8"

# Services
services:
  # Redis service
  myapp-backend-redis:
    build: ./.docker/redis
    networks:
      - myapp-backend_network
    ports:
      - "6379:6379"
    expose:
      - 6379
    restart: always
    container_name: myapp-backend-redis

  # Nginx Service
  myapp-backend-nginx:
    image: nginx:1.19
    ports:
      - 8181:80
    volumes:
      - ./:/var/www/php
      - ./.docker/nginx/conf.d:/etc/nginx/conf.d
    depends_on:
      - myapp-backend-php
    networks:
      - myapp-backend_network
    restart: always
    container_name: myapp-backend-nginx

  # PHP Service
  myapp-backend-php:
    build: ./.docker/php
    working_dir: /var/www/php
    #environment:
    #    DEBUG: 1
    volumes:
      - ./:/var/www/php
    depends_on:
      - myapp-backend-mysql
    networks:
      - myapp-backend_network
    restart: always
    container_name: myapp-backend-php

  # Mysql service
  myapp-backend-mysql:
    build: ./.docker/mysql
    ports:
      - "3306:3306"
    volumes:
      - ./.docker/mysql/my.cnf:/etc/my.cnf
      - /storage/docker/myapp-backend-mysql-datadir:/var/lib/mysql

    environment:
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
      MYSQL_DATABASE: "${DB_NAME}"
      MYSQL_USER: "${DB_USERNAME}"
      MYSQL_PASSWORD: "${DB_PASSWORD}"
      MYSQL_ROOT_HOST: "%"
    networks:
      - myapp-backend_network
    restart: always
    container_name: myapp-backend-mysql

networks:
  myapp-backend_network:
    driver: bridge

php docker文件:

FROM php:7.2-fpm

RUN apt-get update && apt-get install -y \
    zip \
    unzip \
    zlib1g-dev \
    libzip-dev \
    libjpeg-dev \
    jpegoptim \
    libicu-dev \ 
    libonig-dev \
    libxml2-dev \
    g++ \
    curl \
    python

RUN docker-php-ext-install mysqli pdo pdo_mysql zip mbstring simplexml dom

COPY config.aws /var/www/.aws/config
COPY credentials.aws /var/www/.aws/credentials

COPY xdebug.ini $PHP_INI_DIR/conf.d/
RUN pecl install xdebug redis
RUN docker-php-ext-enable xdebug redis

# Install AWS-CLI
RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py| python && \
    pip install awscli==1.16.100

#COPY config.aws /.aws/config
#COPY credentials.aws /.aws/credentials

RUN mkdir /var/company
RUN chmod -R 777 /var/company/

xdebug.ini

[XDebug]
xdebug.client_port = 9000
xdebug.mode = debug,profile
xdebug.start_with_request = yes
xdebug.client_host=host.docker.internal
xdebug.remote_log=/var/log/xdebug.log
xdebug.remote_connect_back=0

因此,如果您正在使用 Docker,我建议您检查您的环境是否存在问题或尝试切换到其他环境。 WSL 或者 Xampp 或 Laragon 之类的东西只是为了快速测试目的。所以你可以知道是你的环境出了问题。

更新 2022/03/01:1200 - 我已经迁移到我们的新 WSL 环境并且 xdebug + phpdebug 适用于 vscode 中的其他两个开发人员。但仍然不适合我,我也重新安装了 vscode,删除了所有扩展(完全重置)但仍然没有运气。

一定是我电脑的东西。

旧:

仅供参考 - 问题可能是 Docker / Docker 桌面,我尝试研究降级,但首先你必须回到相当远的版本并且网站上不再列出低于 4 的版本。

我知道这一点,因为我们确认 XDebug 与 vscode 建立了联系,但随后似乎在某个地方中断了。一位同事尝试了没有 docker(desktop) 层的纯 WSL 设置并让它在那里工作。

遗憾的是,我无法找出确切的问题,但会在我迁移到新的 WSL 环境时更新此 post。