c++ - 无法检查 VS Code 中的 C++ STL 内容

标签 c++ visual-studio-code gdb vscode-debugger

问题陈述:
调试器无法提供 STL 容器的内容(即 vector 或字符串)。

概述:
下面是我的 launch.json ,我添加了 -enable-pretty-printing根据 this thread但我看不到 STL 容器的内容。

{

    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "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,
                    
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}

我什至尝试在观察窗口中添加表情。但这对我也不起作用。或者也许我错过了一些东西。 this thread
cannot debug stl

最佳答案

首先,您可能使用过 x64 Windows。
我找到了一个有效的解决方案,在 x64 Windows 中安装 MinGW 时,安装 i686 (win32) MinGW 的版本(此评论底部给出了其官方下载链接)而不是 x86_64版本,见下图:
pretty-printing-not-work-with-MinGW GDB-solution
win32版MinGW下载:
i686-posix-dwarf
我刚刚将下载的文件解压到文件夹 D:\MinGW ,然后添加MinGW的bin路径D:\MinGW\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\binPATH环境的系统变量。
Add MinGW to system variable
相关配置文件如下:.vscode\tasks.json

{
    "tasks": [
        {
            // "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}
.vscode\launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.    
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb",
            "setupCommands": [
                {   // Display content in STL containers pretty
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}
.vscode\c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "g++", // Or complete absolute path "D:/MinGW/i686-8.1.0-release-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe"
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x86"
        }
    ],
    "version": 4
}
我的电脑环境
VSCode Version: 1.53.2 (system setup)
OS Version: Windows 10 x64 (Windows_NT x64 10.0.19041)
MinGW version: i686-8.1.0-release-posix-dwarf-rt_v6-rev0
GDB version: 8.1.0 (Target: i686-w64-mingw32)
最初发表于 https://github.com/microsoft/vscode-cpptools/issues/3921#issuecomment-780379258 .
愿对你有帮助。

关于c++ - 无法检查 VS Code 中的 C++ STL 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64189683/

相关文章:

c++ - 在 C++ 中选择在运行时调用的函数

visual-studio-code - 如何在 VSCode 上禁用帐户图标上的徽章

visual-studio-code - VSCode - 将所选文本包装在 "<mark></mark>"

linux - gdb 没有给出错误的完整描述

gdb - gdb的list,disas,x在windbg中对应的命令是什么?

c++ - 如何在不重新编码的情况下剪切 MP3?我应该只复制框架吗?

c++ - 如何测试 std::random_device 的随机性?

c - 如何调试使用 gdb 中辅助 txt 文件输入的程序?

c++ - Windows.h 导致 C++ 类出现问题

flutter - 使用 Visual Studio Code 在终端中运行 Dart 控制台应用程序