0

I'm trying to debug my code in Visual Studio Code, but I run into an issues when trying to inspect an std::variant. The "VARIABLES or WATCH" window just shows me: variable_name: {...}. There is a dropdown arrow, but if I press it nothing shows up.

I have also tried writing std::get<0>(variable_name) in the DEBUG CONSOLE but that gives me No symbol "get<0>" in namespace "std".

What should I do to be able to see some values? Do I need some extension and if so which?

What I have found and tried:

I have found this thread saying it is fixed with new release of Visual Studio, but I think that just applies to VS Community and not VS Code.

I also tried to enable the pretty printing in the launch.json but that doesn't seem to help.

  "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
    ]
JaMiT
  • 14,422
  • 4
  • 15
  • 31
C. Binair
  • 419
  • 4
  • 14
  • Is `std::get<0>(variable_name)` getting inlined everywhere? If so, then you'd need to [explicitly instantiate](https://en.cppreference.com/w/cpp/language/class_template#Explicit_instantiation) it to be able to use it during debugging (I think). Possibly related topic: [writing a pretty printer](https://sourceware.org/gdb/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html) but I vaguely recall reading somewhere the gdb comes with pretty printers for standard classes- I just don't know the coverage. – starball Feb 28 '23 at 07:33
  • Also, yeah. I don't see how a Visual Studio thread would be relevant to your VS Code question where you're debugging with gdb. Visual Studio debugger uses .natvis. – starball Feb 28 '23 at 07:37
  • Which standard library are you using? – Alan Birtles Feb 28 '23 at 07:39
  • @AlanBirtles Sorry I'm a noob I guess. What do you mean? I'm using c++17 – C. Binair Feb 28 '23 at 08:00
  • @user Either I do it wrong or the explicit instantiating doesn't work in the debug console. Then I get `-var-create: unable to create variable object` – C. Binair Feb 28 '23 at 08:04
  • Which compiler are you using? Which operating system? – Alan Birtles Feb 28 '23 at 08:12
  • read the link I sent you. explicit instantiation is something you specify at compile-time. not at run-time. – starball Feb 28 '23 at 08:12
  • @AlanBirtles gcc 10.2.1 and Debian 11 (bullseye) – C. Binair Feb 28 '23 at 08:40
  • @user I read the link but generally I understand very little of how things are written on cppreference. I also tried to add that explicit instantiation in the code but then it doesn't compile. Again probably I'm adding it wrong but I have never used something like that before so I don't know what I'm doing. I require more help than just a link it turns out. I tried `template type1 std::get(std::variant);` but that doesn't compile. I could add the compile error, but in any case I think there should be a solution without needing changes to the actual code. – C. Binair Feb 28 '23 at 08:52
  • 1
    if you have a copy of visual studio you might be able to extract the libstdc++ natvis files from it https://github.com/microsoft/vscode-cpptools/issues/3423 – Alan Birtles Feb 28 '23 at 10:06

0 Answers0