VSCode调试Ubuntu C++项目时含::键的std::map打印缺失问题
问题:VSCode监视窗口无法显示键含"::"的std::map条目
在Ubuntu系统上使用VSCode搭配gdb调试C++项目时,发现当std::map的键为包含::的std::string、值为自定义类时,VSCode的监视窗口会缺失对应条目。
示例代码
#include <map> #include <iostream> #include <string> using namespace std; class notused{ notused* next = nullptr; }; int main() { std::map<std::string, notused> a; a["1"] = notused(); a["1::1"] = notused(); int b = 1; // not really used return 0; }
预期与实际表现
在int b = 1;行设置断点后,监视窗口预期输出:
a: ["1"] next:0x0 ["1::1"] next:0x0
但实际监视窗口中["1::1"]条目缺失。项目中统一使用::作为路径连接符,无法修改该符号。
环境信息
- gdb版本:GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
- g++版本:gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
已验证情况
- 直接在命令行运行gdb,执行
print a显示正常:
(gdb) print a $1 = std::map with 2 elements = { ["1"] = { next = 0x0 }, ["1::1"] = { next = 0x0 } }
- 在VSCode调试控制台执行
-exec print a,输出也正常:
-exec print a $1 = std::map with 2 elements = { ["1"] = { next = 0x0 }, ["1::1"] = { next = 0x0 } }
VSCode调试配置
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/reproduce", "args":[], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": false }, { "description": "将反汇编风格设置为 Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": false } ] } ] }
请问是否有简便方法解决VSCode监视窗口的这个显示问题?
内容的提问来源于stack exchange,提问作者D Asp
相关产品推荐
相关产品推荐

