0

I am having trouble inspecting std::set and std::map using the debugger in VS Code. I can see the content of a std::vector of my classes, but for std::set and std::map, I only see the attached photo

enter image description here

I have followed this thread but the solution provided is for Windows users. I have also followed this GitHub thread and modified my launch.json, but adding this only solved the problem for std::vector, not for std::set or std::map. Here is my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(gdb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "preLaunchTask": "Build",
      "program": "pathToExecutable",
      "args": [],
      "stopAtEntry": false,
      "cwd": "/PathToProject/",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "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
        }
      ]
    }
  ]
}

Please note that I have installed libstdc++6:

libstdc++6 is already the newest version (12.1.0-2ubuntu1~22.04).

Also, this path /usr/share/gcc/python/libstdcxx exists and contains: __init__.py __pycache__ v6

MA19
  • 510
  • 3
  • 15
  • 1
    1) Can you please read about [the problems with images of text](//meta.stackoverflow.com/a/285557/11107541) and then [edit] to **convert** your images of text into actual text? Likely useful: [/help/formatting](/help/formatting) 2) What do you see when you run `info pretty-printer` in your GDB? 2) what version of GDB do you have installed? – starball Jun 18 '23 at 23:01
  • @starball sorry about photo. I edited, but the first image is necessary to explain the problem. As I run `info pretty-printer` in debug console, it returns `-var-create: unable to create variable object`. The version of GDB is `GNU gdb (GDB) 12.1` – MA19 Jun 18 '23 at 23:17
  • When I run `info pretty-printer` through terminal not GDB console in VS Code environment, I get this: `global pretty-printers: builtin mpx_bound128` – MA19 Jun 18 '23 at 23:24
  • what if you run it after loading a program that links with libstdc++? – starball Jun 18 '23 at 23:32
  • @starball Okay, It seems I had not added `libstdc++-v6` to `./gdbinit` I corrected that and now `info pretty-printer` returns me `libstdc++-v6` as well. But, I'm not able to start debugging. When hitting F5, it says `Unable to start debugging. Unexpected GDB output from command "- interpreter-exec console "python import sys;sys.path.insert(0, ‘/usr/ share/gcc/python’);From libstdcxx.v6. printers import register_libstdcxx_printers;register_libstdcxx_printers(None)™. Error while executing Python code.` – MA19 Jun 18 '23 at 23:46
  • @starball sorry about that. It won't be new information, since adding that line to ./gdbinit or putting that in setupCommnads is the same thing. – MA19 Jun 18 '23 at 23:55
  • ah apologies. I hadn't noticed it in your launch config. – starball Jun 18 '23 at 23:56

0 Answers0