From 3642a94924510f7e7220aea6aefebc7372d59d8b Mon Sep 17 00:00:00 2001
From: Phil Edwards For each entry, we give the section number of the standard, when
applicable. This list is probably incomplet and inkorrekt.
[1.9]/11 #3 If [17.4.4.5] Non-reentrant functions are probably best
discussed in the various sections on multithreading (see above).
The 'Aborted' line comes from the call to abort(), of course.
UPDATE: Starting with GCC 3.4, this is the default
+ termination handler; nothing need be done to use it. To go back to
+ the previous "silent death" method, simply include
+ Return to top of page or
to the FAQ.
- There are numerous things that can be done to improve the ease with
+ There are numerous things that can be done to improve the ease with
which C++ binaries are debugged when using the GNU C++
tool chain. Here are some things to keep in mind when debugging C++
code with GNU tools.
- The default optimizations and debug flags for a libstdc++ build are
+ The default optimizations and debug flags for a libstdc++ build are
- Many other options are available: please see
+ Many other options are available: please see
"Options for Debugging Your Program"
in Using the GNU Compiler Collection (GCC) for a complete list.
- There are two ways to build libstdc++ with debug flags. The first
+ 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
specialized debug isatty(3)
is true, then
+ interactive stream support is implied.
+ <exception>
and
<cstdlib>
, and call
+
+ std::set_terminate (std::abort);
-Compiler flags determine debug info
--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
flag will
@@ -53,53 +51,45 @@
in the gcc sources.
Using special flags to make a debug binary
-CXXFLAGS
, as in make
CXXFLAGS='-g3 -O0' all
- This quick and dirty approach is often sufficient for quick +
This quick and dirty approach is often sufficient for quick debugging tasks, but the lack of state can be confusing in the long term.
-- A second approach is to use the configuration flags +
A second approach is to use the configuration flags
---enable-debug
--enable-debug
- and perhaps -
+and perhaps
---enable-debug-flags
--enable-debug-flags='...'
- to create a separate debug build. Both the normal build and the +
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 options document
- here
+here
- There are various third party memory tracing and debug utilities +
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 include mtrace
, valgrind
,
@@ -108,8 +98,7 @@
forget right now.
- Regardless of the memory debugging tool being used, there is one +
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
@@ -118,14 +107,13 @@
document and look specifically for GLIBCPP_FORCE_NEW
.
- In a nutshell, the default allocator used by In a nutshell, the default allocator used by For valgrind, there are some specific items to keep in mind. First
+ 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
@@ -134,15 +122,14 @@
cluttering debug information.
- Fourth, it may be necessary to force deallocation in other
+ 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
- or, using or, using
- Suggested valgrind flags, given the suggestions above about setting
+ Suggested valgrind flags, given the suggestions above about setting
up the runtime environment, library, and test file, might be:
- 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
+ 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:
The verbose termination handler
+ gives information about uncaught exceptions which are killing the
+ program. It is described in the linked-to page.
+ Return to the top of the page or
to the libstdc++ homepage.
+
std::allocator
is a high-performance pool allocator, and can
give the mistaken impression that memory is being leaked, when in
reality the memory is reclaimed after program termination.
__cxa_atexit
or atexit
functions.
- #include
-__cxa_atexit
:
-__cxa_atexit
:
extern "C" void __libc_freeres(void);
@@ -171,14 +156,13 @@
{
extern void* __dso_handle __attribute__ ((__weak__));
__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
- &__dso_handle ? __dso_handle : NULL);
+ &__dso_handle ? __dso_handle : NULL);
do_test();
return 0;
}
-valgrind -v --num-callers=20 --leak-check=yes
@@ -187,14 +171,13 @@
Some gdb strategies
-Tracking uncaught exceptions
+
diff --git a/libstdc++-v3/libsupc++/eh_term_handler.cc b/libstdc++-v3/libsupc++/eh_term_handler.cc
index ff7b7edd957..df2ccf989fd 100644
--- a/libstdc++-v3/libsupc++/eh_term_handler.cc
+++ b/libstdc++-v3/libsupc++/eh_term_handler.cc
@@ -29,6 +29,12 @@
#include "unwind-cxx.h"
+/* We default to the talkative, informative handler. This pulls in the
+ demangler, the dyn-string utilities, and elements of the I/O library.
+ For a low-memory environment, you can return to the earlier "silent death"
+ handler by including