phpvisual-studio-codexdebug

VSCode hits breakpoints then stops


So first of all since October for some reason my previously working Xdebug config for VSCode + Docker stopped working.

I switched over to an Xdebug 3 config to try it out, since 2.9 appears to have stopped working for me. Maybe because of a VSCode or PHP Debug plugin update?

But so far I have been unable to get it working or get it working only half?

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 in 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:

My breakpoint is on 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).

... and it's kind of the same from here on out

EDIT: phpinfo xdebug wizard instructions are:

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

Follow these instructions but it doesn't appear to help.


Solution

  • UPDATE 2022/03/01:1300 - Got it working!

    We switched from Docker for Windows to running through WSL (See old comments below) and it appeared that I had installed the remote wsl extension in VSCode which I thought was required.

    The conclusion is that either Docker got updated and it stopped working with our specific environment or the environment wasn't set up right to begin with (ie. maybe some bug got 'fixed' that it work for us previously).

    The configuration I we are using now is very similar:

    {
        "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 compose

    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 dockerfile:

    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
    

    So if you are using Docker I would recommend you to check your environment for issues or try switching to something else. Either WSL or maybe something like Xampp or Laragon just for quick testing purposes. So you can know that it is your environment that is the problem.

    UPDATE 2022/03/01:1200 - I have migrated to our new WSL environment and xdebug + phpdebug works for two other dev's in vscode. But still not for me, I have also reinstalled vscode, removed all extensions (total reset) but still no luck.

    Must be something with my PC.

    OLD:

    FYI - The problem is probably Docker / Docker Desktop, I tried looking into downgrading but firstly you would have to go back in version quite far and below 4 is not listed anymore on the website.

    I know this because we confirmed XDebug makes a connection with vscode but then appears to break somewhere along the way. A colleague has tried a pure WSL setup without the docker(desktop) layer and got it working there.

    Sadly I have not been able to figure out the exact issue but will update this post when I migrate over to our new WSL environment.