【问题标题】:VSCode PHP Debug extension path translation, local to serverVSCode PHP Debug 扩展路径翻译,本地到服务器
【发布时间】:2017-10-18 02:08:49
【问题描述】:

在服务器上使用 Visual Studio Code 和 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:。

看起来 localSourceRootserverSourceRoot 不像我想象的那样工作......

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 。不过看起来不错 - 采用本地相对路径,应用到服务器根目录,获取服务器路径。

如果我能跨过那个...

【问题讨论】:

  • 这些是什么线?对于多行语句.. 实际行在中间的某个地方.. 所以最好只在简单/单行语句上设置断点。不知道 VSC 究竟是如何工作的(这里是 PhpStorm 用户),但也许它与路径映射有关?只是提醒一下——xdebug(或者可能是 PHP 本身)将使用最终/解析的路径,而 IDE/编辑器应该按原样使用路径。因此,如果您在远程端有符号链接或类似的东西.. 最好考虑一下。将xdebug_break(); 放置在实际代码中断中需要该选项=false
  • 如果在两种情况下都会遇到断点的“真”和“假”会话的 xdebug 日志,那就太好了。现在我建议创建一个新的简单脚本,其中包含几行简单的行,每条指令都在新行上,看看它在那里的行为。类似&lt;?php $a = 5; $b = 3; $c = $a + $b; echo $c;

标签: php visual-studio-code xdebug


【解决方案1】:

这是 PHP Debug 扩展中的一个错误,它以区分大小写的方式处理 Windows 驱动器号。将 localSourceRoot 的值更改为 y:\ 有帮助。

https://github.com/felixfbecker/vscode-php-debug/issues/197 https://github.com/felixfbecker/vscode-php-debug/pull/198

【讨论】:

    猜你喜欢
    • 2020-02-10
    • 2020-11-22
    • 2013-09-20
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    相关资源
    最近更新 更多