Using
Prev | Chapter 17. Debug Mode | Next

## 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 17.1. Debugging Containers

Container | Header | Debug container | Debug header
--- | --- | --- | ---
`std::bitset` | `bitset` | `__gnu_debug::bitset` | `<debug/bitset>`
`std::deque` | `deque` | `__gnu_debug::deque` | `<debug/deque>`
`std::list` | `list` | `__gnu_debug::list` | `<debug/list>`
`std::map` | `map` | `__gnu_debug::map` | `<debug/map>`
`std::multimap` | `map` | `__gnu_debug::multimap` | `<debug/map>`
`std::multiset` | `set` | `__gnu_debug::multiset` | `<debug/set>`
`std::set` | `set` | `__gnu_debug::set` | `<debug/set>`
`std::string` | `string` | `__gnu_debug::string` | `<debug/string>`
`std::wstring` | `string` | `__gnu_debug::wstring` | `<debug/string>`
`std::basic_string` | `string` | `__gnu_debug::basic_string` | `<debug/string>`
`std::vector` | `vector` | `__gnu_debug::vector` | `<debug/vector>`

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

Table 17.2. Debugging Containers C++0x

Container | Header | Debug container | Debug header
--- | --- | --- | ---
`std::unordered_map` | `unordered_map` | `__gnu_debug::unordered_map` | `<debug/unordered_map>`
`std::unordered_multimap` | `unordered_map` | `__gnu_debug::unordered_multimap` | `<debug/unordered_map>`
`std::unordered_set` | `unordered_set` | `__gnu_debug::unordered_set` | `<debug/unordered_set>`
`std::unordered_multiset` | `unordered_set` | `__gnu_debug::unordered_multiset` | `<debug/unordered_set>`

Prev | Up | Next
Semantics | Home | Design