You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 10:25:31