Xdebug with Visual Studio 代码忽略了一些断点
Xdebug with Visual Studio Code ignores some breakpoints
我正在使用带有 PHP 调试扩展的 Visual Studio 代码来调试 Laravel 项目。但是有些断点被忽略了,我不明白为什么。我坚持认为并不是所有的断点都会被忽略。例如,方法声明处的所有断点都将被忽略,但变量声明处的断点将被命中。
我的 Xdebug 部分 php.ini
:
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 代码命中所有断点或者这是正常行为?预先感谢您的帮助。
更新 #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)
根据本次更新时的评论和回答,Xdebug 忽略某些行是正常行为。那么我的问题是为什么有些行会被忽略?忽略了哪些行?有正式名单吗?
我也遇到了这个问题,laravel
,我发布了我为解决这个问题所做的步骤
我正在为 PHP
使用 laragon
添加了一个新的 php 版本,
还更新了作曲家 PHP 路径(不知道是否需要这一步,但我做到了并指向最新的 PHP 版本)
已下载xdebg.dll并放入文件夹
更新了 php.ini
中的配置
[xdebug]
zend_extension = D:\lrgn\bin\php\php-7.2.7\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_connect_back = 1
;xdebug.remote_log= D:\lrgn\bin\log\xdebug.log
我没有 xdebug.remote_port = 9000
在launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
在 vscode
在首选项 --> 设置中 (ctrl
+,
)
Add/update:
php.validate.executablePath: "D:\lrgn\bin\php\php-7.2.7\php.exe"
(我的在这里)
重新启动服务器(laragon)
停止 laravel
对项目进行了作曲家更新(不确定这个阶段是否需要)
再次开始 laravel 项目
在浏览器上打开 laravel 项目
on vscode 即使在方法中也设置一些刹车点
在调试部分 -> 侦听 XDebug
在浏览器上重新加载页面
是的,直接命中
运行 它在 PhpStorm 中,但作为 Xdebug 运行s on PHP,行为是相同的。
Xdebug 在内容为 "done" 时停止,在内容为 "done" 的行上。这可以是函数调用、变量赋值、数据转换等。所有这些的共同点是它们必须是显式的。隐式赋值被忽略。
Xdebug 不会为放置 "in" 动作的断点暂停执行。这就是为什么代码中的第一个断点 不会 起作用,而第二个断点会起作用。
显式和隐式示例:
$attributes = [ // this is implicitly an array, no pausing execution
'business_name' => 'DANONE' // this is explicitly assigned a string, execution paused
];
一些截图(代码来自 Symfony 4 public/index.php
,有一些明显的添加 - 蓝色背景暂停执行 "current line"):
在 if()
语句中清楚地执行函数 - 它暂停
如我们所见,此数组的所有 3 行上都有断点。但是,它唯一暂停的是 key/value 对的赋值。这是显式完成的,数组本身是隐式声明的。
这里我们明确声明$testArray
是一个数组。所以:它暂停了。
这是完整的,可以在上面添加。类型数组的隐式设置,但 key/value 的显式分配。
所以:是的。
如果您放置的断点略有不同,它们就会暂停执行。不暂停隐含的是正常行为。
待完成:
在本地 Apache 安装上,我有以下配置:
[XDEBUG]
zend_extension = C:\xampp\php\ext\php_xdebug-2.7.1-7.3-vc15-x86_64.dll
xdebug.remote_mode = req
xdebug.remote_connect_back = 1
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.max_nesting_level = 200;
但我通常运行这个在Docker。在 docker-compose
PHP 图片中:
environment:
PHP_XDEBUG_ENABLED: ${XDEBUG_ENABLED:-0}
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG:-serverName=ProjectName}
XDEBUG_CONFIG: >
idekey=PHPSTORM
remote_host=${XDEBUG_REMOTE_HOST_IP:-host.docker.internal}
remote_port=${XDEBUG_REMOTE_PORT:-9000}
remote_enable=1
- (要启用 xdebug,在开始使用
docker-compose up
时在应用程序中将 XDEBUG_ENABLED
环境配置设置为 1
)
- (将 "ProjectName" 替换为项目名称,在 Xdebug 的 PhpStorm 设置中的 "servers" 配置中使用该名称)
并在 Dockerfile
pecl install xdebug-2.7.2 redis && \
docker-php-ext-enable xdebug redis && \
- (确保将
xdebug-2.7.2
替换为您想要的版本/与您的 PHP 版本兼容,check that here)
编辑:根据对 OP 问题的评论进行补充。
有很多错误报告(请参阅这些评论,感谢 LazyOne 找到它们)。
他提供的最后一个 URL 很有趣,因为它是关于即将发布的 V2.8.0(目前是 2.8.0beta1,不是一般版本),他在 this ticket 中评论了关于 Xdebug not pausing执行隐式赋值:
I've just merged this into the master branch, which will become part of 2.8.0. I will release 2.7.2 soon (this week, today?!), and then probably next week a 2.8alpha1 release so that people can try this out.
(引自 2019-05-06 12:49 by Derick,Xdebug 作者)
你可以看看 Xdebug 的 changelog page or the roadmap。
路线图显示了将包含的所有功能/修复。
对于 2.8.0,它表明将为 IDE 添加对 IDE 的支持,以显示是否可以解决断点。它的当前发布日期定为 2019-09-30。
已发布
无法按vscode
中定义的数组打断
我的建议是获取一些 if 或其他代码,如下所示:
public function testCreateWhenAllParametersAreCorrectlySpecifiedReturnsCompany()
{
• $debug = 'true';
$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'
]);
}
并继续按 f10
按钮
我遇到了同样的错误。
我修复了只下载旧版本的 xdebug。
你可以从这里下载link。
我正在使用带有 PHP 调试扩展的 Visual Studio 代码来调试 Laravel 项目。但是有些断点被忽略了,我不明白为什么。我坚持认为并不是所有的断点都会被忽略。例如,方法声明处的所有断点都将被忽略,但变量声明处的断点将被命中。
我的 Xdebug 部分 php.ini
:
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 代码命中所有断点或者这是正常行为?预先感谢您的帮助。
更新 #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)
根据本次更新时的评论和回答,Xdebug 忽略某些行是正常行为。那么我的问题是为什么有些行会被忽略?忽略了哪些行?有正式名单吗?
我也遇到了这个问题,laravel
,我发布了我为解决这个问题所做的步骤
我正在为 PHP
添加了一个新的 php 版本, 还更新了作曲家 PHP 路径(不知道是否需要这一步,但我做到了并指向最新的 PHP 版本)
已下载xdebg.dll并放入文件夹
更新了 php.ini
[xdebug]
zend_extension = D:\lrgn\bin\php\php-7.2.7\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_connect_back = 1
;xdebug.remote_log= D:\lrgn\bin\log\xdebug.log
我没有 xdebug.remote_port = 9000
在launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
在 vscode
在首选项 --> 设置中 (ctrl
+,
)
Add/update:
php.validate.executablePath: "D:\lrgn\bin\php\php-7.2.7\php.exe"
(我的在这里)
重新启动服务器(laragon) 停止 laravel 对项目进行了作曲家更新(不确定这个阶段是否需要) 再次开始 laravel 项目
在浏览器上打开 laravel 项目
on vscode 即使在方法中也设置一些刹车点
在调试部分 -> 侦听 XDebug
在浏览器上重新加载页面
是的,直接命中
运行 它在 PhpStorm 中,但作为 Xdebug 运行s on PHP,行为是相同的。
Xdebug 在内容为 "done" 时停止,在内容为 "done" 的行上。这可以是函数调用、变量赋值、数据转换等。所有这些的共同点是它们必须是显式的。隐式赋值被忽略。
Xdebug 不会为放置 "in" 动作的断点暂停执行。这就是为什么代码中的第一个断点 不会 起作用,而第二个断点会起作用。
显式和隐式示例:
$attributes = [ // this is implicitly an array, no pausing execution
'business_name' => 'DANONE' // this is explicitly assigned a string, execution paused
];
一些截图(代码来自 Symfony 4 public/index.php
,有一些明显的添加 - 蓝色背景暂停执行 "current line"):
在 if()
语句中清楚地执行函数 - 它暂停
如我们所见,此数组的所有 3 行上都有断点。但是,它唯一暂停的是 key/value 对的赋值。这是显式完成的,数组本身是隐式声明的。
这里我们明确声明$testArray
是一个数组。所以:它暂停了。
这是完整的,可以在上面添加。类型数组的隐式设置,但 key/value 的显式分配。
所以:是的。
如果您放置的断点略有不同,它们就会暂停执行。不暂停隐含的是正常行为。
待完成:
在本地 Apache 安装上,我有以下配置:
[XDEBUG]
zend_extension = C:\xampp\php\ext\php_xdebug-2.7.1-7.3-vc15-x86_64.dll
xdebug.remote_mode = req
xdebug.remote_connect_back = 1
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.max_nesting_level = 200;
但我通常运行这个在Docker。在 docker-compose
PHP 图片中:
environment:
PHP_XDEBUG_ENABLED: ${XDEBUG_ENABLED:-0}
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG:-serverName=ProjectName}
XDEBUG_CONFIG: >
idekey=PHPSTORM
remote_host=${XDEBUG_REMOTE_HOST_IP:-host.docker.internal}
remote_port=${XDEBUG_REMOTE_PORT:-9000}
remote_enable=1
- (要启用 xdebug,在开始使用
docker-compose up
时在应用程序中将XDEBUG_ENABLED
环境配置设置为1
) - (将 "ProjectName" 替换为项目名称,在 Xdebug 的 PhpStorm 设置中的 "servers" 配置中使用该名称)
并在 Dockerfile
pecl install xdebug-2.7.2 redis && \
docker-php-ext-enable xdebug redis && \
- (确保将
xdebug-2.7.2
替换为您想要的版本/与您的 PHP 版本兼容,check that here)
编辑:根据对 OP 问题的评论进行补充。
有很多错误报告(请参阅这些评论,感谢 LazyOne 找到它们)。
他提供的最后一个 URL 很有趣,因为它是关于即将发布的 V2.8.0(目前是 2.8.0beta1,不是一般版本),他在 this ticket 中评论了关于 Xdebug not pausing执行隐式赋值:
I've just merged this into the master branch, which will become part of 2.8.0. I will release 2.7.2 soon (this week, today?!), and then probably next week a 2.8alpha1 release so that people can try this out.
(引自 2019-05-06 12:49 by Derick,Xdebug 作者)
你可以看看 Xdebug 的 changelog page or the roadmap。
路线图显示了将包含的所有功能/修复。
对于 2.8.0,它表明将为 IDE 添加对 IDE 的支持,以显示是否可以解决断点。它的当前发布日期定为 2019-09-30。
已发布
无法按vscode
中定义的数组打断
我的建议是获取一些 if 或其他代码,如下所示:
public function testCreateWhenAllParametersAreCorrectlySpecifiedReturnsCompany()
{
• $debug = 'true';
$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'
]);
}
并继续按 f10
按钮
我遇到了同样的错误。
我修复了只下载旧版本的 xdebug。
你可以从这里下载link。