head 1.1; branch 1.1.1; access; symbols netbsd-11-0-RC4:1.1.1.10 netbsd-11-0-RC3:1.1.1.10 netbsd-11-0-RC2:1.1.1.10 netbsd-11-0-RC1:1.1.1.10 gcc-14-3-0:1.1.1.11 perseant-exfatfs-base-20250801:1.1.1.10 netbsd-11:1.1.1.10.0.4 netbsd-11-base:1.1.1.10 gcc-12-5-0:1.1.1.10 netbsd-10-1-RELEASE:1.1.1.9 perseant-exfatfs-base-20240630:1.1.1.10 gcc-12-4-0:1.1.1.10 perseant-exfatfs:1.1.1.10.0.2 perseant-exfatfs-base:1.1.1.10 netbsd-8-3-RELEASE:1.1.1.3 netbsd-9-4-RELEASE:1.1.1.5 netbsd-10-0-RELEASE:1.1.1.9 netbsd-10-0-RC6:1.1.1.9 netbsd-10-0-RC5:1.1.1.9 netbsd-10-0-RC4:1.1.1.9 netbsd-10-0-RC3:1.1.1.9 netbsd-10-0-RC2:1.1.1.9 netbsd-10-0-RC1:1.1.1.9 gcc-12-3-0:1.1.1.10 gcc-10-5-0:1.1.1.9 netbsd-10:1.1.1.9.0.6 netbsd-10-base:1.1.1.9 netbsd-9-3-RELEASE:1.1.1.5 gcc-10-4-0:1.1.1.9 cjep_sun2x-base1:1.1.1.9 cjep_sun2x:1.1.1.9.0.4 cjep_sun2x-base:1.1.1.9 cjep_staticlib_x-base1:1.1.1.9 netbsd-9-2-RELEASE:1.1.1.5 cjep_staticlib_x:1.1.1.9.0.2 cjep_staticlib_x-base:1.1.1.9 gcc-10-3-0:1.1.1.9 netbsd-9-1-RELEASE:1.1.1.5 gcc-9-3-0:1.1.1.8 gcc-7-5-0:1.1.1.7 phil-wifi-20200421:1.1.1.6 phil-wifi-20200411:1.1.1.6 is-mlppp:1.1.1.5.0.4 is-mlppp-base:1.1.1.5 phil-wifi-20200406:1.1.1.6 netbsd-8-2-RELEASE:1.1.1.3 gcc-8-4-0:1.1.1.8 netbsd-9-0-RELEASE:1.1.1.5 netbsd-9-0-RC2:1.1.1.5 netbsd-9-0-RC1:1.1.1.5 phil-wifi-20191119:1.1.1.5 gcc-8-3-0:1.1.1.5 netbsd-9:1.1.1.5.0.2 netbsd-9-base:1.1.1.5 phil-wifi-20190609:1.1.1.5 netbsd-8-1-RELEASE:1.1.1.3 netbsd-8-1-RC1:1.1.1.3 pgoyette-compat-merge-20190127:1.1.1.3.14.2 pgoyette-compat-20190127:1.1.1.5 gcc-7-4-0:1.1.1.5 pgoyette-compat-20190118:1.1.1.4 pgoyette-compat-1226:1.1.1.4 pgoyette-compat-1126:1.1.1.4 gcc-6-5-0:1.1.1.4 pgoyette-compat-1020:1.1.1.3 pgoyette-compat-0930:1.1.1.3 pgoyette-compat-0906:1.1.1.3 netbsd-7-2-RELEASE:1.1.1.2 pgoyette-compat-0728:1.1.1.3 netbsd-8-0-RELEASE:1.1.1.3 phil-wifi:1.1.1.3.0.16 phil-wifi-base:1.1.1.3 pgoyette-compat-0625:1.1.1.3 netbsd-8-0-RC2:1.1.1.3 pgoyette-compat-0521:1.1.1.3 pgoyette-compat-0502:1.1.1.3 pgoyette-compat-0422:1.1.1.3 netbsd-8-0-RC1:1.1.1.3 pgoyette-compat-0415:1.1.1.3 pgoyette-compat-0407:1.1.1.3 pgoyette-compat-0330:1.1.1.3 pgoyette-compat-0322:1.1.1.3 pgoyette-compat-0315:1.1.1.3 netbsd-7-1-2-RELEASE:1.1.1.2 pgoyette-compat:1.1.1.3.0.14 pgoyette-compat-base:1.1.1.3 gcc-6-4-0:1.1.1.3 netbsd-7-1-1-RELEASE:1.1.1.2 gcc-5-5-0:1.1.1.3 matt-nb8-mediatek:1.1.1.3.0.12 matt-nb8-mediatek-base:1.1.1.3 perseant-stdc-iso10646:1.1.1.3.0.10 perseant-stdc-iso10646-base:1.1.1.3 netbsd-8:1.1.1.3.0.8 netbsd-8-base:1.1.1.3 prg-localcount2-base3:1.1.1.3 prg-localcount2-base2:1.1.1.3 prg-localcount2-base1:1.1.1.3 prg-localcount2:1.1.1.3.0.6 prg-localcount2-base:1.1.1.3 pgoyette-localcount-20170426:1.1.1.3 bouyer-socketcan-base1:1.1.1.3 pgoyette-localcount-20170320:1.1.1.3 netbsd-7-1:1.1.1.2.0.10 netbsd-7-1-RELEASE:1.1.1.2 netbsd-7-1-RC2:1.1.1.2 netbsd-7-nhusb-base-20170116:1.1.1.2 bouyer-socketcan:1.1.1.3.0.4 bouyer-socketcan-base:1.1.1.3 pgoyette-localcount-20170107:1.1.1.3 netbsd-7-1-RC1:1.1.1.2 pgoyette-localcount-20161104:1.1.1.3 netbsd-7-0-2-RELEASE:1.1.1.2 localcount-20160914:1.1.1.3 netbsd-7-nhusb:1.1.1.2.0.8 netbsd-7-nhusb-base:1.1.1.2 pgoyette-localcount-20160806:1.1.1.3 pgoyette-localcount-20160726:1.1.1.3 pgoyette-localcount:1.1.1.3.0.2 pgoyette-localcount-base:1.1.1.3 gcc-5-4-0:1.1.1.3 netbsd-7-0-1-RELEASE:1.1.1.2 gcc-5-3-0:1.1.1.3 netbsd-7-0:1.1.1.2.0.6 netbsd-7-0-RELEASE:1.1.1.2 gcc-4-8-5-pre-gcc-old-import:1.1.1.2 netbsd-7-0-RC3:1.1.1.2 netbsd-7-0-RC2:1.1.1.2 post-gcc-4-8-5-merge:1.1.1.2 gcc-4-8-5:1.1.1.2 netbsd-7-0-RC1:1.1.1.2 gcc-4-8-4:1.1.1.2 gcc-4-8-20141009:1.1.1.2 netbsd-6-0-6-RELEASE:1.1.1.1 netbsd-6-1-5-RELEASE:1.1.1.1 netbsd-7:1.1.1.2.0.4 netbsd-7-base:1.1.1.2 gcc-4-8-3:1.1.1.2 yamt-pagecache-base9:1.1.1.2 yamt-pagecache-tag8:1.1.1.1 netbsd-6-1-4-RELEASE:1.1.1.1 netbsd-6-0-5-RELEASE:1.1.1.1 tls-earlyentropy:1.1.1.2.0.2 tls-earlyentropy-base:1.1.1.2 riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.2 riastradh-drm2-base3:1.1.1.2 gcc-4-8-3-pre-r208254:1.1.1.2 gcc-4-8-3-pre-r206687:1.1.1.2 imported-to-gcc-old-20140227-0107:1.1.1.1 netbsd-6-1-3-RELEASE:1.1.1.1 netbsd-6-0-4-RELEASE:1.1.1.1 netbsd-6-1-2-RELEASE:1.1.1.1 netbsd-6-0-3-RELEASE:1.1.1.1 netbsd-6-1-1-RELEASE:1.1.1.1 riastradh-drm2-base2:1.1.1.1 riastradh-drm2-base1:1.1.1.1 riastradh-drm2:1.1.1.1.0.12 riastradh-drm2-base:1.1.1.1 netbsd-6-1:1.1.1.1.0.16 netbsd-6-0-2-RELEASE:1.1.1.1 netbsd-6-1-RELEASE:1.1.1.1 netbsd-6-1-RC4:1.1.1.1 netbsd-6-1-RC3:1.1.1.1 agc-symver:1.1.1.1.0.14 agc-symver-base:1.1.1.1 netbsd-6-1-RC2:1.1.1.1 netbsd-6-1-RC1:1.1.1.1 yamt-pagecache-base8:1.1.1.1 netbsd-6-0-1-RELEASE:1.1.1.1 yamt-pagecache-base7:1.1.1.1 matt-nb6-plus-nbase:1.1.1.1 yamt-pagecache-base6:1.1.1.1 netbsd-6-0:1.1.1.1.0.10 netbsd-6-0-RELEASE:1.1.1.1 gcc-4-5-4:1.1.1.1 netbsd-6-0-RC2:1.1.1.1 tls-maxphys:1.1.1.1.0.8 tls-maxphys-base:1.1.1.2 matt-nb6-plus:1.1.1.1.0.6 matt-nb6-plus-base:1.1.1.1 netbsd-6-0-RC1:1.1.1.1 yamt-pagecache-base5:1.1.1.1 yamt-pagecache-base4:1.1.1.1 netbsd-6:1.1.1.1.0.4 netbsd-6-base:1.1.1.1 yamt-pagecache-base3:1.1.1.1 yamt-pagecache-base2:1.1.1.1 yamt-pagecache:1.1.1.1.0.2 yamt-pagecache-base:1.1.1.1 gcc-4-5-3:1.1.1.1 FSF:1.1.1; locks; strict; comment @# @; 1.1 date 2011.06.21.01.24.07; author mrg; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2011.06.21.01.24.07; author mrg; state Exp; branches 1.1.1.1.2.1 1.1.1.1.8.1; next 1.1.1.2; 1.1.1.2 date 2014.03.01.08.41.30; author mrg; state Exp; branches; next 1.1.1.3; commitid TtaB91QNTknAoYqx; 1.1.1.3 date 2016.01.24.06.05.43; author mrg; state Exp; branches 1.1.1.3.14.1 1.1.1.3.16.1; next 1.1.1.4; commitid uWWfbLp08zOK79Sy; 1.1.1.4 date 2018.11.04.00.12.37; author mrg; state Exp; branches; next 1.1.1.5; commitid bulspy67pMB6EyYA; 1.1.1.5 date 2019.01.19.10.14.11; author mrg; state Exp; branches; next 1.1.1.6; commitid VQ8OwWIg5RS9kn8B; 1.1.1.6 date 2020.03.11.08.15.59; author mrg; state Exp; branches; next 1.1.1.7; commitid AhKhCnGPUZgytXZB; 1.1.1.7 date 2020.08.11.05.10.39; author mrg; state Exp; branches; next 1.1.1.8; commitid 5dBRDT7i6e65xBjC; 1.1.1.8 date 2020.08.11.05.30.16; author mrg; state Exp; branches; next 1.1.1.9; commitid 7AI4OfpLi4eqEBjC; 1.1.1.9 date 2021.04.10.22.10.05; author mrg; state Exp; branches; next 1.1.1.10; commitid eC4g0MRpqTvEkNOC; 1.1.1.10 date 2023.07.30.05.21.21; author mrg; state Exp; branches; next 1.1.1.11; commitid tk6nV4mbc9nVEMyE; 1.1.1.11 date 2025.09.13.23.45.49; author mrg; state Exp; branches; next ; commitid KwhwN4krNWa6XBaG; 1.1.1.1.2.1 date 2014.05.22.16.37.45; author yamt; state Exp; branches; next ; commitid DX8bafDLmqEbpyBx; 1.1.1.1.8.1 date 2014.08.19.23.54.46; author tls; state Exp; branches; next ; commitid jTnpym9Qu0o4R1Nx; 1.1.1.3.14.1 date 2018.11.26.01.50.57; author pgoyette; state Exp; branches; next 1.1.1.3.14.2; commitid Zj4q5SspGdKXto1B; 1.1.1.3.14.2 date 2019.01.26.21.59.32; author pgoyette; state Exp; branches; next ; commitid JKpcmvSjdT25dl9B; 1.1.1.3.16.1 date 2019.06.10.21.54.48; author christos; state Exp; branches; next 1.1.1.3.16.2; commitid jtc8rnCzWiEEHGqB; 1.1.1.3.16.2 date 2020.04.08.14.06.37; author martin; state Exp; branches; next ; commitid Qli2aW9E74UFuA3C; desc @@ 1.1 log @Initial revision @ text @
There are numerous things that can be done to improve the ease with which C++ binaries are debugged when using the GNU tool chain. Here are some of them.
Compiler flags determine how debug information is transmitted between compilation and debug or analysis tools.
The default optimizations and debug flags for a libstdc++ build
are -g -O2. However, both debug and optimization
flags can be varied to change debugging characteristics. For
instance, turning off all optimization via the -g -O0
-fno-inline flags will disable inlining and optimizations,
and add 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,
is desired.
Or, the debug format that the compiler and debugger use to
communicate information about source constructs can be changed via
-gdwarf-2 or -gstabs flags: some debugging
formats permit more expressive type and scope information to be
shown in gdb. Expressiveness can be enhanced by flags like
-g3. The default debug information for a particular
platform can be identified via the value set by the
PREFERRED_DEBUGGING_TYPE macro in the gcc sources.
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 run make from the toplevel in a freshly-configured tree with
--enable-libstdcxx-debug
and perhaps
--enable-libstdcxx-debug-flags='...'
to create a separate debug build. 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
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 various third party memory tracing and debug utilities
that can be used to provide detailed memory allocation information
about C++ code. An exhaustive list of tools is not going to be
attempted, but includes mtrace, valgrind,
mudflap, and the non-free commercial product
purify. In addition, libcwd has a
replacement for the global new and delete operators that can track
memory allocation and deallocation and provide useful memory
statistics.
Regardless of the memory debugging tool being used, there is one
thing of great importance to keep in mind when debugging C++ code
that uses new and delete: there are
different kinds of allocation schemes that can be used by
std::allocator . For implementation details, see the mt allocator documentation and
look specifically for GLIBCXX_FORCE_NEW.
In a nutshell, the default allocator used by
std::allocator is a high-performance pool allocator, and can
give the mistaken impression that in a suspect executable, memory is
being leaked, when in reality the memory "leak" is a pool being used
by the library's allocator and is reclaimed after program
termination.
For valgrind, there are some specific items to keep in mind. First of all, use a version of valgrind that will work with current GNU C++ tools: the first that can do this is valgrind 1.0.4, but later versions should work at least as well. Second of all, use a completely unoptimized build to avoid confusing valgrind. Third, use GLIBCXX_FORCE_NEW to keep extraneous pool allocation noise from cluttering debug information.
Fourth, it may be necessary to force deallocation in other libraries
as well, namely the "C" library. On linux, this can be accomplished
with the appropriate use of the __cxa_atexit or
atexit functions.
#include <cstdlib>
extern "C" void __libc_freeres(void);
void do_something() { }
int main()
{
atexit(__libc_freeres);
do_something();
return 0;
}
or, using __cxa_atexit:
extern "C" void __libc_freeres(void);
extern "C" int __cxa_atexit(void (*func) (void *), void *arg, void *d);
void do_something() { }
int main()
{
extern void* __dso_handle __attribute__ ((__weak__));
__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
&__dso_handle ? __dso_handle : NULL);
do_test();
return 0;
}
Suggested valgrind flags, given the suggestions above about setting up the runtime environment, library, and test file, might be:
valgrind -v --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes a.out
Many options are available for gdb itself: please see "GDB features for C++" in the gdb documentation. Also recommended: the other parts of this manual.
These settings can either be switched on in at the gdb command line, or put into a .gdbint file to establish default debugging characteristics, like so:
set print pretty on set print object on set print static-members on set print vtbl on set print demangle on set demangle-style gnu-v3
Starting with version 7.0, GDB includes support for writing pretty-printers in Python. Pretty printers for STL classes are distributed with GCC from version 4.5.0. The most recent version of these printers are always found in libstdc++ svn repository. To enable these printers, check-out the latest printers to a local directory:
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
Next, add the following section to your ~/.gdbinit The path must match the location where the Python module above was checked-out. So if checked out to: /home/maude/gdb_printers/, the path would be as written in the example below.
python import sys sys.path.insert(0, '/home/maude/gdb_printers/python') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) end
The path should be the only element that needs to be adjusted in the example. Once loaded, STL classes that the printers support should print in a more human-readable format. To print the classes in the old style, use the /r (raw) switch in the print command (i.e., print /r foo). This will print the classes as if the Python pretty-printers were not loaded.
For additional information on STL support and GDB please visit: "GDB Support for STL" in the GDB wiki. Additionally, in-depth documentation and discussion of the pretty printing feature can be found in "Pretty Printing" node in the GDB manual. You can find 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 are killing the program. It is described in the linked-to page.
The Debug Mode has compile and run-time checks for many containers.
The Compile-Time Checks Extension has compile-time checks for many algorithms.
The Profile-based Performance Analysis Extension has performance checks for many algorithms.
d7 1 a7 1
d26 1 a26 1 shown in GDB. Expressiveness can be enhanced by flags like d29 1 a29 1 PREFERRED_DEBUGGING_TYPE macro in the GCC sources. d31 1 a31 1 Many other options are available: please see "Options d34 1 a34 1
d36 2
a37 3
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
d43 5
a47 5
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.
d49 1
a49 1
A second approach is to use the configuration flags
d55 1
a55 1
application to use the debug mode.
d70 1
a70 1
std::allocator. For implementation details, see the mt allocator documentation and
d73 2
a74 2
In a nutshell, the optional mt_allocator
is a high-performance pool allocator, and can
d114 2
a115 2
__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
&__dso_handle ? __dso_handle : NULL);
d122 1
a122 1
d124 1 a124 51
All synchronization primitives used in the library internals need to be understood by race detectors so that they do not produce false reports.
Two annotation macros are used to explain low-level synchronization
to race detectors:
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE() and
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER().
By default, these macros are defined empty -- anyone who wants
to use a race detector needs to redefine them to call an
appropriate API.
Since these macros are empty by default when the library is built,
redefining them will only affect inline functions and template
instantiations which are compiled in user code. This allows annotation
of templates such as shared_ptr, but not code which is
only instantiated in the library. Code which is only instantiated in
the library needs to be recompiled with the annotation macros defined.
That can be done by rebuilding the entire
libstdc++.so file but a simpler
alternative exists for ELF platforms such as GNU/Linux, because ELF
symbol interposition allows symbols defined in the shared library to be
overridden by symbols with the same name that appear earlier in the
runtime search path. This means you only need to recompile the functions
that are affected by the annotation macros, which can be done by
recompiling individual files.
Annotating std::string and std::wstring
reference counting can be done by disabling extern templates (by defining
_GLIBCXX_EXTERN_TEMPLATE=-1) or by rebuilding the
src/string-inst.cc file.
Annotating the remaining atomic operations (at the time of writing these
are in ios_base::Init::~Init, locale::_Impl,
locale::facet and thread::_M_start_thread)
requires rebuilding the relevant source files.
The approach described above is known to work with the following race detection tools: DRD, Helgrind, and ThreadSanitizer.
With DRD, Helgrind and ThreadSanitizer you will need to define the macros like this:
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(A) ANNOTATE_HAPPENS_BEFORE(A) #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(A) ANNOTATE_HAPPENS_AFTER(A)
Refer to the documentation of each particular tool for details.
d126 2 a127 2 Many options are available for GDB itself: please see "GDB features for C++" in the GDB documentation. Also d130 1 a130 1 These settings can either be switched on in at the GDB command line, d148 1 a148 1 svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python d170 1 a170 1 "GDB Support d175 1 a175 1 "GDB: The GNU Project d177 2 a178 2
The Debug Mode d184 1 a184 1
The Profile-based Performance Analysis Extension has performance checks for many d189 4 a192 3
d7 1 a7 1
d26 1 a26 1 shown in GDB. Expressiveness can be enhanced by flags like d29 1 a29 1 PREFERRED_DEBUGGING_TYPE macro in the GCC sources. d31 1 a31 1 Many other options are available: please see "Options d34 1 a34 1
d36 2
a37 3
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
d43 5
a47 5
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.
d49 1
a49 1
A second approach is to use the configuration flags
d55 1
a55 1
application to use the debug mode.
d70 1
a70 1
std::allocator. For implementation details, see the mt allocator documentation and
d73 2
a74 2
In a nutshell, the optional mt_allocator
is a high-performance pool allocator, and can
d114 2
a115 2
__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
&__dso_handle ? __dso_handle : NULL);
d122 1
a122 1
d124 1 a124 51
All synchronization primitives used in the library internals need to be understood by race detectors so that they do not produce false reports.
Two annotation macros are used to explain low-level synchronization
to race detectors:
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE() and
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER().
By default, these macros are defined empty -- anyone who wants
to use a race detector needs to redefine them to call an
appropriate API.
Since these macros are empty by default when the library is built,
redefining them will only affect inline functions and template
instantiations which are compiled in user code. This allows annotation
of templates such as shared_ptr, but not code which is
only instantiated in the library. Code which is only instantiated in
the library needs to be recompiled with the annotation macros defined.
That can be done by rebuilding the entire
libstdc++.so file but a simpler
alternative exists for ELF platforms such as GNU/Linux, because ELF
symbol interposition allows symbols defined in the shared library to be
overridden by symbols with the same name that appear earlier in the
runtime search path. This means you only need to recompile the functions
that are affected by the annotation macros, which can be done by
recompiling individual files.
Annotating std::string and std::wstring
reference counting can be done by disabling extern templates (by defining
_GLIBCXX_EXTERN_TEMPLATE=-1) or by rebuilding the
src/string-inst.cc file.
Annotating the remaining atomic operations (at the time of writing these
are in ios_base::Init::~Init, locale::_Impl,
locale::facet and thread::_M_start_thread)
requires rebuilding the relevant source files.
The approach described above is known to work with the following race detection tools: DRD, Helgrind, and ThreadSanitizer.
With DRD, Helgrind and ThreadSanitizer you will need to define the macros like this:
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(A) ANNOTATE_HAPPENS_BEFORE(A) #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(A) ANNOTATE_HAPPENS_AFTER(A)
Refer to the documentation of each particular tool for details.
d126 2 a127 2 Many options are available for GDB itself: please see "GDB features for C++" in the GDB documentation. Also d130 1 a130 1 These settings can either be switched on in at the GDB command line, d148 1 a148 1 svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python d170 1 a170 1 "GDB Support d175 1 a175 1 "GDB: The GNU Project d177 2 a178 2
The Debug Mode d184 1 a184 1
The Profile-based Performance Analysis Extension has performance checks for many d189 4 a192 3
d7 1 a7 1
d26 1 a26 1 shown in GDB. Expressiveness can be enhanced by flags like d29 1 a29 1 PREFERRED_DEBUGGING_TYPE macro in the GCC sources. d31 1 a31 1 Many other options are available: please see "Options d34 1 a34 1
d36 2
a37 3
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
d43 5
a47 5
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.
d49 1
a49 1
A second approach is to use the configuration flags
d55 1
a55 1
application to use the debug mode.
d70 1
a70 1
std::allocator. For implementation details, see the mt allocator documentation and
d73 2
a74 2
In a nutshell, the optional mt_allocator
is a high-performance pool allocator, and can
d114 2
a115 2
__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
&__dso_handle ? __dso_handle : NULL);
d122 1
a122 1
d124 1 a124 51
All synchronization primitives used in the library internals need to be understood by race detectors so that they do not produce false reports.
Two annotation macros are used to explain low-level synchronization
to race detectors:
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE() and
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER().
By default, these macros are defined empty -- anyone who wants
to use a race detector needs to redefine them to call an
appropriate API.
Since these macros are empty by default when the library is built,
redefining them will only affect inline functions and template
instantiations which are compiled in user code. This allows annotation
of templates such as shared_ptr, but not code which is
only instantiated in the library. Code which is only instantiated in
the library needs to be recompiled with the annotation macros defined.
That can be done by rebuilding the entire
libstdc++.so file but a simpler
alternative exists for ELF platforms such as GNU/Linux, because ELF
symbol interposition allows symbols defined in the shared library to be
overridden by symbols with the same name that appear earlier in the
runtime search path. This means you only need to recompile the functions
that are affected by the annotation macros, which can be done by
recompiling individual files.
Annotating std::string and std::wstring
reference counting can be done by disabling extern templates (by defining
_GLIBCXX_EXTERN_TEMPLATE=-1) or by rebuilding the
src/string-inst.cc file.
Annotating the remaining atomic operations (at the time of writing these
are in ios_base::Init::~Init, locale::_Impl,
locale::facet and thread::_M_start_thread)
requires rebuilding the relevant source files.
The approach described above is known to work with the following race detection tools: DRD, Helgrind, and ThreadSanitizer.
With DRD, Helgrind and ThreadSanitizer you will need to define the macros like this:
#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(A) ANNOTATE_HAPPENS_BEFORE(A) #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(A) ANNOTATE_HAPPENS_AFTER(A)
Refer to the documentation of each particular tool for details.
d126 2 a127 2 Many options are available for GDB itself: please see "GDB features for C++" in the GDB documentation. Also d130 1 a130 1 These settings can either be switched on in at the GDB command line, d148 1 a148 1 svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python d170 1 a170 1 "GDB Support d175 1 a175 1 "GDB: The GNU Project d177 2 a178 2
The Debug Mode d184 1 a184 1
The Profile-based Performance Analysis Extension has performance checks for many d189 4 a192 3
.gdbinit file to establish default
debugging characteristics, like so:
d192 22
a213 12
pretty-printers in Python. Pretty printers for containers and other
classes are distributed with GCC from version 4.5.0 and should be installed
alongside the libstdc++ shared library files and found automatically by
GDB.
Depending where libstdc++ is installed, GDB might refuse to auto-load
the python printers and print a warning instead.
If this happens the python printers can be enabled by following the
instructions GDB gives for setting your auto-load safe-path
in your .gdbinit configuration file.
Once loaded, standard library classes that the printers support
d215 3
a217 3
in the old style, use the /r (raw) switch in the
print command (i.e., print /r foo). This will
print the classes as if the Python pretty-printers were not loaded.
d230 2
a231 1
exceptions which kill the program.
d235 1
a235 1
Checks extension has compile-time checks for many algorithms.
d237 1
a237 1
Performance Analysis extension has performance checks for many
@
1.1.1.3.16.1
log
@Sync with HEAD
@
text
@d2 1
a2 1
There are also various third party memory tracing and debug utilities
d60 19
a78 6
mudflap (no longer supported since GCC 4.9.0), ElectricFence,
and the non-free commercial product purify.
In addition, libcwd, jemalloc and TCMalloc have replacements
for the global new and delete operators
that can track memory allocation and deallocation and provide useful
memory statistics.
d83 4
a86 2
versions should work better. Second, using an unoptimized build
might avoid confusing valgrind.
d88 2
a89 2
Third, it may be necessary to force deallocation in other libraries
as well, namely the "C" library. On GNU/Linux, this can be accomplished
d124 1
a124 23
There are different kinds of allocation schemes that can be used by
std::allocator. Prior to GCC 3.4.0 the default was to use
a pooling allocator, pool_allocator,
which is still available as the optional
__pool_alloc extension.
Another optional extension, __mt_alloc,
is a high-performance pool allocator.
In a suspect executable these pooling allocators can give the mistaken impression that memory is being leaked, when in reality the memory "leak" is a pool being used by the library's allocator and is reclaimed after program termination.
If you're using memory debugging tools on a program that uses
one of these pooling allocators, you can set the environment variable
GLIBCXX_FORCE_NEW to keep extraneous pool allocation
noise from cluttering debug information.
For more details, see the
mt allocator
documentation and look specifically for GLIBCXX_FORCE_NEW.
@ 1.1.1.3.14.1 log @Sync with HEAD, resolve a couple of conflicts @ text @d2 1 a2 1
@
1.1.1.3.14.2
log
@Sync with HEAD
@
text
@d164 1
a164 1
@
1.1.1.4
log
@import GCC 6.5.0. this is largely a maint release with no
particularly features listed here:
http://gcc.gnu.org/gcc-6/changes.html
this fixes over 250 PRs in the GCC bugzilla:
https://gcc.gnu.org/bugzilla/buglist.cgi?bug_status=RESOLVED&resolution=FIXED&target_milestone=6.5
@
text
@d2 1
a2 1
@
1.1.1.5
log
@import GCC 7.4.0. main changes include:
The non-standard C++0x type traits has_trivial_default_constructor,
has_trivial_copy_constructor and has_trivial_copy_assign have been
removed.
On ARM targets (arm*-*-*), a bug introduced in GCC 5 that affects
conformance to the procedure call standard (AAPCS) has been fixed.
Many optimiser improvements
DWARF-5 support.
Many new and enhanced warnings.
Warnings about format strings now underline the pertinent part of
the string, and can offer suggested fixes.
Several new warnings related to buffer overflows and buffer
truncation.
New __builtin_add_overflow_p, __builtin_sub_overflow_p,
__builtin_mul_overflow_p built-ins added that test for overflow.
The C++ front end has experimental support for all of the current
C++17 draft.
The -fverbose-asm option has been expanded to prints comments
showing the source lines that correspond to the assembly.
The gcc and g++ driver programs will now provide suggestions for
misspelled arguments to command-line options.
AArch64 specific:
GCC has been updated to the latest revision of the procedure call
standard (AAPCS64) to provide support for parameter passing when
data types have been over-aligned.
The ARMv8.2-A and ARMv8.3-A architecture are now supported.
ARM specific:
Support for the ARMv5 and ARMv5E architectures has been
deprecated (which have no known implementations).
A new command-line option -mpure-code has been added. It does not
allow constant data to be placed in code sections.
x86 specific:
Support for the AVX-512 4FMAPS, 4VNNIW, VPOPCNTDQ and Software
Guard Extensions (SGX) ISA extensions has been added.
PPC specific:
GCC now diagnoses inline assembly that clobbers register r2.
RISC-V specific:
Support for the RISC-V instruction set has been added.
SH specific:
Support for SH5/SH64 has been removed.
Support for SH2A has been enhanced.
@
text
@d164 1
a164 1
@
1.1.1.6
log
@import GCC 8.4. it fixes at least these 210 PRs in GCC bugzilla:
90095 93348 89906 89766 86747 87770 89588 89753 88235 89762 89684 89946
89965 90010 90026 90733 90810 90840 90842 90867 91623 92930 93073 93402
93505 93576 93744 93820 93908 85762 86429 86521 87327 87480 87513 87554
87685 87748 88183 88380 88394 88419 88690 88820 89381 89422 89576 89831
89917 90951 92003 92852 93140 80791 89358 89970 90899 89212 89419 92745
93684 93789 88273 91826 92376 84746 89497 89595 89664 89711 89725 90018
90316 90900 91108 91293 91772 92763 93054 93246 90313 92420 93434 93767
88530 89517 91838 79262 84680 85459 85711 85860 86567 87008 87651 87652
88469 89546 89827 90197 93072 93241 81800 89190 85400 91472 91854 92095
92131 92575 93704 60228 61414 65782 89405 89498 89703 89752 90187 90193
90898 91401 91450 91665 92296 92384 92438 92615 92648 92723 92732 92904
93087 93228 93515 93905 82081 92859 89712 89876 92106 82645 78552 81266
85965 89102 90165 90299 90532 91436 92059 93205 93325 93562 90359 91280
91375 92674 92704 93439 92768 80938 83361 90563 92113 92961 87833 89848
89902 89903 92022 93828 78179 79221 82920 84016 87015 88075 89077 89266
90454 90634 91226 92154 92664 92886 93065 92692 92629 80590 91944 92899
92977 93463 89601 88025 91660 91845 90498 91077 84487 86119 89174 89981
91550 92569 84135 84974 90872 93714
@
text
@d56 1
a56 4
On many targets GCC supports AddressSanitizer, a fast memory error detector,
which is enabled by the
There are also various third party memory tracing and debug utilities
d60 19
a78 6
There are different kinds of allocation schemes that can be used by
In a suspect executable these pooling allocators can give
the mistaken impression that memory is being leaked,
when in reality the memory "leak" is a pool being used
by the library's allocator and is reclaimed after program
termination.
If you're using memory debugging tools on a program that uses
one of these pooling allocators, you can set the environment variable
@
1.1.1.7
log
@import GCC 7.5.0. doing this here so that the vendor branch has
the code we'll merge into gcc.old and the netbsd-9 tree gcc tree.
GCC 8.4.0 will be imported immediately on top of this again,
restoring the current status.
these PRs in the GCC bugzilla are fixed with this update:
89869 80693 89795 84272 85593 86669 87148 87647 87895 88103 88107 88563
88870 88976 89002 89187 89195 89234 89303 89314 89354 89361 89403 89412
89512 89520 89590 89621 89663 89679 89704 89734 89872 89933 90090 90208
87075 85870 89009 89242 88167 80864 81933 85890 86608 87145 88857 89024
89119 89214 89511 89612 89705 89400 81740 82186 84552 86554 87609 88105
88149 88415 88739 88903 89135 89223 89296 89505 89572 89677 89698 89710
90006 90020 90071 90328 90474 91126 91162 91812 91887 90075 88998 89945
87047 87506 88074 88656 88740 91137 89008 84010 89349 91136 91347 91995
89397 87030 60702 78884 85594 87649 87725 88181 88470 88553 88568 88588
88620 88644 88906 88949 89246 89587 89726 89768 89796 89998 90108 90756
90950 91704 88825 88983 86538 51333 89446 90220 91308 92143 89392 90213
90278 91131 91200 91510 89037 91481 87673 88418 88938 88948 90547 27221
58321 61250 67183 67958 77583 83531 86215 88648 88720 88726 89091 89466
89629 90105 90329 90585 90760 90924 91087 89222 81956 71861 35031 69455
81849 82993 85798 88138 88155 88169 88205 88206 88228 88249 88269 88376
77703 80260 82077 86248 88393 90786 57048 66089 66695 67679 68009 71723
72714 84394 85544 87734 88298 90937 91557 63891 64132 65342 68649 68717
71066 71860 71935 77746 78421 78645 78865 78983 79485 79540 85953 88326
89651 90744
@
text
@d56 4
a59 1
There are various third party memory tracing and debug utilities
d63 6
a68 19
Regardless of the memory debugging tool being used, there is one
thing of great importance to keep in mind when debugging C++ code
that uses
In a nutshell, the optional
@
1.1.1.8
log
@re-import GCC 8.4.0.
@
text
@d56 1
a56 4
On many targets GCC supports AddressSanitizer, a fast memory error detector,
which is enabled by the
There are also various third party memory tracing and debug utilities
d60 19
a78 6
There are different kinds of allocation schemes that can be used by
In a suspect executable these pooling allocators can give
the mistaken impression that memory is being leaked,
when in reality the memory "leak" is a pool being used
by the library's allocator and is reclaimed after program
termination.
If you're using memory debugging tools on a program that uses
one of these pooling allocators, you can set the environment variable
@
1.1.1.9
log
@initial import of GCC 10.3.0. main changes include:
caveats:
- ABI issue between c++14 and c++17 fixed
- profile mode is removed from libstdc++
- -fno-common is now the default
new features:
- new flags -fallocation-dce, -fprofile-partial-training,
-fprofile-reproducible, -fprofile-prefix-path, and -fanalyzer
- many new compile and link time optimisations
- enhanced drive optimisations
- openacc 2.6 support
- openmp 5.0 features
- new warnings: -Wstring-compare and -Wzero-length-bounds
- extended warnings: -Warray-bounds, -Wformat-overflow,
-Wrestrict, -Wreturn-local-addr, -Wstringop-overflow,
-Warith-conversion, -Wmismatched-tags, and -Wredundant-tags
- some likely C2X features implemented
- more C++20 implemented
- many new arm & intel CPUs known
hundreds of reported bugs are fixed. full list of changes
can be found at:
https://gcc.gnu.org/gcc-10/changes.html
@
text
@d132 1
a132 1
mt allocator
d236 3
@
1.1.1.10
log
@initial import of GCC 12.3.0.
major changes in GCC 11 included:
- The default mode for C++ is now -std=gnu++17 instead of -std=gnu++14.
- When building GCC itself, the host compiler must now support C++11,
rather than C++98.
- Some short options of the gcov tool have been renamed: -i to -j and
-j to -H.
- ThreadSanitizer improvements.
- Introduce Hardware-assisted AddressSanitizer support.
- For targets that produce DWARF debugging information GCC now defaults
to DWARF version 5. This can produce up to 25% more compact debug
information compared to earlier versions.
- Many optimisations.
- The existing malloc attribute has been extended so that it can be
used to identify allocator/deallocator API pairs. A pair of new
-Wmismatched-dealloc and -Wmismatched-new-delete warnings are added.
- Other new warnings:
-Wsizeof-array-div, enabled by -Wall, warns about divisions of two
sizeof operators when the first one is applied to an array and the
divisor does not equal the size of the array element.
-Wstringop-overread, enabled by default, warns about calls to string
functions reading past the end of the arrays passed to them as
arguments.
-Wtsan, enabled by default, warns about unsupported features in
ThreadSanitizer (currently std::atomic_thread_fence).
- Enchanced warnings:
-Wfree-nonheap-object detects many more instances of calls to
deallocation functions with pointers not returned from a dynamic
memory allocation function.
-Wmaybe-uninitialized diagnoses passing pointers or references to
uninitialized memory to functions taking const-qualified arguments.
-Wuninitialized detects reads from uninitialized dynamically
allocated memory.
-Warray-parameter warns about functions with inconsistent array forms.
-Wvla-parameter warns about functions with inconsistent VLA forms.
- Several new features from the upcoming C2X revision of the ISO C
standard are supported with -std=c2x and -std=gnu2x.
- Several C++20 features have been implemented.
- The C++ front end has experimental support for some of the upcoming
C++23 draft.
- Several new C++ warnings.
- Enhanced Arm, AArch64, x86, and RISC-V CPU support.
- The implementation of how program state is tracked within
-fanalyzer has been completely rewritten with many enhancements.
see https://gcc.gnu.org/gcc-11/changes.html for a full list.
major changes in GCC 12 include:
- An ABI incompatibility between C and C++ when passing or returning
by value certain aggregates containing zero width bit-fields has
been discovered on various targets. x86-64, ARM and AArch64
will always ignore them (so there is a C ABI incompatibility
between GCC 11 and earlier with GCC 12 or later), PowerPC64 ELFv2
always take them into account (so there is a C++ ABI
incompatibility, GCC 4.4 and earlier compatible with GCC 12 or
later, incompatible with GCC 4.5 through GCC 11). RISC-V has
changed the handling of these already starting with GCC 10. As
the ABI requires, MIPS takes them into account handling function
return values so there is a C++ ABI incompatibility with GCC 4.5
through 11.
- STABS: Support for emitting the STABS debugging format is
deprecated and will be removed in the next release. All ports now
default to emit DWARF (version 2 or later) debugging info or are
obsoleted.
- Vectorization is enabled at -O2 which is now equivalent to the
original -O2 -ftree-vectorize -fvect-cost-model=very-cheap.
- GCC now supports the ShadowCallStack sanitizer.
- Support for __builtin_shufflevector compatible with the clang
language extension was added.
- Support for attribute unavailable was added.
- Support for __builtin_dynamic_object_size compatible with the
clang language extension was added.
- New warnings:
-Wbidi-chars warns about potentially misleading UTF-8
bidirectional control characters.
-Warray-compare warns about comparisons between two operands of
array type.
- Some new features from the upcoming C2X revision of the ISO C
standard are supported with -std=c2x and -std=gnu2x.
- Several C++23 features have been implemented.
- Many C++ enhancements across warnings and -f options.
see https://gcc.gnu.org/gcc-12/changes.html for a full list.
@
text
@d138 1
a138 1
Two annotation macros are used to explain low-level synchronization
d160 2
a161 2
reference counting can be done by disabling extern templates (by defining
The Debug Mode
has compile and run-time checks for many containers.
d49 7
a55 10
There are also lightweight assertions for checking function preconditions,
such as checking for out-of-bounds indices when accessing a
The verbose
termination handler gives information about uncaught
exceptions which kill the program.
a58 5
The
d187 1
a187 1
Many options are available for GDB itself: please see
d228 7
a234 24
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 and perhaps
Both the normal build and the debug build will persist, without
having to specify
A second approach is to use the configuration flags
-fsanitize=address option.
mudflap (no longer supported since GCC 4.9.0), ElectricFence,
and the non-free commercial product purify.
In addition, libcwd, jemalloc and TCMalloc have replacements
for the global new and delete operators
that can track memory allocation and deallocation and provide useful
memory statistics.
d83 4
a86 2
versions should work better. Second, using an unoptimized build
might avoid confusing valgrind.
d88 2
a89 2
Third, it may be necessary to force deallocation in other libraries
as well, namely the "C" library. On GNU/Linux, this can be accomplished
d124 1
a124 23
std::allocator. Prior to GCC 3.4.0 the default was to use
a pooling allocator, pool_allocator,
which is still available as the optional
__pool_alloc extension.
Another optional extension, __mt_alloc,
is a high-performance pool allocator.
GLIBCXX_FORCE_NEW to keep extraneous pool allocation
noise from cluttering debug information.
For more details, see the
mt allocator
documentation and look specifically for GLIBCXX_FORCE_NEW.
mudflap, and the non-free commercial product
purify. In addition, libcwd has a
replacement for the global new and delete operators that can track
memory allocation and deallocation and provide useful memory
statistics.
new and delete: there are
different kinds of allocation schemes that can be used by
std::allocator. For implementation details, see the mt allocator documentation and
look specifically for GLIBCXX_FORCE_NEW.
mt_allocator
is a high-performance pool allocator, and can
give the mistaken impression that in a suspect executable, memory is
being leaked, when in reality the memory "leak" is a pool being used
by the library's allocator and is reclaimed after program
termination.
d73 2
a74 4
versions should work at least as well. Second of all, use a
completely unoptimized build to avoid confusing valgrind. Third, use
GLIBCXX_FORCE_NEW to keep extraneous pool allocation noise from
cluttering debug information.
d76 2
a77 2
Fourth, it may be necessary to force deallocation in other libraries
as well, namely the "C" library. On linux, this can be accomplished
d112 23
a134 1
-fsanitize=address option.
mudflap (no longer supported since GCC 4.9.0), ElectricFence,
and the non-free commercial product purify.
In addition, libcwd, jemalloc and TCMalloc have replacements
for the global new and delete operators
that can track memory allocation and deallocation and provide useful
memory statistics.
d83 4
a86 2
versions should work better. Second, using an unoptimized build
might avoid confusing valgrind.
d88 2
a89 2
Third, it may be necessary to force deallocation in other libraries
as well, namely the "C" library. On GNU/Linux, this can be accomplished
d124 1
a124 23
std::allocator. Prior to GCC 3.4.0 the default was to use
a pooling allocator, pool_allocator,
which is still available as the optional
__pool_alloc extension.
Another optional extension, __mt_alloc,
is a high-performance pool allocator.
GLIBCXX_FORCE_NEW to keep extraneous pool allocation
noise from cluttering debug information.
For more details, see the
mt allocator
documentation and look specifically for GLIBCXX_FORCE_NEW.
_GLIBCXX_EXTERN_TEMPLATE=-1) or by rebuilding the
d170 1
a170 1
d172 1
a172 1
d174 1
a174 1
@
1.1.1.11
log
@initial import of GCC 14.3.0.
major changes in GCC 13:
- improved sanitizer
- zstd debug info compression
- LTO improvements
- SARIF based diagnostic support
- new warnings: -Wxor-used-as-pow, -Wenum-int-mismatch, -Wself-move,
-Wdangling-reference
- many new -Wanalyzer* specific warnings
- enhanced warnings: -Wpessimizing-move, -Wredundant-move
- new attributes to mark file descriptors, c++23 "assume"
- several C23 features added
- several C++23 features added
- many new features for Arm, x86, RISC-V
major changes in GCC 14:
- more strict C99 or newer support
- ia64* marked deprecated (but seemingly still in GCC 15.)
- several new hardening features
- support for "hardbool", which can have user supplied values of true/false
- explicit support for stack scrubbing upon function exit
- better auto-vectorisation support
- added clang-compatible __has_feature and __has_extension
- more C23, including -std=c23
- several C++26 features added
- better diagnostics in C++ templates
- new warnings: -Wnrvo, Welaborated-enum-base
- many new features for Arm, x86, RISC-V
- possible ABI breaking change for SPARC64 and small structures with arrays
of floats.
@
text
@d15 1
a15 1
and include debugging information, so that stepping through all functions,
d33 15
a47 3
std::vector. These can be enabled without using
the full Debug Mode, by using -D_GLIBCXX_ASSERTIONS
(see Macros).
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).
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
--enable-libstdcxx-debug-flags='...'
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.
make CXXFLAGS='-g3 -fno-inline -O0' all