Using

Using the Debug Mode

To use the libstdc++ debug mode, compile your application with the compiler flag -D_GLIBCXX_DEBUG. Note that this flag changes the sizes and behavior of standard class templates such as std::vector, and therefore you can only link code compiled with debug mode and code compiled without debug mode if no instantiation of a container is passed between the two translation units.

By default, error messages are formatted to fit on lines of about 78 characters. The environment variable GLIBCXX_DEBUG_MESSAGE_LENGTH can be used to request a different length.

Using a Specific Debug Container

When it is not feasible to recompile your entire application, or only specific containers need checking, debugging containers are available as GNU extensions. These debugging containers are functionally equivalent to the standard drop-in containers used in debug mode, but they are available in a separate namespace as GNU extensions and may be used in programs compiled with either release mode or with debug mode. The following table provides the names and headers of the debugging containers:

Table 30.1. Debugging Containers

ContainerHeaderDebug containerDebug header
std::bitsetbitset__gnu_debug::bitsetbitset
std::dequedeque__gnu_debug::dequedeque
std::listlist__gnu_debug::listlist
std::mapmap__gnu_debug::mapmap
std::multimapmap__gnu_debug::multimapmap
std::multisetset__gnu_debug::multisetset
std::setset__gnu_debug::setset
std::stringstring__gnu_debug::stringstring
std::wstringstring__gnu_debug::wstringstring
std::basic_stringstring__gnu_debug::basic_stringstring
std::vectorvector__gnu_debug::vectorvector

In addition, when compiling in C++0x mode, these additional containers have additional debug capability.

Table 30.2. Debugging Containers C++0x

ContainerHeaderDebug containerDebug header
std::unordered_mapunordered_map__gnu_debug::unordered_mapunordered_map
std::unordered_multimapunordered_map__gnu_debug::unordered_multimapunordered_map
std::unordered_setunordered_set__gnu_debug::unordered_setunordered_set
std::unordered_multisetunordered_set__gnu_debug::unordered_multisetunordered_set