错误:无法启动调试。命令 "-exec-run" 出现意外的 GDB 输出。找不到进程 ID 1401 的 Mach 任务端口



我正试图使用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

如果能在这个问题上提供任何帮助,我们将不胜感激。

我也遇到了同样的问题。或多或少这样:

错误:无法启动调试。来自命令"的意外GDB输出-exec运行";。创建进程/usr/bin/时出错(错误2(。

要解决此问题,请尝试使用较低版本的gcc/g++(v_9左右(和特别低版本的gdb(v_10,安装的实验版本有问题,改为9.3,可以(。

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

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

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

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

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

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

我希望你遵循所有的步骤。

在我的案例中,这个问题似乎与gdb 10.2-1直接相关。将gdb降级到9.2-1立即解决了问题。

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

尝试这种文件结构

> 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"

}

2022年11月更新

我尝试了前面回答中描述的降级选项,但没有成功。事实证明,这个问题是由以下事实引起的:macOS的最新版本中的Darwin内核限制了一个进程控制另一个进程的能力,而这正是gdb调试器必须做的

解决方案是对gdb二进制文件进行代码签名。

请参阅https://sourceware.org/gdb/wiki/PermissionsDarwin有关如何执行此操作的说明。

注意:使用brew安装gdb实际上会警告您现在有此要求。以下摘录嵌入安装后打印的消息中,并引用了相同的URL。

==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:
https://sourceware.org/gdb/wiki/PermissionsDarwin

来源:这里的Visual Code GitHub论坛也讨论了这个问题,我在那里找到了GDB wiki的解决方案链接

我在Ubuntu 22.04上使用GDB 12.1时遇到了类似的问题。听起来WSL不支持/proc/*/mem文件,而GDB坚持这样做,这是一个长期存在的问题

不确定什么时候会有一个长期的解决方案(可能需要来自gdb团队(,但这篇文章描述了给我带来短期缓解的黑客攻击。

echo -en 'x90x90' | sudo dd of=/usr/bin/gdb count=2 bs=1 conv=notrunc seek=$((0x335C7D))

此命令编辑gdb二进制文件以忽略它找不到/proc//mem的事实(,因为ptrace做得足够好(。

请注意;破解";是依赖于二进制的-它在另一个版本的gdb上不起作用。

最新更新