I have in trouble in inspecting std::map type variable with GDB. In GDB, I usually use the pretty-printer in libstd-c++ repository (https://sourceware.org/gdb/wiki/STLSupport) to print items in STL containers. The pretty-printer works fine with simple containers like vector, but it does not seem to fully support map.
To find an item with a given key in map, I tried to use operator[], but GDB reported the following error message, "Could not find operator[]".
Is it due to the pretty-printer's lack of support of map? or am I missing something?
Thanks
The pretty-printers are just a display feature. They don't affect evaluation. This can be confusing at times, as you've found.
In your case, gdb is trying to invoke the correct
operator[]
. However, your compiler has optimized it away -- this is very common in C++ programs.One option might be to compile with
-fkeep-inline-functions
. This will cause an out-of-line copy to be emitted. But, this isn't always desirable.Another method might be to use gdb's relatively new
xmethod
feature (see the relevant manual page) to write your own. Some xmethods for libstdc++ already went into the GCC tree, so your answer might be as simple as upgrading GCC.