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

Maq*_*sud 8 c++ gdb visual-studio-code vscode-debugger

问题陈述:

调试器无法提供 STL 容器的内容(即向量或字符串)。


概述:

下面是我的launch.json,我已-enable-pretty-printing按照此线程添加,但我无法看到 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"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我什至尝试在手表窗口中添加表情。但这对我来说也不起作用。或者也许我错过了一些东西。这个线程

无法调试stl

Bra*_*ung 6

首先,您可能使用 x64 Windows。

我找到了一个有效的解决方案,在 x64 Windows 中安装 MinGW 时,安装i686 (win32)MinGW 的版本(此评论底部给出了其官方下载链接)而不是x86_64版本,如下所示:

漂亮的打印不能与 MinGW GDB 解决方案一起使用

win32版本的MinGW下载:

i686-win32-矮人

我只是将下载的文件解压到该文件夹​​中D:\MinGW,然后将MinGW的bin路径添加到环境的系统变量D:\MinGW\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\bin中。PATH

将MinGW添加到系统变量中

相关配置文件如下:

.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"
}
Run Code Online (Sandbox Code Playgroud)

.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"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

.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
}
Run Code Online (Sandbox Code Playgroud)

我的电脑环境

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)
Run Code Online (Sandbox Code Playgroud)

最初发布于https://github.com/microsoft/vscode-cpptools/issues/3921#issuecomment-780379258

愿它对您有帮助。