microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

Debug page: variables cannot be displayed #12541

Closed Willaaaaaaa closed 2 weeks ago

Willaaaaaaa commented 1 month ago

Type: Bug

I am a beginner in programming so this question might be easy. That is I can't see the variables in the debug page. If you need more information, I can provide the picture posted below.

Extension version: 1.21.5 VS Code version: Code 1.92.0 (b1c0a14de1414fcdaa400695b4db1c0799bc3124, 2024-07-31T23:26:45.634Z) OS version: Windows_NT x64 10.0.22631 Modes:

Willaaaaaaa commented 1 month ago

This is a test cpp file.

My expectation is: VARIABLES > Locals > arr = [4] > arr[0] = "I am" arr[1] = "using" ...... But I can't see any data.

debug

sean-mcmanus commented 1 month ago

@Willaaaaaaa I'm not sure why it's not working for you. It's working for me. Does any debugging work? Do you have gdb installed? What version of g++/gdb do you have installed?

image
Willaaaaaaa commented 1 month ago

@sean-mcmanus Thanks for your attention, sir. I have install g++ and the version of g++ is as shown in the photo content. I have no idea about why I can't view variables because I'm a beginner in programming. I would greatly appreciate it if you could provide me with further assistance. debug

Willaaaaaaa commented 3 weeks ago

@sean-mcmanus Sir, it still don't work properly. And this is my launch.json file. Could you please help me and take a look?

{
    "configurations": [
        {
            "name": "C/C++: g++.exe 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\temp_exe_files\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\CS learning\\MinGW64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        },
        {
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\CS learning\\MinGW64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ],
    "version": "2.0.0"
}
Willaaaaaaa commented 2 weeks ago

@sean-mcmanus help me, please!

sean-mcmanus commented 2 weeks ago

@Willaaaaaaa Sorry, I'm not sure how to help you (I don't actually work on the debugger component, only the language service).

sean-mcmanus commented 2 weeks ago

@Willaaaaaaa You could try updating your gcc and gdb versions -- 8.1 is pretty old. You may be hitting a bug that got fixed in a newer version.

sean-mcmanus commented 2 weeks ago

@Willaaaaaaa Also, in your code, you should add #include <string> although I don't think that would cause a debugger issue.

Willaaaaaaa commented 2 weeks ago

@sean-mcmanus Hello sir. You have mentioned upgrading the g++, gdb version, which is really a very constructive and wonderful suggestion! And now I have successfully resolved the issue after the upgrade. Thank you for your continuous replies and patience!