1ncend1ary
1ncend1ary

Reputation: 23

How to make LLDB work with STL in CLion on MacOS as I would expect on Linux

What I want to accomplish is to debug C++ code in CLion hassle-free, just like I would on Linux. I am going to be using the following code for illustration further on:

set<int> time;
time.insert(1);
size_t qq = time.size();

I attach screenshots of me using the Bundled LLDB and the GDB debuggers (attachments lldb and gdb respectively).

Expected gdb

Gdb

Lldb

As Apple dropped support of GDB, I had to install version 8.0.1, codesign it, and so on to get it working. I am expecting the behavior I get on my Linxu machine (with bundled GDB) (attachment expected respectively). I really want to be able to see the size of my set!

The issue is present both with LLDB and GDB on macOS as can be seen in attachments lldb and gdb (though there are no issues on Linux). I decided to try getting GDB for macOS just because the LLDB debugger wasn't working as expected and I was hoping it to be a debugger-specific issue.

Upvotes: 0

Views: 670

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

The problem with calling vector::size() is not actually a debugger problem but one with the clang implementation of the STL. Another version of this issue was discussed here:

Printing/Debugging libc++ STL with Xcode/LLDB

Note, the most recent version of the clang STL (the one in Xcode 12) is a lot less aggressive about inlining. With Xcode 12, I can run expr my_vec.size() and expr my_vec[0] and so forth and lldb does have a function to call (and successfully calls it!)

Since this is an issue with the compiler and the libraries, you will have to upgrade the tools you are using for building to get this fix.

Also, if you put just the variable in your watch window, rather than variable.size() CLion will print the variable summary, i.e. the size. That won't help if you need to use the size in an lldb expression (pass it to some other function or test whether it's > 5...) But the summary formatter for the variable will show you its size and do so more efficiently than calling the size method would.

Upvotes: 0

Related Questions