在 Windows VSCode 中使用 GDB 进行调试
Debugging with GDB in VSCode on Windows
我在这里有点不知所措,我真的没想到这会很困难。我通常在 Linux 上工作,但今天我有一些需要做的工作,只有一台 Windows 机器。我认为这没问题,我可以为 windows 安装 git,克隆我的项目,然后开始工作。真是一团糟。我真的希望有人能帮助我理解我在 Windows 上设置所有这些时哪里出错了。这不是我打算经常做的事情,但绝对是我希望能够在合理的时间内在 Windows 机器上做的事情。
我正在使用 WSL 并将我的默认 VSCode Windows 集成终端设置为 C:\WINDOWS\System32\bash.exe
我安装了 Windows 10 SDK 来修复 crtdbg.h
包含错误作为对 <iostream>
的依赖
我用 MinGW 安装了 gdb -
我设置路径环境变量
我创建了一个 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) CDLL Driver",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/driver",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\MinGW\bin\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
我的 MinGW bin 包含以下内容
我在 VSCode 中启动调试任务,但出现以下错误
cmd /C "c:\Users\shaun\.vscode\extensions\ms-vscode.cpptools-0.28.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-4n4ohh2f.ibt --stdout=Microsoft-MIEngine-Out-1irudlfy.q5x --stderr=Microsoft-MIEngine-Error-fg20cagk.ynl --pid=Microsoft-MIEngine-Pid-kzdzn4p4.lro --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
Command 'cmd' not found, but there are 16 similar ones.
如果需要,我可以提供更多信息。我真的希望我在这里错过了一些简单的东西,这对于从事 Windows 的人来说是显而易见的。提前谢谢你,我真的很感谢你的帮助!
如果您使用 WSL 编译项目,则不应使用 MinGW gdb。
您需要在 Linux 子系统上安装 gdb(如果您使用 Ubuntu WSL,则使用 apt 等原生工具),在 WSL 中重新打开您的项目,并将 WSL 路径配置为 gdb。
我能够在 WSL 上使用此设置成功调试。
用这个文件替换你的launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"args": ["1"],
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\MinGW\bin\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
确保您已经安装了 MinGw 编译器和 gdb 调试器
我在这里有点不知所措,我真的没想到这会很困难。我通常在 Linux 上工作,但今天我有一些需要做的工作,只有一台 Windows 机器。我认为这没问题,我可以为 windows 安装 git,克隆我的项目,然后开始工作。真是一团糟。我真的希望有人能帮助我理解我在 Windows 上设置所有这些时哪里出错了。这不是我打算经常做的事情,但绝对是我希望能够在合理的时间内在 Windows 机器上做的事情。
我正在使用 WSL 并将我的默认 VSCode Windows 集成终端设置为 C:\WINDOWS\System32\bash.exe
我安装了 Windows 10 SDK 来修复 crtdbg.h
包含错误作为对 <iostream>
我用 MinGW 安装了 gdb -
我设置路径环境变量
我创建了一个 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) CDLL Driver",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/driver",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\MinGW\bin\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
我的 MinGW bin 包含以下内容
我在 VSCode 中启动调试任务,但出现以下错误
cmd /C "c:\Users\shaun\.vscode\extensions\ms-vscode.cpptools-0.28.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-4n4ohh2f.ibt --stdout=Microsoft-MIEngine-Out-1irudlfy.q5x --stderr=Microsoft-MIEngine-Error-fg20cagk.ynl --pid=Microsoft-MIEngine-Pid-kzdzn4p4.lro --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
Command 'cmd' not found, but there are 16 similar ones.
如果需要,我可以提供更多信息。我真的希望我在这里错过了一些简单的东西,这对于从事 Windows 的人来说是显而易见的。提前谢谢你,我真的很感谢你的帮助!
如果您使用 WSL 编译项目,则不应使用 MinGW gdb。 您需要在 Linux 子系统上安装 gdb(如果您使用 Ubuntu WSL,则使用 apt 等原生工具),在 WSL 中重新打开您的项目,并将 WSL 路径配置为 gdb。 我能够在 WSL 上使用此设置成功调试。
用这个文件替换你的launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"args": ["1"],
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\MinGW\bin\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
确保您已经安装了 MinGw 编译器和 gdb 调试器