Software: Apache/2.0.54 (Fedora). PHP/5.0.4 uname -a: Linux mina-info.me 2.6.17-1.2142_FC4smp #1 SMP Tue Jul 11 22:57:02 EDT 2006 i686 uid=48(apache) gid=48(apache) groups=48(apache) Safe-mode: OFF (not secure) /usr/share/doc/libstdc++-devel-4.0.2/html/ drwxr-xr-x |
Viewing file: Select action/file-type: Debugging schemes and strategiesThe latest version of this document is always available at http://gcc.gnu.org/onlinedocs/libstdc++/debug.html. To the libstdc++-v3 homepage. 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 debug infoThe default optimizations and debug flags for a libstdc++ build are
Or, the debug format that the compiler and debugger use to communicate
information about source constructs can be changed via Many other options are available: please see "Options for Debugging Your Program" in Using the GNU Compiler Collection (GCC) for a complete list. Using special flags to make a debug binaryIf 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
A second approach is to use the configuration flags make CXXFLAGS='-g3 -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. The libstdc++ debug modeBy 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 means that programs that incorrectly use the C++ standard library will exhibit behavior that is not portable and may not even be predictable, because they tread into implementation-specific or undefined behavior. To detect some of these errors before they can become problematic, libstdc++ offers a debug mode that provides additional checking of library facilities, and will report errors in the use of libstdc++ as soon as they can be detected by emitting a description of the problem to standard error and aborting the program. This debug mode is available with GCC 3.4.0 and later versions. The libstdc++ debug mode performs checking for many areas of the C++ standard, but the focus is on checking interactions among standard iterators, containers, and algorithms, including:
Using the libstdc++ debug modeTo use the libstdc++ debug mode, compile your application with the
compiler flag For information about the design of the libstdc++ debug mode, please see the libstdc++ debug mode design document. Using the debugging containers without debug modeWhen 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:
Debug mode semanticsA program that uses the C++ standard library correctly
will maintain the same semantics under debug mode as it had with
the normal (release) library. All functional and exception-handling
guarantees made by the normal library also hold for the debug mode
library, with one exception: performance guarantees made by the
normal library may not hold in the debug mode library. For
instance, erasing an element in a libstdc++ includes many extensions to the C++ standard library. In
some cases the extensions are obvious, such as the hashed
associative containers, whereas other extensions give predictable
results to behavior that would otherwise be undefined, such as
throwing an exception when a The following library components provide extra debugging capabilities in debug mode:
Tips for memory leak huntingThere 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 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 default allocator used by 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
#include <cstdlib> extern "C" void __libc_freeres(void); void do_something() { } int main() { atexit(__libc_freeres); do_something(); return 0; } or, using 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 Some gdb strategiesMany 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 Tracking uncaught exceptionsThe 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. See license.html for copying conditions. Comments and suggestions are welcome, and may be sent to the libstdc++ mailing list. |
:: Command execute :: | |
--[ c99shell v. 1.0 pre-release build #16 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0027 ]-- |