【发布时间】:2019-12-10 21:42:10
【问题描述】:
我正在使用带有 PHP 调试扩展的 Visual Studio Code 来调试 Laravel 项目。但是有些断点被忽略了,我不知道为什么。我坚持认为并非所有断点都被忽略的事实。例如,方法声明处的所有断点都会被忽略,但变量声明处的断点会被命中。
我php.ini的Xdebug部分:
xdebug.profiler_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back=1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
这是我的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": 9001,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
我尝试了什么:
- 将默认端口 9000 更改为 9001
- 卸载并重新安装 PHP 调试扩展(你永远不知道)
示例:“•”表示行断点。下面代码示例中的所有断点都将被忽略。
public function testCreateWhenAllParametersAreCorrectlySpecifiedReturnsCompany()
{
• $attributes = [
'business_name' => 'DANONE'
];
$address = factory(Address::class)->create();
$company = Company::create($attributes, $address);
$this->assertInstanceOf(Company::class, $company);
$this->assertDatabaseHas('companies', [
• 'address_id' => $address->id,
'business_name' => 'DANONE'
]);
}
如何让 Xdebug 与 Visual Studio Code 打到所有断点还是这是正常行为?提前感谢您的帮助。
更新 #1 (08/07/2019)
Zend 扩展路径在我的php.ini 中指定,如下所示。
zend_extension = "/usr/local/Cellar/php@7.2/7.2.18/pecl/20170718/xdebug.so"
我尝试在我的settings.json 中添加php.validate.executablePath。
更新 #2 (08/08/2019)
根据本次更新时的 cmets 和答案,Xdebug 忽略某些行是正常行为。那么我的问题是为什么有些行被忽略了?哪些行会被忽略?有官方名单吗?
【问题讨论】:
-
那些不工作的断点在哪里?它们是什么线?欢迎截图。尝试在您的代码中放置
xdebug_break();,看看它是否会触发它。附言我建议在实际的代码行上放置断点,它们最好是单行/简单指令。由于 PHP 生成字节码的方式,一些断点的行与您期望的不同(例如,多行数组声明——它会在中间的某个地方)。附言也许 VSC 不支持“方法断点”(当它放在函数声明行时)。 -
P.S.如果一个断点有效而另一个断点无效,那么更改端口将无济于事。仅当您根本没有收到来自 Xdebug 的任何连接时才需要更改端口(例如,某个其他服务正在该端口上运行,例如 php-fpm 是典型情况)。在任何情况下:启用和收集,然后检查 Xdebug 日志——它会告诉它尝试连接的位置(以及它是否成功)、在哪些行设置了断点等。
-
请添加代码以及断点在哪些特定行上不起作用?
-
PPS Xdebug 2.8 应该有“断点验证”机制:如果该行中设置的断点将被命中或不是。显然,调试客户端(IDE/编辑器)也需要了解/支持这一点。
-
@rkeet 请使用您需要的任何 URL(越多越好):它会提供更好的答案,而无需通过 cmets,例如解释为什么这样的断点没有被点击/链接到存在此类解释的票证等。
标签: php laravel visual-studio-code xdebug