VSCode PHP 调试扩展路径转换,本地到服务器
VSCode PHP Debug extension path translation, local to server
在服务器上使用 Visual Studio 代码和 XDebug 调试 PHP。服务器端配置为:
zend_extension=xdebug.so
xdebug.remote_enable=true
xdebug.remote_host=mybox
xdebug.remote_port=9000
xdebug.remote_log=/tmp/xdebug/xdebug-remote.log
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir=/tmp/xdebug
launch.json 中的配置为:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"localSourceRoot": "Y:\",
"serverSourceRoot": "/home/seva/myproject",
"stopOnEntry":true
}
现在,当配置是这样的,我在浏览器中打开该项目的页面时,调试器在第一行 PHP 停止,从那一点开始,我可以设置断点和继续他们。但是,如果我在同一文件中设置断点,将 stopOnEntry
设置为 false
并在浏览器中加载它,则不会命中断点。我在这里错过了什么?
编辑:非常简单的代码,一行语句,那里没有符号链接,路径映射已提供给 VS Code。
EDIT2:在日志中发现了一个有趣的行:
<- breakpoint_list -i 5
-> <response xmlns="urn:debugger_protocol_v1"
xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list"
transaction_id="5">
<breakpoint type="line"
filename="file:///home/seva/y:/admin_main.php"
lineno="5" state="enabled" hit_count="0" hit_value="0" id="274990011">
</breakpoint>
<breakpoint type="line"
filename="file:///home/seva/y:/db.php"
lineno="770" state="enabled" hit_count="0" hit_value="0" id="274990010">
</breakpoint>
</response>
注意断点对象上的文件名:file:///home/seva/y:/admin_main.php
。这是本地路径和服务器路径的奇怪混搭。该文件实际上位于服务器盒上的 /home/seva/myproject
,它通过 SAMBA 共享为 \servername\myproject
,然后映射到我的本地驱动器 Y:.
看起来 localSourceRoot
和 serverSourceRoot
不像我想的那样工作...
EDIT3:当我将 localSourceRoot
更改为 myproject
时,日志中的条目仍然有 file:///home/seva/y:/admin_main.php
。我看不出 Y:\ 从哪里来,除了它是我在 VS Code 中编辑的文件夹。所以这些设置和当前文件夹路径之间发生了一些有趣的相互作用。
EDIT4:我认为罪魁祸首是 convertClientPathToDebugger()
下的函数 https://github.com/felixfbecker/vscode-php-debug/blob/5bfc474d681d5500d7b31d27bccdbfc08b88884e/src/paths.ts 。不过它看起来是正确的 - 采用本地相对路径,应用到服务器根目录,获取服务器路径。
要是我能一步到位就好了...
这是 PHP 调试扩展中的一个错误,它以区分大小写的方式处理 Windows 驱动器号。将 localSourceRoot
的值更改为 y:\
有帮助。
https://github.com/felixfbecker/vscode-php-debug/issues/197
https://github.com/felixfbecker/vscode-php-debug/pull/198
在服务器上使用 Visual Studio 代码和 XDebug 调试 PHP。服务器端配置为:
zend_extension=xdebug.so
xdebug.remote_enable=true
xdebug.remote_host=mybox
xdebug.remote_port=9000
xdebug.remote_log=/tmp/xdebug/xdebug-remote.log
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir=/tmp/xdebug
launch.json 中的配置为:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"localSourceRoot": "Y:\",
"serverSourceRoot": "/home/seva/myproject",
"stopOnEntry":true
}
现在,当配置是这样的,我在浏览器中打开该项目的页面时,调试器在第一行 PHP 停止,从那一点开始,我可以设置断点和继续他们。但是,如果我在同一文件中设置断点,将 stopOnEntry
设置为 false
并在浏览器中加载它,则不会命中断点。我在这里错过了什么?
编辑:非常简单的代码,一行语句,那里没有符号链接,路径映射已提供给 VS Code。
EDIT2:在日志中发现了一个有趣的行:
<- breakpoint_list -i 5
-> <response xmlns="urn:debugger_protocol_v1"
xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list"
transaction_id="5">
<breakpoint type="line"
filename="file:///home/seva/y:/admin_main.php"
lineno="5" state="enabled" hit_count="0" hit_value="0" id="274990011">
</breakpoint>
<breakpoint type="line"
filename="file:///home/seva/y:/db.php"
lineno="770" state="enabled" hit_count="0" hit_value="0" id="274990010">
</breakpoint>
</response>
注意断点对象上的文件名:file:///home/seva/y:/admin_main.php
。这是本地路径和服务器路径的奇怪混搭。该文件实际上位于服务器盒上的 /home/seva/myproject
,它通过 SAMBA 共享为 \servername\myproject
,然后映射到我的本地驱动器 Y:.
看起来 localSourceRoot
和 serverSourceRoot
不像我想的那样工作...
EDIT3:当我将 localSourceRoot
更改为 myproject
时,日志中的条目仍然有 file:///home/seva/y:/admin_main.php
。我看不出 Y:\ 从哪里来,除了它是我在 VS Code 中编辑的文件夹。所以这些设置和当前文件夹路径之间发生了一些有趣的相互作用。
EDIT4:我认为罪魁祸首是 convertClientPathToDebugger()
下的函数 https://github.com/felixfbecker/vscode-php-debug/blob/5bfc474d681d5500d7b31d27bccdbfc08b88884e/src/paths.ts 。不过它看起来是正确的 - 采用本地相对路径,应用到服务器根目录,获取服务器路径。
要是我能一步到位就好了...
这是 PHP 调试扩展中的一个错误,它以区分大小写的方式处理 Windows 驱动器号。将 localSourceRoot
的值更改为 y:\
有帮助。
https://github.com/felixfbecker/vscode-php-debug/issues/197 https://github.com/felixfbecker/vscode-php-debug/pull/198