microsoft / microsoft/vscode-cpptools

Cannot inspect values of stl containers

Aperta
#6,937 5 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

debugger more info needed
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

Type: Debugger

I installed VSCode with the newest C/C++ extension, downloaded MinGW 17.1 from https://nuwen.net/mingw.html and tried to debug my CPP code, but there is either a bug, a wrong setting, or a missing feature in the debugger.

I also have MSVC but I tried to use g++ and gdb, and without installation, simply by copying them into my home directory, because in a corporate environment, one cannot use an online installer nor can install files into program files, for which one would need admin rights.

What is wrong

I cannot inspect the element of an stl container. In the example, I create a vector<int>, put a breakpoint into the code, and try to see its element. The debugger does not show it.

Versions

  • OS and Version: Windows 10 pro x64
  • VS Code Version: 1.53.0
  • C/C++ Extension Version: 1.2.0
  • Other extensions you installed (and if the issue persists after disabling them): g++ 9.2.0, gdb 8.3.1

Code

Use the following code and put a breakpoint within the loop:

#include <vector>
#include <iostream>

int main()
{
    std::vector<int> myints = {1, 2, 3};
    for (auto myint : myints)
        std::cout << myint; // put breakpoint here

    return 0;
}

Actual behavior

The debugger stops at the breakpoint but doesn't show the values of the vector in the VARIABLES (or Watch) tab. It only shows:
vector

json files

lunch.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 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "C:\\Users\\tuzes\\AppData\\Local\\MinGW\\bin",
            "environment": [],
            "console": "externalTerminal",
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Users\\tuzes\\AppData\\Local\\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"
        }
    ]
}
tasks.json:
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Users\\tuzes\\AppData\\Local\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\Users\\tuzes\\AppData\\Local\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
c_cpp_properties.json:
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        },
        {
            "name": "GCC",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Users/tuzes/AppData/Local/MinGW/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il comportamento del debugger con l’esempio di vector in C++, launch.json, tasks.json e i setupCommands di GDB forniti. Esamina la gestione dello STL pretty-printing da parte dell’estensione; il lavoro è completato quando gli elementi del vector compaiono nella vista VARIABLES o Watch durante l’arresto al breakpoint del ciclo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, vscode
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.