On Feb 6, 2006, at 1:08 PM, Robb Olsen-Albright wrote:
The Mac team where I work (well, it's me and one other developer) is working on converting our fairly large cross-platform Codewarrior project to Xcode (isn't everybody :) )
My question is regarding debugging code that uses STL vectors.
<snip>The first thing I'd do is turn on STL debug mode in Xcode. It's unfortunately only documented in the gcc 3.3 release notes:
STL debugging mode for C++
By default, libstdc++ is built with efficiency in mind, and therefore performs little or no error checking that is not required by the C++ standard. This release adds support for the libstdc++ debug mode, which performs run-time checking for correct usage of the C++ standard library. Incorrect usage (such as passing an iterator to the wrong container, or passing an invalid range to a generic algorithm) will result in a clear error message followed by an abort, rather than an unpredictable crash.
To enable STL debugging mode, compile your application with the -D_GLIBCXX_DEBUG compile flag. 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. This does not mean that you are required to recompile your entire application: for instance, if one source file uses std::vector but std::vector doesn't occur in its public interface, that file can be recompiled in debug mode even if the rest of the program is not compiled in debug mode.
When it is not feasible to recompile your application, or when only specific containers need checking, debugging containers are available as GNU extensions. These debugging containers are functionally equivalent to the containers used in debug mode, e.g., __gnu_debug::vector<int> is equivalent to std::vector<int> in debug mode, but the __gnu_debug versions can be used in either release or debug mode without changing semantics.
Pedantic debug mode checks not only for errors, but also for usages that rely on GNU extensions and that, while correct, may not be portable to other compilers. In pedantic mode, for example, constructing an std::string with a null pointer will result in an abort, not an exception. Pedantic debug mode is not the default. To enable pedantic debug mode, compile your program with both -D_GLIBCXX_DEBUG and -D_GLIBCXX_DEBUG_PEDANTIC.
STL debugging mode is recommended during developent or when you suspect an error caused by incorrect use of the C++ standard library. It is not recommended for deployment builds, because it introduces substantial overhead.
Chris