vscode-php-debug icon indicating copy to clipboard operation
vscode-php-debug copied to clipboard

Unexpected behavior when mapping multiple server paths to one local path

Open neillrobson opened this issue 7 years ago • 1 comments

PHP version: 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS ) XDebug version: v2.4.0 Adapter version: 1.12.1

Description: I recently found it necessary to debug both a Web application and command-line script for the same PHP project (Magento 2, in particular). PHP source files are "served" from two different locations for a Web app vs CLI script, and my initial solution was to map both server paths to the same local workspace path. However, this caused breakpoints to become completely non-functional (although exceptions and xdebug_break() were still hit). After sifting through the logs, I found an appropriate solution by adding an additional configuration in my launch.json.

I don't think that this issue is something that needs fixing in your plugin or in Xdebug, but perhaps some documentation somewhere would help out others with similar issues!

Your launch.json:

Broken:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "pathMappings": {
                "/var/www": "v:\\www",
                "/home/username/www": "v:\\www"
            },
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

Fixed:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug - Web",
            "type": "php",
            "request": "launch",
            "pathMappings": {
                "/var/www": "v:\\www"
            },
            "port": 9000
        },
        {
            "name": "Listen for XDebug - CLI",
            "type": "php",
            "request": "launch",
            "pathMappings": {
                "/home/username/www": "v:\\www"
            },
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

XDebug php.ini config:

zend_extension=xdebug.so
xdebug.remote_enable=On
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_port=9000
xdebug.remote_host=10.10.10.251
xdebug.remote_autostart=On
xdebug.remote_log="/tmp/xdebug.log"
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir=/var/www/profile/
xdebug.profiler_output_name=cachegrind.out.%t.%R
xdebug.max_nesting_level=1000
xdebug.var_display_max_depth=10
xdebug.cli_color=1

XDebug logfile (from setting xdebug.remote_log in php.ini):

Log opened at 2018-01-23 19:55:38
I: Connecting to configured address/port: 10.10.10.251:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///home/username/www/dev-client.usernamesolutions.net/bin/magento" language="PHP" xdebug:language_version="7.0.4-5ubuntu1" protocol_version="1.0" appid="16141" idekey="username"><engine version="2.4.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>

<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

<- breakpoint_list -i 2
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="2"></response>

<- breakpoint_set -i 3 -t line -f file:///var/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php -n 71
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="161410001"></response>

<- breakpoint_set -i 4 -t line -f file:///var/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php -n 88
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="161410002"></response>

<- breakpoint_set -i 5 -t line -f file:///var/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php -n 273
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="161410003"></response>

<- breakpoint_list -i 6
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="6"><breakpoint type="line" filename="file:///var/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php" lineno="88" state="enabled" hit_count="0" hit_value="0" id="161410002"></breakpoint><breakpoint type="line" filename="file:///var/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="273" state="enabled" hit_count="0" hit_value="0" id="161410003"></breakpoint><breakpoint type="line" filename="file:///var/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php" lineno="71" state="enabled" hit_count="0" hit_value="0" id="161410001"></breakpoint></response>

<- breakpoint_list -i 7
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="7"><breakpoint type="line" filename="file:///var/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php" lineno="88" state="enabled" hit_count="0" hit_value="0" id="161410002"></breakpoint><breakpoint type="line" filename="file:///var/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="273" state="enabled" hit_count="0" hit_value="0" id="161410003"></breakpoint><breakpoint type="line" filename="file:///var/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php" lineno="71" state="enabled" hit_count="0" hit_value="0" id="161410001"></breakpoint></response>

<- breakpoint_set -i 8 -t exception -x *
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="161410004"></response>

<- run -i 9
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="9" status="break" reason="ok"><xdebug:message filename="file:///home/username/www/dev-client.usernamesolutions.net/bin/magento" lineno="10"></xdebug:message></response>

<- stack_get -i 10
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="10"><stack where="{main}" level="0" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/bin/magento" lineno="10"></stack></response>

<- run -i 11
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="11" status="break" reason="ok"><xdebug:message filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="284" exception="InvalidArgumentException"><![CDATA[Composer could not find the config file: /home/username/www/dev-client.usernamesolutions.net/var/composer_home/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section]]></xdebug:message></response>

<- stack_get -i 12
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="12"><stack where="Composer\Factory-&gt;createComposer" level="0" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="284"></stack><stack where="Composer\Factory-&gt;createGlobalComposer" level="1" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="433"></stack><stack where="Composer\Factory-&gt;createComposer" level="2" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="371"></stack><stack where="Composer\Factory::create" level="3" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/composer/composer/src/Composer/Factory.php" lineno="569"></stack><stack where="Magento\Framework\Composer\ComposerFactory-&gt;create" level="4" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/Composer/ComposerFactory.php" lineno="47"></stack><stack where="Magento\Framework\Composer\ComposerInformation-&gt;getComposer" level="5" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/Composer/ComposerInformation.php" lineno="362"></stack><stack where="Magento\Framework\Composer\ComposerInformation-&gt;getLocker" level="6" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/Composer/ComposerInformation.php" lineno="375"></stack><stack where="Magento\Framework\Composer\ComposerInformation-&gt;getSystemPackages" level="7" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/Composer/ComposerInformation.php" lineno="242"></stack><stack where="Magento\Framework\App\ProductMetadata-&gt;getSystemPackageVersion" level="8" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/App/ProductMetadata.php" lineno="104"></stack><stack where="Magento\Framework\App\ProductMetadata-&gt;getVersion" level="9" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/App/ProductMetadata.php" lineno="65"></stack><stack where="Magento\Framework\Console\Cli-&gt;__construct" level="10" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/vendor/magento/framework/Console/Cli.php" lineno="91"></stack><stack where="{main}" level="11" type="file" filename="file:///home/username/www/dev-client.usernamesolutions.net/bin/magento" lineno="24"></stack></response>

<- run -i 13
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="13" status="stopping" reason="ok"></response>

<- stop -i 14
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="14" status="stopped" reason="ok"></response>

Log closed at 2018-01-23 19:55:49

Adapter logfile (from setting "log": true in launch.json):

Omitting for brevity: can include if necessary

neillrobson avatar Jan 23 '18 20:01 neillrobson

Hi. That makes sense, since the extension does two way mappings (for breakpoints and for opening files) and if the mappings overlap (v:\www) it can choose the wrong one.

I'll mark this task as docs and see if I can do something about better explaining the inner workings of mappings.

zobo avatar May 10 '21 09:05 zobo