From: Jonathan Wakely
Table of Contents
-g -O0
-fno-inline
flags will disable inlining and optimizations,
- and add debugging information, so that stepping through all functions,
+ and include debugging information, so that stepping through all functions,
(including inlined constructors and destructors) is possible. In
addition, -fno-eliminate-unused-debug-types
can be
used when additional debug information, such as nested class info,
@@ -30,31 +30,27 @@
Many other options are available: please see "Options
for Debugging Your Program" in Using the GNU Compiler
Collection (GCC) for a complete list.
-- If you would like debug symbols in libstdc++, there are two ways to - build libstdc++ with debug flags. The first is to create a separate - debug build by running make from the top-level of a tree - freshly-configured with -
- --enable-libstdcxx-debug -
and perhaps
- --enable-libstdcxx-debug-flags='...' -
- Both the normal build and the debug build will persist, without
- having to specify CXXFLAGS
, and the debug library will
- be installed in a separate directory tree, in (prefix)/lib/debug
.
- For more information, look at the
- configuration section.
+
+ The Debug Mode + has compile and run-time checks for many containers.
- A second approach is to use the configuration flags -
- make CXXFLAGS='-g3 -fno-inline -O0' all -
- This quick and dirty approach is often sufficient for quick - debugging tasks, when you cannot or don't want to recompile your - application to use the debug mode.
+ There are also lightweight assertions for checking function preconditions,
+ such as checking for out-of-bounds indices when accessing a
+ std::vector
. These can be enabled without using
+ the full Debug Mode, by using -D_GLIBCXX_ASSERTIONS
+ (see Macros).
+
+ The verbose + termination handler gives information about uncaught + exceptions which kill the program. +
On many targets GCC supports AddressSanitizer, a fast memory error detector,
which is enabled by the -fsanitize=address
option.
+
+ The std::vector
implementation has additional
+ instrumentation to work with AddressSanitizer, but this has to be enabled
+ explicitly by using -D_GLIBCXX_SANITIZE_VECTOR
+ (see Macros).
There are also various third party memory tracing and debug utilities that can be used to provide detailed memory allocation information @@ -225,14 +221,33 @@ on-line versions of the GDB user manual in GDB's homepage, at "GDB: The GNU Project Debugger" . -
- The verbose - termination handler gives information about uncaught - exceptions which kill the program. -
The Debug Mode - has compile and run-time checks for many containers. -
The Compile-Time +
+ As described above, libstdc++ is built with debug symbols enabled by default, + but because it's also built with optimizations the code can be hard to + follow when stepping into the library in a debugger. +
+ If you would like to debug libstdc++.so
itself,
+ there are two ways to build an unoptimized libstdc++ with debug flags.
+ The first is to create a separate debug build by running make from the
+ top-level of a tree freshly-configured with
+
+ --enable-libstdcxx-debug +
and perhaps
+ --enable-libstdcxx-debug-flags='...' +
+ Both the normal build and the debug build will persist, without
+ having to specify CXXFLAGS
, and the debug library will
+ be installed in a separate directory tree, in (prefix)/lib/debug
.
+ For more information, look at the
+ configuration section.
+
+ A second approach is to use the configuration flags +
+ make CXXFLAGS='-g3 -fno-inline -O0' all +
The Compile-Time Checks extension has compile-time checks for many algorithms. + These checks were designed for C++98 and have not been updated to work + with C++11 and later standards. They might be removed at a future date.