错误:无法开始调试。命令“-exec-run”出现意外的 GDB 输出。无法找到进程 ID 1401 的 Mach 任务端口

Nat*_*son 12 c++ debugging gdb cmake visual-studio-code

我正在尝试使用 GDB 在 C++ 项目中的 VSCode 中运行调试器,但在运行调试器时不断收到此错误。我已经设置了证书和所有内容,但它仍然给我这个错误(我运行的是 macOS Catalina 版本 10.15.4)。

这是我的 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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/Assignment8",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这是我的tasks.json 文件

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "make",
            "options": {
                "cwd": "${workspaceFolder}/build"
            },
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

此外,我看到了一些关于制作 .gdbinit 文件的信息,我在根目录中执行了该文件,并在其中放置了以下命令:

set startup-with-shell off
Run Code Online (Sandbox Code Playgroud)

任何有关此问题的帮助将不胜感激。

Ash*_*cob 3

launch.json 中的“program”参数应该是可调试可执行文件的路径。

我猜你正在使用 g++。如果使用 -g 开关,您的程序将是可调试的。因此你的编译将是

g++ -g path/to/prog.cpp -o a.out
Run Code Online (Sandbox Code Playgroud)

这将生成一个可调试的可执行文件“a.out”。

确保您的“程序”参数指向该文件。考虑到此文件是在工作区的根目录生成的,您需要将其设置为

"program": "${workspaceFolder}/a.out
Run Code Online (Sandbox Code Playgroud)

我希望您遵循所有步骤。