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.
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
Container | Header | Debug container | Debug header |
---|---|---|---|
std::bitset | bitset | __gnu_debug::bitset | bitset |
std::deque | deque | __gnu_debug::deque | deque |
std::list | list | __gnu_debug::list | list |
std::map | map | __gnu_debug::map | map |
std::multimap | map | __gnu_debug::multimap | map |
std::multiset | set | __gnu_debug::multiset | set |
std::set | set | __gnu_debug::set | set |
std::string | string | __gnu_debug::string | string |
std::wstring | string | __gnu_debug::wstring | string |
std::basic_string | string | __gnu_debug::basic_string | string |
std::vector | vector | __gnu_debug::vector | vector |
In addition, when compiling in C++0x mode, these additional containers have additional debug capability.
Table 30.2. Debugging Containers C++0x
Container | Header | Debug container | Debug header |
---|---|---|---|
std::unordered_map | unordered_map | __gnu_debug::unordered_map | unordered_map |
std::unordered_multimap | unordered_map | __gnu_debug::unordered_multimap | unordered_map |
std::unordered_set | unordered_set | __gnu_debug::unordered_set | unordered_set |
std::unordered_multiset | unordered_set | __gnu_debug::unordered_multiset | unordered_set |