使用无GDB的VS代码进行调试GNU
Debug GNU using VS Code without GDB
在周末,我通过MSYS2 Bash安装了GCC。我将其设置为VS代码,并使其正常工作。我什至让GDB工作(是的,我知道这是一个调试器(。但是,我的主要问题是,是否可以在VS代码中使用调试函数进行调试,而不是GDB。按F5
,它会拔起启动。JSON文件并给我launch: program 'enter program name, for example c:Schoola.exe' does not exist
。在一些研究后,我看到您将其提供给ARGS的文件,以使其在调试器中运行。当我这样做时,尽管我似乎不能给它正确的文件或使其整体工作。我也使用a.exe
而不是a.out
。我不确定这是否有效。
{
// 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": "enter program name, for example ${workspaceFolder}/a.exe",
"args": ["C:\School\CSE340\project2\main.cpp"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
vs代码没有内部调试器(请参阅此处(。您需要使用GDB或Visual Studio调试器(如果您有后者(。
在您的launch.json
中,您需要修改条目:
"program"
:这是要调试程序的途径,即您的编译程序(可以是您项目文件夹的相对路径(
"miDebuggerPath"
:这是通往GDB
"args"
:这些是参数,您想传递给程序员进行调试目的,即您可以离开此空白
因此,您的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}\CSE340\project2\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\MinGW\bin\gdb.exe", // Path where your gdb.exe is located
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
${workspaceFolder}
是工作空间的路径变量,似乎指向C:\School\
,因此也许您需要修改"program"
的值以指向要调试的应用程序。您也可以指定程序的绝对路径。
另外,不要忘记使用调试范围(-g
(编译代码,GDB需要这些代码才能逐步浏览代码。例如: g++ -g main.cpp -o main.exe
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 在linux上调试巨大的C++项目
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 正在VS调试器中监视映射条目
- 使用调试/崩溃报告将应用程序部署到客户端
- VC++本机单元测试,找不到调试符号
- 如何在C++生成器中禁用"使用调试.dcus"
- 使用vscode调试时,GDB意外退出
- 即使使用调试编译标志,表达式也是"optimized out"
- 调试 CUDA MMU 故障
- 小字符串优化(调试与发布模式)
- 调试和自由执行中的信号处理
- 调试编译的服务器在数据库打开时崩溃
- Visual Studio 调试优化如何工作?
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 使用无GDB的VS代码进行调试GNU
- GNU 调试器无法从显示中删除变量?
- 这些 valgrind/GNU 调试器错误消息是什么意思