无法使用 gdb 在 VS 代码中调试 C++
Can't debug C++ in VS code with gdb
我正在尝试在 Visual Studio 代码中调试 C++,但这里有问题。
调试状态不断滚动,但没有控制台显示。如果我停止调试 (shift+ F5),我将无法再次调试。无论是单击绿色三角形还是 F5,都没有任何反应。 Debug screenshot
建筑没问题。这只是调试问题。
MinGW 已添加到 PATH。我可以在 CMD 中使用 g++ 或 gdb。
我的环境:
- OS: Windows10 1803
- Visual Studio代码:1.24.0
- C/C++ 扩展名:0.17.4
- MinGW_w64: x86_64-8.1.0-release-posix-seh-rt_v6-rev0
这是我的配置:
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/MinGW/include",
"C:/MinGW/x86_64-w64-mingw32/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"${workspaceFolder}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"C:/MinGW/include",
"C:/MinGW/x86_64-w64-mingw32/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-g",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\${fileBasenameNoExtension}.exe\""
]
}
}
]
}
settings.json
{
"files.associations": {
"iostream": "cpp",
"ostream": "cpp",
"cmath": "cpp",
"array": "cpp",
"chrono": "cpp",
"functional": "cpp",
"ratio": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"future": "cpp",
"streambuf": "cpp",
"sstream": "cpp",
"initializer_list": "cpp",
"valarray": "cpp"
}
}
我发现这是一个编码问题,我自己解决了。
首先,尝试 gdb logging 以确定您是否遇到同样的问题。
启用 "logging": { "engineLogging": true }
,如果您看到类似
的内容
1: (1992) ->&"7371001-gdb-set target-async on\n"
1: (1993) ->&"Undefined command: "7". Try "help".\n"
1: (1993) ->^error,msg="Undefined command: "7". Try "help"."
那你也有同样的问题
要修复它,您需要禁用 Unicode UTF-8 以获得全球语言支持,这是自 Windows10 1803 以来的测试版功能,默认情况下处于禁用状态。
它位于控制面板 - 时钟和区域 - 区域 - 管理 - 更改系统定位(需要管理员授权) - Beta:使用 Unicode UTF-8 以获得全球语言支持(需要重新启动系统)。
前往 GitHub 的 why vscode just hang in there when start debugging with gdb.exe? 了解更多详情。
我正在尝试在 Visual Studio 代码中调试 C++,但这里有问题。
调试状态不断滚动,但没有控制台显示。如果我停止调试 (shift+ F5),我将无法再次调试。无论是单击绿色三角形还是 F5,都没有任何反应。 Debug screenshot
建筑没问题。这只是调试问题。
MinGW 已添加到 PATH。我可以在 CMD 中使用 g++ 或 gdb。
我的环境:
- OS: Windows10 1803
- Visual Studio代码:1.24.0
- C/C++ 扩展名:0.17.4
- MinGW_w64: x86_64-8.1.0-release-posix-seh-rt_v6-rev0
这是我的配置:
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/MinGW/include",
"C:/MinGW/x86_64-w64-mingw32/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"${workspaceFolder}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"C:/MinGW/include",
"C:/MinGW/x86_64-w64-mingw32/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++",
"args": [
"-g",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\${fileBasenameNoExtension}.exe\""
]
}
}
]
}
settings.json
{
"files.associations": {
"iostream": "cpp",
"ostream": "cpp",
"cmath": "cpp",
"array": "cpp",
"chrono": "cpp",
"functional": "cpp",
"ratio": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"future": "cpp",
"streambuf": "cpp",
"sstream": "cpp",
"initializer_list": "cpp",
"valarray": "cpp"
}
}
我发现这是一个编码问题,我自己解决了。
首先,尝试 gdb logging 以确定您是否遇到同样的问题。
启用 "logging": { "engineLogging": true }
,如果您看到类似
1: (1992) ->&"7371001-gdb-set target-async on\n"
1: (1993) ->&"Undefined command: "7". Try "help".\n"
1: (1993) ->^error,msg="Undefined command: "7". Try "help"."
那你也有同样的问题
要修复它,您需要禁用 Unicode UTF-8 以获得全球语言支持,这是自 Windows10 1803 以来的测试版功能,默认情况下处于禁用状态。
它位于控制面板 - 时钟和区域 - 区域 - 管理 - 更改系统定位(需要管理员授权) - Beta:使用 Unicode UTF-8 以获得全球语言支持(需要重新启动系统)。
前往 GitHub 的 why vscode just hang in there when start debugging with gdb.exe? 了解更多详情。