1

This is a VSCode specific question.

Asking here since the VSCode repo points to asking question on SO.

I'm using VSCode on Mac OS, with LLDB.

I'm trying to figure out how to inspect a std::set.

I can't find any doc on this; I found some ways to do it with GDB using macros (https://sourceware.org/ml/gdb/2008-02/msg00064/stl-views.gdb)

but I can't get GDB to work with VS Code (used the WebFreak Native Debug extension but on run I just get "running executable" and nothing happening, no error, no log, so I gave up on that)

LLDB has worked good for me so far (using -DDEBUG=2 flags to get symbols working right), but I see nothing when trying to open a set in the variables frame.

I only get the number of items in it.

Is there similar macros as the GDB ones to inspect sets in LLDB? Or is there some other way?

Thanks

MrE
  • 19,584
  • 12
  • 87
  • 105

1 Answers1

0

lldb uses "data formatters" to pretty print objects. See:

http://lldb.llvm.org/varformats.html

for more details.

lldb has built-in data formatters for std::set from the clang standard libraries. If VSCode uses that version of the C++ standard library then the data formatters should fire automatically. If VSCode gives you access to the lldb command line, you can check the std::set data formatter thusly:

(lldb) fr v my_set
(std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> >) my_set = size=3 {
  [0] = 100
  [1] = 200
  [2] = 300
}

If you see the elements broken out then the data formatters are working (and you can use the console to view them.) If they use a different version of the STL, then the link above will get you started writing data formatters for their object layout.

The data formatters also hook into the API's lldb provides to inspect values, but it may be that VSCode is using lldb's emulation of gdb's "Machine Interface" layer, in which case it won't be able to access the data formatter results.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • Data formatters could also fail because the variable has been partially/entirely optimized away. – zneak Jul 19 '17 at 23:12
  • I use `O0` and `-DDEBUG=2`, so there should not be any optimization – MrE Jul 19 '17 at 23:38
  • Finally got to try this, but when I do `fr v myset` i get the size, and {} so it's not inspecting the object for some reason. Note that the set contain objects itself, so that may be why... but then how to i inspect objects isnide a set? – MrE Jul 25 '17 at 18:05