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

Cannot inspect the content of STL containers in debugger #69

Closed
hungys opened this issue Jun 12, 2016 · 30 comments

Comments

@hungys
Copy link

commented Jun 12, 2016

Currently when I tried to inspect a STL container or a C++ string, the debugger are not able to provide useful information such as the content of a STL vector or string variable. As shown in the screenshot, I have a pretty printer registered to .gdbinit and I'm able to use -exec print v to see the content of a vector (even a string), but it seems the VSCode debugger doesn't know them.

It will be helpful when debugging if the debugger provides such features :)

@delmyers

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2016

@hungys, sorry for the delayed response. Try typing "-exec set print pretty" in the debug console. This will turn on pretty printing for gdb. We turned it off by default because of performance issues.

@dmazuronak

This comment has been minimized.

Copy link

commented Jul 7, 2016

The option pretty print only affect the way how gdb print structures.
The output in Varaiables windows remains unaffected.

@mschuckmann

This comment has been minimized.

Copy link

commented Jul 7, 2016

I'm seeing the same thing, it would be really nice if VSCode could use the pretty printers when show STL variables in mouse hovers and the Watch window.

@paulmaybee

This comment has been minimized.

Copy link
Member

commented Jul 14, 2016

Type "-exec -enable-pretty-printing" in the debug console.

@hungys

This comment has been minimized.

Copy link
Author

commented Jul 15, 2016

@delmyers @paulmaybee Thanks. It works now with -exec -enable-pretty-printing.
Btw, can we set it as the default configurations, or is there any roadmap to add this feature? Seems that we need to type that command in the debug console every time.

STL debugging

@mschuckmann

This comment has been minimized.

Copy link

commented Jul 15, 2016

Yes works for me too and I second the need for some way to set it as the default configuration or event some way to provide a list of command gdb at launch.

I tried adding it my ~/.gdbinit file and it doesn't seem to work.

@filipsky

This comment has been minimized.

Copy link

commented Oct 26, 2016

You can setup initial gdb commands this way in the launch.json

            "linux": {

                "MIMode": "gdb",

                "setupCommands": [

                    { "text": "-enable-pretty-printing", "description": "enable pretty printing", "ignoreFailures": true },

                    { "text": "handle SIGPIPE nostop noprint pass", "description": "ignore SIGPIPE", "ignoreFailures": true }  
                ]
            },
@mschuckmann

This comment has been minimized.

Copy link

commented Oct 26, 2016

@filipsky
That's great, where did you find this documented?
Also where in the launch.json file does this block?

@filipsky

This comment has been minimized.

Copy link

commented Oct 26, 2016

I found it here {just search for setupCommands on the page):
https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md

I have added the setupCommands block in my OS specific ("linux": {} in my case) branch

Best, Honza

@mschuckmann

This comment has been minimized.

Copy link

commented Oct 27, 2016

Thank you, I figured out that it works if the OS specific block is in the
configuration block, which means it has to be repeated for each
configuration, not terrible.
Also thank you for the link.

Matt S.

On Wed, Oct 26, 2016 at 9:27 AM filipsky notifications@github.com wrote:

I found it here {just search for setupCommands on the page):
https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md

I have added the setupCommands block in my OS specific ("linux": {} in my
case) branch

Best, Honza


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#69 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/APF3Sgmi-jnWvDL6nF8T86aiJTPIi8ncks5q33-HgaJpZM4IztDQ
.

Matt S.

@yoyo930021

This comment has been minimized.

Copy link

commented Jan 27, 2017

macOS for lldb
have any function?

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Feb 2, 2017

@yoyo930021 If you download our new version, cpptools 0.10.0 , we have enabled the python pretty printers on macOS. You can also look at natvis and write your own visualizer file which we also support.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Feb 2, 2017

This issue should be resolved as we have added the gdb pretty printer commands by default in the launch.json file. Please comment/reopen if this is still an issue.

@pieandcakes pieandcakes closed this Feb 2, 2017
@jhscsc

This comment has been minimized.

Copy link

commented Feb 1, 2018

Hi, how do I set up pretty printing for VS Code? I'm running GDB on Cygwin (Windows 10) . Specifically, I don't understand what to do with said ".gdbinit" file. Thank you very much!

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Feb 1, 2018

@jhscsc If you are using the default pretty-printers you don't need to do anything with a .gdbinit file. If you want to extend and add your own pretty-printers, you will need to create a .gdbinit file. Since that is a gdb feature and not one provided by the extension, you may need to do some searching online for the file format. On Windows, that should go in the root of your home directory c:\users\<username>.

In your launch.json you should see:

"setupCommands": [

                    { "text": "-enable-pretty-printing", "description": "enable pretty printing", "ignoreFailures": true }
]

If not, then add that and it should tell gdb to enable pretty-printing. This does rely on your version of gdb shipping the Python script files that tell it how to visualize the STL objects.

@jhscsc

This comment has been minimized.

Copy link

commented Feb 1, 2018

Thank you for your quick response. I currently have that snippet in my launch.json; however, when I type -exec print v in the example program shown below, I'm still unable to look into the vector. Do you have any suggestions on how to get it to work?
image

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Feb 1, 2018

If you expand the variable in your locals, does it show a formatted value? -exec print v is telling gdb to print v. It could be you are missing the Python files that do the formatting, and if that is the case you may need to figure out where they come from. My experience with Cygwin gdb is limited. It looks like according to the answer on this link that you need to do additional work to get the files.

@jhscsc

This comment has been minimized.

Copy link

commented Feb 2, 2018

Installing gcc-debuginfo like the link instructed enabled formatting when looking in STL containers in locals - that's what I was going for. Thanks so much @pieandcakes!

@Snape3058

This comment has been minimized.

Copy link

commented Feb 2, 2018

I am using gdb 8.0.1 on my PC, and if I use gdb from command line, it can print the inner content of the STL classes correctly. But when I am using vscode, both -exec print v and the variables window will not show the inner content. What should I do? Thx

OS: Arch Linux
VSCode Version 1.19.3
cpptools Version 0.14.6
No ~/.gdbinit file and /etc/gdb/gdbinit is empty.
"pretty printing" is enable in launch.json just as mentioned above.

@DollarAkshay

This comment has been minimized.

Copy link

commented Feb 3, 2018

I tried all the steps in this github issue. I am using the MinGW compiler and I made sure to install the mingw32-gdb-python package via the MinGW Installation Manager which I assume is required to view the STL container. After all that. All I can see is this

gdb pretty printing

I have Python 3.6. Do I seriously need to install Python 2.7 ? IS there a solution that uses Python 3 ? :/

Update
I have installed Python 2.7 and gdb-python.exe is running fine right now (also followed the additional steps from this stackoverflow question). I still can't look at the STL vector

gdb pythonno errors

Also this is the command I am using to build the C++ executable : g++ '${file}' -g -o out

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Feb 5, 2018

@DollarAkshay That looks correct.

To be clear: Pretty printing is something that gdb provides, although from this thread it looks like it isn't the same across different implementations. Your question about which version of Python should probably be asked to MinGW as that is the tool set that you are using and they control the dependencies for the toolset? From searching online, it looks like the MinGW pretty-printing is a lot harder to setup and you will need to set "miDebuggerPath" to point to the python version of gdb in your launch.json.

The document I found that sort of explains some steps for MinGW is here, scroll to the section labeled "This is for MinGW users...".

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Feb 5, 2018

@Snape3058 The only documentation I found is this. I don't know if that is something you can check/verify/try but that might get you started in the right direction.

@DollarAkshay

This comment has been minimized.

Copy link

commented Mar 5, 2018

@pieandcakes Okay. I finally switched to Cygwin GDB and installed the gcc-debuginfo. It works on windows now 😄 Thank you.

Now it shows only the basic array for a vector. If I want it to show like the capacity, size and other data members, like how VisualStudio does it, I will have to use a custom .gdbinit file ?

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Mar 5, 2018

@DollarAkshay I assume so. We don't do anything special for visualization so it is whatever gdb provides us through pretty printing. There may be some expression shortcuts that you can find online that might give you what you are looking for too that you can add to the watch pane.

@rszibele

This comment has been minimized.

Copy link

commented Nov 15, 2018

I've also encountered this problem on Debian, however, the solution is to install the GDB package which is linked to python2.

When you install the gdb package with apt, you install gdb-minimal which isn't linked against python. You need to install the gdb-python2 package.

On newer GCC/GDB versions (I'm using 8.2.0/8.1) you no longer need a .gdbinit file, unless you need something custom.

@ismailhkose

This comment has been minimized.

Copy link

commented Jan 5, 2019

It doesn't show STL container accurately on the variable window.
For example, I added two strings to vector and it stills show "size: 0" in the variables window as seen in the following screenshot.

image

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented Jan 7, 2019

@ismailhkose Can you include a log? This looks like a pretty printing issue within the debugger you are using but the log would show us what we are getting back from gdb.

@x6herbius

This comment has been minimized.

Copy link

commented Feb 28, 2019

I'm getting this issue on MacOS 10.13.6 with Python 3.6.5, LLDB 1000.11.38.2 and C/C++ extension 0.21.0. When I put -exec -enable-pretty-printing into the debug console, I get the following:

result-class: done
supported: 0

I'm assuming this means my version of LLDB doesn't support pretty printing? Is there anything else I'd need to download?

@Snape3058

This comment has been minimized.

Copy link

commented Mar 11, 2019

@Snape3058 The only documentation I found is this. I don't know if that is something you can check/verify/try but that might get you started in the right direction.

It is the -static compiler parameter that makes gdb not able to recognize the STL objects. Thank you for your reply.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

commented May 2, 2019

@x6herbius the pretty printing command is a feature of gdb and not lldb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.