我有一个PHP脚本,在某一点上,我在另一个PHP脚本上调用exec().这非常正常,但在NetBeans中使用XDebug调试器时会挂起.这导致了各种各样的问题,因为我无法调试整个应用程序.
这是一个简单的例子:
test1.php
<?php
$output = array();
$status = 0;
exec('echo "Running inside test 1"', $output, $status);
exec('php ' . __DIR__ . '/test2.php', $output, $status); // Debugger hangs here
var_dump($output);
var_dump($status);
?>
Run Code Online (Sandbox Code Playgroud)
test2.php
<?php
echo "Running inside test 2" . PHP_EOL;
?>
Run Code Online (Sandbox Code Playgroud)
如果我运行 test1.php,它将运行完成并产生预期的输出.
如果我调试 test1.php,它会挂起exec('php ...')行.
我用shell_exec尝试了这个,并得到了同样的问题.我也尝试过对.sh文件或其他可执行文件的执行,没有任何问题.
起初我认为xdebug以某种方式附加到由exec启动的新PHP进程并锁定它,但我检查了我的php.ini并且有xdebug.remote_autostart=off.
我知道通过exec()调用PHP脚本是一种奇怪的处理方式; 它实际上是一个外部提供的PHAR文件,我们在实际的代码库中执行,但上面的小例子有相同的症状,所以我假设它是同样的问题.
如果它是相关的,我使用PHP 5.5.13,Xdebug 2.2.3,Netbeans 7.3.1,Ubuntu 12.0.4.
我刚开始在Visual Studio Code(Ubuntu 14.04)中使用PHP Debug扩展.它对我来说效果很好,但我有一个问题,每次抛出异常时,调试器会自动中断.我们有许多异常,这些异常在我们的代码中被内部捕获和处理,因此我不想逐步完成这些异常.
我一直试图找到类似Visual Studio 2015中的异常设置,但在Visual Studio Code中找不到任何等效选项.
php.ini设置:
[debug]
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
Run Code Online (Sandbox Code Playgroud)
Visual Studio Code launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"args": ["some arguments"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
请注意,当我使用相同的xdebug设置和相同的代码库来使用Netbeans进行调试时,没有违反异常的行为,因此我认为这必须是Visual Studio Code和/或PHP Debug扩展中的内容.
谁能建议如何在不破坏的情况下通过异常?
概括
我正在尝试在 docker 映像 (Ubuntu) 中调试 C++ 程序,同时在我的主机系统 (OS X) 上使用 VSCode 作为 IDE。在对 gdbserver 和 VSCode 任务进行各种修补后,我现在能够成功运行调试器,但是每次启动调试会话时,VSCode 都会挂起 10 秒,然后报告错误消息:
“无法跟踪 preLaunchTask 'docker gdb'。”
如果我点击这个错误,我可以正常地完美调试,但是每次调试时都要等待 10 秒,这让我非常沮丧。
细节
我的 Docker 映像是通过以下方式启动的,因此我的源代码安装在“app”目录中。安全设置是我在 Stack Overflow 上的其他地方找到的,需要允许 gdbserver:
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it -v "$(pwd):/app" -w "/app" -p 9091:9091 {imageName} /bin/bash
Run Code Online (Sandbox Code Playgroud)
当我在主机上启动调试会话时,我使用这个启动命令,将本地 gdb 连接到 docker gdbserver,并运行一个预启动任务:
{
"version": "0.2.0",
"configurations": [
{
"name": "Remote unit test",
"type": "cppdbg",
"request": "launch",
"program": "./tests/ConfigurationTest.cpp_TestRunner",
"miDebuggerServerAddress": "localhost:9091",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": …Run Code Online (Sandbox Code Playgroud)