如何在 vscode 中调试已编译的可执行文件?

mil*_*bos 5 c json visual-studio-code vscode-debugger

当尝试在 vscode 中调试时,vscode 会生成launch.json配置文件。当我尝试调试时,它首先尝试编译源代码,然后调试 exe。我只想调试已编译的可执行文件(使用gcc -g选项编译)。

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": "gcc-10 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [
                "-pthread",
                "common.c"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc-10 build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我可以以某种方式使 vsode编译,而只是使用已编译的源进行调试"program":"${fileDirname}/${fileBasenameNoExtension}"吗?我已编译为完全相同的名称 - 当前目录中没有扩展名,如属性所示。那么如何让 vscode 将这个可执行文件作为它的调试文件呢?

小智 0

我正在使用谷歌测试来测试我的应用程序层。但当测试失败时,我还需要逐步调试它们。

这是我的由 vscode 生成的 launch.json,并进行了一些细微的调整

 {
        "name": "Debug debug_test",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/test/build/app/debug/logging_test.exe",
        "args": [
            "${cmake.testArgs}"
        ],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            },
            {
                "description": "Set Disassembly Flavor to Intel",
                "text": "-gdb-set disassembly-flavor intel",
                "ignoreFailures": true
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)

这是通过 vscode 上的运行和调试工具栏执行的。我使用 ninja 构建脚本和 cmake。cmake 使用 ninja-multicondig 生成器。编译器来自msys2网站。该文件夹中还有一个 .exe 和 .pdb。我认为两者都需要。