【问题标题】:ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Unable to find Mach task port for process-id 1401错误:无法开始调试。来自命令“-exec-run”的意外 GDB 输出。找不到进程 ID 1401 的 Mach 任务端口
【发布时间】:2020-07-10 09:21:31
【问题描述】:

我正在尝试使用 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
                }
            ]
        }
    ]
}

这是我的 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"
            },
        }
    ]
}

另外,我看到了一些关于制作 .gdbinit 文件的内容,我在我的根目录中做了这个,我在其中放置了以下命令:

set startup-with-shell off

对于这个问题的任何帮助将不胜感激。

【问题讨论】:

    标签: c++ debugging visual-studio-code cmake gdb


    【解决方案1】:

    我也有同样的问题。或多或少是这样的:

    错误:无法开始调试。来自命令“-exec-run”的意外 GDB 输出。创建进程 /usr/bin/ 时出错,(错误 2)。

    要修复,请尝试使用低版本的 gcc / g++(v_9 左右),特别是低版本的 gdb(v_10,安装的实验版本是问题,改成 9.3 就可以了)。

    【讨论】:

      【解决方案2】:

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

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

      g++ -g path/to/prog.cpp -o a.out
      

      这将使可调试的可执行文件成为“a.out”。

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

      "program": "${workspaceFolder}/a.out
      

      我希望您遵循所有步骤。

      【讨论】:

        【解决方案3】:

        就我而言,这个问题似乎与 gdb 10.2-1 直接相关。将 gdb 降级到 9.2-1 立即解决了问题。

        【讨论】:

          【解决方案4】:

          试试这种文件结构

          > SomeFolder   
            > .vscode    
              - tasks.json    
              - launch.json  
          > MainFolder   
              - main.cpp    
              - main.exe
          

          launch.json

              "version": "0.2.0",
          "configurations": [
              {
                  "name": "DEBUG",
                  "type": "cppdbg",
                  "request": "launch",
                  "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
                  "args": [],
                  "stopAtEntry": false,
                  "cwd": "${workspaceFolder}",
                  "environment": [],
                  "externalConsole": false,
                  "MIMode": "gdb",
                  "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
                  "setupCommands": [
                      {
                          "description": "gdb",
                          "text": "-enable-pretty-printing",
                          "ignoreFailures": true
                      }
                  ],
                  "preLaunchTask": "C/C++: g++.exe build active file"
              }
          ]
          

          }

          tasks.json

          {
          "tasks": [
              {
                  "type": "shell",
                  "label": "C/C++: g++.exe build active file",
                  "command": "C:\\MinGW\\bin\\g++.exe",
                  "args": [
                      "-g",
                      "${file}",
                      "-o",
                      "${fileDirname}\\${fileBasenameNoExtension}.exe"
                  ],
                  "options": {
                      "cwd": "${workspaceFolder}"
                  },
                  "problemMatcher": [
                      "$gcc"
                  ],
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  }
              }
          ],
          "version": "2.0.0"
          

          }

          【讨论】:

            【解决方案5】:

            我遇到了类似的问题。问题是文件夹的名称带有重音符号 (´),例如 path/to/elétron。解决方案是删除口音。致path/to/eletron

            【讨论】:

            • 这并不能真正回答问题。如果您有其他问题,可以点击 提问。要在此问题有新答案时收到通知,您可以follow this question。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
            猜你喜欢
            • 2012-07-15
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多