Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
philong6297 opened this issue Jan 6, 2018 · 15 comments
Closed

Comments

@philong6297
Copy link

philong6297 commented Jan 6, 2018

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
Copy link

Gruntfuggly commented Jan 9, 2018

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
Copy link
Contributor

@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
Copy link
Contributor

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
Copy link

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
Copy link

How do I do the same for Windows?

@harrism
Copy link

harrism commented Jun 30, 2020

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
Copy link
Contributor

@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
Copy link

bcaddy commented Jan 17, 2022

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
Copy link

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
Copy link

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
Copy link

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

@sajedehkebriti
Copy link

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

@FDCNBY
Copy link

FDCNBY commented Sep 11, 2023

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
Copy link

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
Copy link

dvirtz commented Jan 30, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests