microsoft / vscode-cpptools

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

How can i see the value of elements in STL containers or arrays in debug #1414

Closed philong6297 closed 6 years ago

philong6297 commented 6 years ago

For example with std::vector<std::vector> v(10,vector<int>(5,-1)). When I run the debug with GDB, i can only see the address of the first and last element. When i expand the _M_start_ or _M_finish_, it still show the address, not the value i need to see. How can i see the value of elements in STL or arrays in debug: capture

Gruntfuggly commented 6 years ago

You need to set up python pretty printers for C++ in the .gdbinit file.

Have a look here: https://sourceware.org/gdb/wiki/STLSupport

pieandcakes commented 6 years ago

@philong6297 Also make sure you have the following block in your launch.json to enable pretty printing:

"setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
andyneff commented 6 years ago

For the record, you need both of those, and they can both be wrapped in the setupCommands

Modern OSes like Fedora and Ubuntu include the svn submodule, and you don't need to download them separately. For example, in Ubuntu 18.04

"setupCommands": [
    {
        "description": "Test",
        "text": "python import sys;sys.path.insert(0, '/usr/share/gcc-8/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
        "ignoreFailures": false
    },
    {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": true
    }
]
nealYangVic commented 4 years ago

not sure why { "version": "0.2.0", "configurations": [ { "name": "(lldb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/helloworld.out", "args": ["-arg1", "-arg2"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "lldb", "customLaunchSetupCommands": [ { "description": "Test", "text": "python import sys;sys.path.insert(0, '/Users/mingyeyang/gcc/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)", "ignoreFailures": false }, { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "logging": { "trace": true, "traceResponse": true, "engineLogging": true } } ] } --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (476) STDERR: error: 'logout' is not a valid command.\n"},"seq":44} 1: (476) STDERR: error: 'logout' is not a valid command. --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (477) STDERR: error: Unrecognized command 'logout'.\n"},"seq":46} 1: (477) STDERR: error: Unrecognized command 'logout'. --> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/Launch","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.61023.1","VS.Diagnostics.Debugger.HostVersion":"14.0.61023.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.ErrorCode":1005,"VS.Diagnostics.Debugger.Launch.IsError":true}},"seq":48} --> R (launch-2): {"type":"response","request_seq":2,"success":false,"command":"launch","message":"Unable to start debugging. Specified argument was out of the range of valid values.\nParameter name: options.TargetArchitecture","body":{"error":{"id":1005,"format":"Unable to start debugging. Specified argument was out of the range of valid values.\nParameter name: options.TargetArchitecture"}},"seq":50}

AniruddhaHumane commented 4 years ago

How do I do the same for Windows?

harrism commented 4 years ago

For the record, you need both of those, and they can both be wrapped in the setupCommands

Modern OSes like Fedora and Ubuntu include the svn submodule, and you don't need to download them separately. For example, in Ubuntu 18.04

"setupCommands": [
    {
        "description": "Test",
        "text": "python import sys;sys.path.insert(0, '/usr/share/gcc-8/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
        "ignoreFailures": false
    },
    {
        "description": "Enable pretty-printing for gdb",
        "text": "-enable-pretty-printing",
        "ignoreFailures": true
    }
]

Any idea why @andyneff 's suggestion can't be rolled into vscode-cpptools so that it works out of the box? I've been struggling with debugging STL in vscode for a while now, and this suggestion is going to make it a lot easier.

pieandcakes commented 4 years ago

@WardenGnaw can we see if we can get a test matrix with @andyneff's suggestion above and wee where it works and where it doesn't? we would need to at the bare minimum set up Arch, Ubuntu, Centos and WSL1/2

bcaddy commented 2 years ago

I'm on Ubuntu 20.04 and none of the suggestions here are having any effect at all, though they do work on a RHEL system I have access to. Any suggestions?

Edit: It appears to be due to the fact that I'm using CUDA-gdb not GDB. If anyone has any suggestions I'd love them otherwise I'll go ask the NVIDIA people

hansfbaier commented 1 year ago

On Ubuntu 22.04, this seemed to work:

            "setupCommands": [
                {
                    "description": "Test",
                    "text": "python import sys;sys.path.insert(0, '/usr/share/gcc/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
                    "ignoreFailures": false
                },
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
sajedehkebriti commented 1 year ago

hansfbaier

I'm using this set up in launch.json file. Before copying this command, I was seeing only implementation details of std::set but now it shows me {...} basically no information. I'm attaching the photo of what I'm seeing in debugger. I'm using Ubuntu 22.04.

Screenshot from 2023-05-20 16-13-04

hansfbaier commented 1 year ago

@sajedehkebriti You need the libstdc++6 package to be installed

sajedehkebriti commented 1 year ago

@sajedehkebriti You need the libstdc++6 package to be installed I have already installed this package.

FDCNBY commented 1 year ago

hansfbaier

I'm using this set up in launch.json file. Before copying this command, I was seeing only implementation details of std::set but now it shows me {...} basically no information. I'm attaching the photo of what I'm seeing in debugger. I'm using Ubuntu 22.04.

Screenshot from 2023-05-20 16-13-04

the same question in gdb 13.2 use gdb init from [https://github.com/cyrus-and/gdb-dashboard]. did u solve this problem?

saifeiLee commented 10 months ago

hansfbaier

I'm using this set up in launch.json file. Before copying this command, I was seeing only implementation details of std::set but now it shows me {...} basically no information. I'm attaching the photo of what I'm seeing in debugger. I'm using Ubuntu 22.04. Screenshot from 2023-05-20 16-13-04

the same question in gdb 13.2 use gdb init from [https://github.com/cyrus-and/gdb-dashboard]. did u solve this problem?

You can change your compiler from clang++ to g++. Work for me.

dvirtz commented 8 months ago

@WardenGnaw can we see if we can get a test matrix with @andyneff's suggestion above and wee where it works and where it doesn't? we would need to at the bare minimum set up Arch, Ubuntu, Centos and WSL1/2

@pieandcakes any progress on that front?

joyWang-77 commented 3 months ago

How do I do the same for Windows?

do you find how to do it for windows