我尝试使用GDB在C++项目的VSCode中运行调试器,但在运行调试器时不断收到此错误。我已经设置了证书和所有东西,但它仍然给我这个错误(我运行的是macOS Catalina version10.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在这个问题上的任何帮助都是非常感谢的。
发布于 2020-04-04 15:34:38
launch.json中的"program“参数应该是可调试可执行文件的路径。
我猜您正在使用g++。如果您使用-g开关,您的程序将是可调试的。因此,您的编译将是
g++ -g path/to/prog.cpp -o a.out这将使一个可调试的可执行文件名为"a.out“。
确保你的“程序”参数指向这个文件。考虑到此文件是在工作区的根目录下生成的,您需要将其设置为
"program": "${workspaceFolder}/a.out我希望您遵循所有这些步骤。
发布于 2020-10-10 21:27:09
尝试此文件结构
> SomeFolder
> .vscode
- tasks.json
- launch.json
> MainFolder
- main.cpp
- main.exelaunch.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"}
发布于 2021-03-10 18:58:12
我也有同样的问题。或多或少如下:
错误:无法开始调试。命令"-exec-run“产生意外的GDB输出。创建进程/usr/bin/时出错(错误% 2)。
要修复此问题,请尝试使用较低版本的gcc / g++ (v_9或更低版本)和特别低版本的gdb ( v_10,已安装的实验版本是问题所在,更改为9.3和Ok)。
https://stackoverflow.com/questions/60923232
复制相似问题