我使用的 VScode 具有以下版本详细信息:
版本:1.73.0(用户设置) 提交:8fa188b2b301d36553cbc9ce1b0a146ccb93351f 日期:2022-11-01T15:34:06.111Z 电子:19.0.17 Chrome :102.0.5005.167 Node.js:16.14.2 V8:10.2.154.15-电子.0 操作系统:Windows_NT x64 10.0.22000 沙盒:否
使用 fork() 时无法调试子进程。
我尝试寻找一种方法来做到这一点,并听说了 Visual Studio 的这个扩展:https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool2022&ssr=false#overview
我尝试检查 VSCode 的扩展部分,但没有找到。因此,我决定通过下载 vsix 文件手动安装。当我尝试使用扩展管理器中的“从 VSIX 安装”选项安装它时,出现以下错误:
在 zip 中找不到扩展名/package.json。
我又进行了一些谷歌搜索,发现 Visual Studio 与 Visual Studio Code 有所不同,这可能是安装错误的原因。
那么,有什么办法/替代方案吗?如何在 Visual Studio Code 中调试子进程?
最佳答案
这是 VS Code 主要指南之外的内容,尽管他们含糊地提到了支持 this .
可以引用GDB的fork调试页面以获取更多信息,以下是您可以添加到 .vscode/launch.json 中的内容:
{
"configurations": [
{
// ...
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
// https://sourceware.org/gdb/onlinedocs/gdb/Forks.html
"description": "Fork follows Child process",
"text": "set follow-fork-mode child",
"ignoreFailures": true
},
{
// https://sourceware.org/gdb/onlinedocs/gdb/Forks.html
"description": "Fork will keep the other process attached to debugger",
"text": "set detach-on-fork off",
"ignoreFailures": true
}
]
}
]
}
如果您使用 LLDB 或 codeLLDB ,这是LLDB command除了分离功能之外,它反射(reflect)了上面的内容:
{
"configurations": [
{
// ...
"initCommands": [
"settings set target.process.follow-fork-mode child"
]
}
]
}
编辑
我个人没有使用过MSVC,但是如果你使用MSVC调试器,你可以尝试使用.childdbg 1
作为启动命令,这里是reference page来自微软。
关于c - 使用 VS Code 调试 C 子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74366554/