c - 使用 VS Code 调试 C 子进程

标签 c visual-studio-code fork parent-child

我使用的 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/

相关文章:

c - 腻子 Shift 箭头

c - qsort 比较 : why const void *?

visual-studio-code - 将图标添加到 TreeView 的正确方法是什么?

visual-studio-code - 在 VS-Code 中查找任何操作(如在 Intellij 中)

c - 如何接受第一次迭代的一个输入?

C语言程序编译 会用到多核cpu吗?

visual-studio-code - VSCode选择边框颜色

使用管道在两个子进程之间进行通信

linux - 修改子进程的输出以添加时间戳

perl fork() & exec()