“Pretty-printing” STL vector in Eclipse CDT
It’s surprising to see why the C++ debugging scene in Mac/Linux is so behind Visual Studio. One definite strengths of MSVS is the ability to display STL vectors as arrays in the debug view.
If you’re using Eclipse CDT on Mac, you’re probably stuck with GDB 6.8 which doesn’t come with pretty printing. I tried self building GDB 7.2 but Eclipse CDT 8.0 doesn’t seem to be able to interact well with it (please someone come and correct me if I’m wrong).
So here’s how to display std::vector
nicely even if you’re using GDB 6.8:
https://cfc.kizzx2.com/wp-content/uploads/2011/07/eclipse-cdt-debug-vector.png
As you can see, the trick is to convert it to a pointer and to use the array syntax *((int*)nums) @ 3
Enjoy 🙂