【发布时间】:2021-12-16 12:06:07
【问题描述】:
我正在尝试使用 gdb 在 VS Code 中调试简单的 C++ 代码,但出现了问题。 Gdb 调试会话是无穷无尽的,没有错误
环境:
- Win10 19043.1288 (21H1),默认俄语
- VS 代码 1.60.1
- C/C++ 扩展 1.7.1
- 从 msys2-x86_64-20210725 安装的 MinGW
- gcc (11.2.0) 和 gdb (11.1) 在路径中
helloworld.cpp:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
tasks.json(注意 "-static-libstdc++" 没有它,生成的 .exe 文件将无法工作)
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe сборка активного файла",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-static-libstdc++"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "компилятор: C:\\msys64\\mingw64\\bin\\g++.exe"
}
]
}
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": "g++.exe - Сборка и отладка активного файла",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"logging": { "engineLogging": true },
"setupCommands": [
{
"description": "Включить автоматическое форматирование для gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe сборка активного файла"
}
]
}
建筑总是正确通过。但是在构建调试器后冻结
终端:
(base) PS C:\Users\NAME\Documents\Ящик\Разработка\CPP_training\helloworld> & 'c:\Users\NAME\.vscode\extensions\ms-vscode.cpptools-1.7.1\debugAdapters\bin\WindowsDebugLauncher.exe'
'--stdin=Microsoft-MIEngine-In-xrq1w4ni.vpd' '--stdout=Microsoft-MIEngine-Out-hz0moxmf.ebp' '--stderr=Microsoft-MIEngine-Error-ow1iwyo5.0ow'
'--pid=Microsoft-MIEngine-Pid-iwvvrfdm.b4e' '--dbgExe=C:\msys64\mingw64\bin\gdb.exe' '--interpreter=mi'
调试器控制台日志:
1: (342) Wait for connection completion.
1: (869) ->=thread-group-added,id="i1"
1: (871) ->~"GNU gdb (GDB) 11.1\n"
1: (872) ->~"Copyright (C) 2021 Free Software Foundation, Inc.\n"
1: (872) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
1: (873) ->~"\nType \"show copying\" and \"show warranty\" for details.\n"
1: (875) ->~"This GDB was configured as \"x86_64-w64-mingw32\".\n"
1: (877) ->~"Type \"show configuration\" for configuration details.\n"
1: (877) ->~"For bug reporting instructions, please see:\n"
1: (878) ->~"<https://www.gnu.org/software/gdb/bugs/>.\n"
1: (878) ->~"Find the GDB manual and other documentation resources online at:\n <http://www.gnu.org/software/gdb/documentation/>."
1: (879) ->~"\n\n"
1: (879) ->~"For help, type \"help\".\n"
1: (879) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (885) ->(gdb)
1: (889) <-1001-gdb-set target-async on
1: (901) ->~"Warning: 'set target-async', an alias for the command 'set mi-async', is deprecated.\n"
1: (901) ->~"Use 'set mi-async'.\n\n"
1: (901) ->1001^done
1: (902) ->(gdb)
1: (902) ->&"\n"
1: (902) ->^done
1: (903) ->(gdb)
1: (906) 1001: elapsed time 18
1: (932) <-1002-enable-pretty-printing
1: (947) ->1002^done
1: (948) 1002: elapsed time 15
1: (948) ->(gdb)
1: (948) <-1003-interpreter-exec console "set pagination off"
1: (948) ->&"\n"
1: (948) ->^done
1: (949) ->(gdb)
1: (962) ->=cmd-param-changed,param="pagination",value="off"
1: (963) ->1003^done
1: (963) 1003: elapsed time 15
1: (963) ->(gdb)
1: (963) <-1004-gdb-set auto-solib-add on
1: (963) ->&"\n"
1: (964) ->^done
1: (964) ->(gdb)
1: (978) ->1004^done
1: (979) 1004: elapsed time 15
1: (979) <-1005-gdb-set solib-search-path c:\\Users\\NAME\\Documents\\Ящик\\Разработка\\CPP_training\\helloworld;
1: (979) ->(gdb)
1: (980) ->&"\n"
1: (980) ->^done
1: (980) ->(gdb)
1: (982) ->1005^done
1: (982) 1005: elapsed time 2
1: (982) ->(gdb)
1: (982) <-1006-environment-cd c:\\Users\\NAME\\Documents\\Ящик\\Разработка\\CPP_training\\helloworld
1: (982) ->&"\n"
1: (982) ->^done
1: (983) ->(gdb)
Everyting 看起来像一些 github 问题和类似的 stackoverflow 问题(例如 https://github.com/microsoft/vscode-cpptools/issues/4523)。但是它们都使用 C/C++ 扩展 0.26.0 和相当旧的 win10 版本,其中包含一些与 unicode 相关的 betha 功能。编码问题在 C/C++ 扩展 0.26.1 版本中得到修复,但我使用 1.7.1 并且有类似的症状。也许我配置不正确。这就是为什么我在这里问而不是在 github 中创建新问题。
【问题讨论】:
-
@AzuxirenLeadGuy 没有任何改变(只是控制台开始是外部的)。添加断点不会改变。调试在开始前冻结 - 只是运行微小的进度条
标签: c++ debugging visual-studio-code gdb