Situation
This is a debugging issue. I installed GDB printers for the standard library, but found that they did not work correctly under many circumstances. For example, debugging a piece of code with the following declaration:
std::map<int, int> foo;
I compiled with -O0 -ggdb3 , so I expected that I would not understand foo , and if I manually examine the structures, I will not have any problems. However, STL printers do not work quite well, because GCC seems to omit the type information of nested types, which my program does not explicitly create.
For example, if I run the following command in GDB:
p foo.begin()
I see the following error message:
Python Exception <class 'gdb.error'> No type named std::_Rb_tree_iterator<std::pair<int const, int> >::_Link_type.
This missing type name is an internal typedef defined inside std::map::iterator . This is an implementation-specific standard library support code, so it does not overlap with the platform (or even guaranteed to continue to exist between different versions of the implementation on the same platform).
However, if I declare something with this type in the program, a pretty printer will work correctly.
std::_Rb_tree_iterator<std::pair<int const, int> > ::_Link_type *dummy = NULL;
Question
So, how do I tell GCC not to delete type definitions in such situations so that they remain available to the debugger? Given that the STL implementation is not cross-platform, a hacky workaround, similar to declaring a bunch of dummy variables with a preprocessor macro, does not look like a scalable solution. Is there a flag that I can pass to GCC to force recursive inclusion of template types? Or does GCC not support this at all? Has anyone else encountered this problem and solved it?
Author Note
The printed version of GDB in GDB 7.7.1 (the latest version in the ubuntu repositories is 14.04 at the time of this writing) and cannot correctly print pointers. Those looking at this question may find it useful to know that this is a known issue and that an error has already been filed.