From: Jonathan Wakely Date: Thu, 7 Mar 2024 15:19:12 +0000 (+0000) Subject: libstdc++: Improve documentation on debugging with libstdc++ X-Git-Tag: basepoints/gcc-15~683 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45a3ee8a402cc51c02b7f45e8f041039390a4ef8;p=thirdparty%2Fgcc.git libstdc++: Improve documentation on debugging with libstdc++ libstdc++-v3/ChangeLog: * doc/xml/manual/debug.xml: Improve docs on debug builds and using ASan. Mention _GLIBCXX_ASSERTIONS. Reorder sections to put the most relevant ones first. * doc/xml/manual/using.xml: Add comma. * doc/html/*: Regenerate. --- diff --git a/libstdc++-v3/doc/html/index.html b/libstdc++-v3/doc/html/index.html index 8648d8e2bea6..f9288e471f48 100644 --- a/libstdc++-v3/doc/html/index.html +++ b/libstdc++-v3/doc/html/index.html @@ -23,7 +23,7 @@


Table of Contents

The GNU C++ Library Manual
I. Introduction -
1. Status
Implementation Status
C++ 1998/2003
Implementation Status
Implementation Specific Behavior
C++ 2011
Implementation Specific Behavior
C++ 2014
Implementation Specific Behavior
Filesystem TS
C++ 2017
Implementation Specific Behavior
Parallelism 2 TS
C++ 2020
C++ 2023
C++ TR1
Implementation Specific Behavior
C++ TR 24733
C++ IS 29124
Implementation Specific Behavior
License
The Code: GPL
The Documentation: GPL, FDL
Bugs
Implementation Bugs
Standard Bugs
2. Setup
Prerequisites
Configure
Make
3. Using
Command Options
Headers
Header Files
Mixing Headers
The C Headers and namespace std
Precompiled Headers
Macros
Dual ABI
Troubleshooting
Namespaces
Available Namespaces
namespace std
Using Namespace Composition
Linking
Almost Nothing
Finding Dynamic or Shared Libraries
Experimental Library Extensions
Concurrency
Prerequisites
Thread Safety
Atomics
IO
Structure
Defaults
Future
Alternatives
Containers
Exceptions
Exception Safety
Exception Neutrality
Memory allocation
Doing without
Compatibility
With C
With POSIX thread cancellation
Debugging Support
Using g++
Debug Versions of Library Binary Files
Memory Leak Hunting
Non-memory leaks in Pool and MT allocators
Data Race Hunting
Using gdb
Tracking uncaught exceptions
Debug Mode
Compile Time Checking
II. +
1. Status
Implementation Status
C++ 1998/2003
Implementation Status
Implementation Specific Behavior
C++ 2011
Implementation Specific Behavior
C++ 2014
Implementation Specific Behavior
Filesystem TS
C++ 2017
Implementation Specific Behavior
Parallelism 2 TS
C++ 2020
C++ 2023
C++ TR1
Implementation Specific Behavior
C++ TR 24733
C++ IS 29124
Implementation Specific Behavior
License
The Code: GPL
The Documentation: GPL, FDL
Bugs
Implementation Bugs
Standard Bugs
2. Setup
Prerequisites
Configure
Make
3. Using
Command Options
Headers
Header Files
Mixing Headers
The C Headers and namespace std
Precompiled Headers
Macros
Dual ABI
Troubleshooting
Namespaces
Available Namespaces
namespace std
Using Namespace Composition
Linking
Almost Nothing
Finding Dynamic or Shared Libraries
Experimental Library Extensions
Concurrency
Prerequisites
Thread Safety
Atomics
IO
Structure
Defaults
Future
Alternatives
Containers
Exceptions
Exception Safety
Exception Neutrality
Memory allocation
Doing without
Compatibility
With C
With POSIX thread cancellation
Debugging Support
Using g++
Debug Mode
Tracking uncaught exceptions
Memory Leak Hunting
Non-memory leaks in Pool and MT allocators
Data Race Hunting
Using gdb
Debug Versions of Library Binary Files
Compile Time Checking
II. Standard Contents
4. Support diff --git a/libstdc++-v3/doc/html/manual/debug.html b/libstdc++-v3/doc/html/manual/debug.html index 34ec6598ce46..eb83d4e15ac9 100644 --- a/libstdc++-v3/doc/html/manual/debug.html +++ b/libstdc++-v3/doc/html/manual/debug.html @@ -12,7 +12,7 @@ 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, + 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. -

Debug Versions of Library Binary Files

- 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. +

Debug Mode

+ 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.

Memory Leak Hunting

+ 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). +

Tracking uncaught exceptions

+ The verbose + termination handler gives information about uncaught + exceptions which kill the program. +

Memory Leak Hunting

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" . -

Tracking uncaught exceptions

- The verbose - termination handler gives information about uncaught - exceptions which kill the program. -

Debug Mode

The Debug Mode - has compile and run-time checks for many containers. -

Compile Time Checking

The Compile-Time +

Debug Versions of Library Binary Files

+ 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
+

Compile Time Checking

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.

\ No newline at end of file diff --git a/libstdc++-v3/doc/html/manual/ext_compile_checks.html b/libstdc++-v3/doc/html/manual/ext_compile_checks.html index c60b03381ba0..240d4e47f666 100644 --- a/libstdc++-v3/doc/html/manual/ext_compile_checks.html +++ b/libstdc++-v3/doc/html/manual/ext_compile_checks.html @@ -24,8 +24,7 @@

The new version imposes a much smaller space overhead on the generated object file. The checks are also cleaner and easier to read and understand. -

They are off by default for all versions of GCC from 3.0 to 3.4 (the - latest release at the time of writing). +

They are off by default for all GCC 3.0 and all later versions. They can be enabled at configure time with --enable-concept-checks. You can enable them on a per-translation-unit basis with @@ -34,8 +33,15 @@ (or with #define _GLIBCPP_CONCEPT_CHECKS for versions 3.1, 3.2 and 3.3).

Please note that the concept checks only validate the requirements - of the old C++03 standard. C++11 was expected to have first-class - support for template parameter constraints based on concepts in the core - language. This would have obviated the need for the library-simulated concept - checking described above, but was not part of C++11. + of the old C++03 standard and reject some valid code that meets the relaxed + requirements of C++11 and later standards. + C++11 was expected to have first-class support for template parameter + constraints based on concepts in the core language. + This would have obviated the need for the library-simulated concept checking + described above, but was not part of C++11. + C++20 adds a different model of concepts, which is now used to constrain + some new parts of the C++20 library, e.g. the + <ranges> header and the new overloads in the + <algorithm> header for working with ranges. + The old library-simulated concept checks might be removed at a future date.

\ No newline at end of file diff --git a/libstdc++-v3/doc/html/manual/index.html b/libstdc++-v3/doc/html/manual/index.html index ef58061c5cf0..ed2aee54cead 100644 --- a/libstdc++-v3/doc/html/manual/index.html +++ b/libstdc++-v3/doc/html/manual/index.html @@ -4,7 +4,7 @@


Table of Contents

I. Introduction -
1. Status
Implementation Status
C++ 1998/2003
Implementation Status
Implementation Specific Behavior
C++ 2011
Implementation Specific Behavior
C++ 2014
Implementation Specific Behavior
Filesystem TS
C++ 2017
Implementation Specific Behavior
Parallelism 2 TS
C++ 2020
C++ 2023
C++ TR1
Implementation Specific Behavior
C++ TR 24733
C++ IS 29124
Implementation Specific Behavior
License
The Code: GPL
The Documentation: GPL, FDL
Bugs
Implementation Bugs
Standard Bugs
2. Setup
Prerequisites
Configure
Make
3. Using
Command Options
Headers
Header Files
Mixing Headers
The C Headers and namespace std
Precompiled Headers
Macros
Dual ABI
Troubleshooting
Namespaces
Available Namespaces
namespace std
Using Namespace Composition
Linking
Almost Nothing
Finding Dynamic or Shared Libraries
Experimental Library Extensions
Concurrency
Prerequisites
Thread Safety
Atomics
IO
Structure
Defaults
Future
Alternatives
Containers
Exceptions
Exception Safety
Exception Neutrality
Memory allocation
Doing without
Compatibility
With C
With POSIX thread cancellation
Debugging Support
Using g++
Debug Versions of Library Binary Files
Memory Leak Hunting
Non-memory leaks in Pool and MT allocators
Data Race Hunting
Using gdb
Tracking uncaught exceptions
Debug Mode
Compile Time Checking
II. +
1. Status
Implementation Status
C++ 1998/2003
Implementation Status
Implementation Specific Behavior
C++ 2011
Implementation Specific Behavior
C++ 2014
Implementation Specific Behavior
Filesystem TS
C++ 2017
Implementation Specific Behavior
Parallelism 2 TS
C++ 2020
C++ 2023
C++ TR1
Implementation Specific Behavior
C++ TR 24733
C++ IS 29124
Implementation Specific Behavior
License
The Code: GPL
The Documentation: GPL, FDL
Bugs
Implementation Bugs
Standard Bugs
2. Setup
Prerequisites
Configure
Make
3. Using
Command Options
Headers
Header Files
Mixing Headers
The C Headers and namespace std
Precompiled Headers
Macros
Dual ABI
Troubleshooting
Namespaces
Available Namespaces
namespace std
Using Namespace Composition
Linking
Almost Nothing
Finding Dynamic or Shared Libraries
Experimental Library Extensions
Concurrency
Prerequisites
Thread Safety
Atomics
IO
Structure
Defaults
Future
Alternatives
Containers
Exceptions
Exception Safety
Exception Neutrality
Memory allocation
Doing without
Compatibility
With C
With POSIX thread cancellation
Debugging Support
Using g++
Debug Mode
Tracking uncaught exceptions
Memory Leak Hunting
Non-memory leaks in Pool and MT allocators
Data Race Hunting
Using gdb
Debug Versions of Library Binary Files
Compile Time Checking
II. Standard Contents
4. Support diff --git a/libstdc++-v3/doc/html/manual/intro.html b/libstdc++-v3/doc/html/manual/intro.html index 3027cb6f3f73..5bb4814d5022 100644 --- a/libstdc++-v3/doc/html/manual/intro.html +++ b/libstdc++-v3/doc/html/manual/intro.html @@ -5,4 +5,4 @@ Prev The GNU C++ Library Manual Next

Part I.  Introduction -

\ No newline at end of file +

Table of Contents

1. Status
Implementation Status
C++ 1998/2003
Implementation Status
Implementation Specific Behavior
C++ 2011
Implementation Specific Behavior
C++ 2014
Implementation Specific Behavior
Filesystem TS
C++ 2017
Implementation Specific Behavior
Parallelism 2 TS
C++ 2020
C++ 2023
C++ TR1
Implementation Specific Behavior
C++ TR 24733
C++ IS 29124
Implementation Specific Behavior
License
The Code: GPL
The Documentation: GPL, FDL
Bugs
Implementation Bugs
Standard Bugs
2. Setup
Prerequisites
Configure
Make
3. Using
Command Options
Headers
Header Files
Mixing Headers
The C Headers and namespace std
Precompiled Headers
Macros
Dual ABI
Troubleshooting
Namespaces
Available Namespaces
namespace std
Using Namespace Composition
Linking
Almost Nothing
Finding Dynamic or Shared Libraries
Experimental Library Extensions
Concurrency
Prerequisites
Thread Safety
Atomics
IO
Structure
Defaults
Future
Alternatives
Containers
Exceptions
Exception Safety
Exception Neutrality
Memory allocation
Doing without
Compatibility
With C
With POSIX thread cancellation
Debugging Support
Using g++
Debug Mode
Tracking uncaught exceptions
Memory Leak Hunting
Non-memory leaks in Pool and MT allocators
Data Race Hunting
Using gdb
Debug Versions of Library Binary Files
Compile Time Checking
\ No newline at end of file diff --git a/libstdc++-v3/doc/html/manual/using.html b/libstdc++-v3/doc/html/manual/using.html index e8e0c6c0e859..d663660b3a4f 100644 --- a/libstdc++-v3/doc/html/manual/using.html +++ b/libstdc++-v3/doc/html/manual/using.html @@ -2,7 +2,7 @@ Chapter 3. Using

Chapter 3. Using

Command Options

+ Next


Chapter 3. Using

Command Options

The set of features available in the GNU C++ library is shaped by several GCC Command Options. Options that impact libstdc++ are diff --git a/libstdc++-v3/doc/html/manual/using_macros.html b/libstdc++-v3/doc/html/manual/using_macros.html index 62c66b7de4c2..ae5646926307 100644 --- a/libstdc++-v3/doc/html/manual/using_macros.html +++ b/libstdc++-v3/doc/html/manual/using_macros.html @@ -123,5 +123,5 @@ or malloc_allocator. The annotations must be present on all vector operations or none, so this macro must be defined to the same value for all translation units that create, - destroy or modify vectors. + destroy, or modify vectors.

\ No newline at end of file diff --git a/libstdc++-v3/doc/xml/manual/debug.xml b/libstdc++-v3/doc/xml/manual/debug.xml index 7f6d0876fc61..23dbae5e5213 100644 --- a/libstdc++-v3/doc/xml/manual/debug.xml +++ b/libstdc++-v3/doc/xml/manual/debug.xml @@ -30,7 +30,7 @@ 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, + 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, @@ -55,41 +55,30 @@ -
Debug Versions of Library Binary Files - +
Debug Mode - 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 + 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 + (see ). - - make CXXFLAGS='-g3 -fno-inline -O0' all - + +
+ +
Tracking uncaught exceptions - 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 verbose + termination handler gives information about uncaught + exceptions which kill the program. +
Memory Leak Hunting @@ -99,6 +88,13 @@ which is enabled by the option. + + The std::vector implementation has additional + instrumentation to work with AddressSanitizer, but this has to be enabled + explicitly by using + (see ). + + There are also various third party memory tracing and debug utilities that can be used to provide detailed memory allocation information @@ -331,22 +327,45 @@
-
Tracking uncaught exceptions +
Debug Versions of Library Binary Files - The verbose - termination handler gives information about uncaught - exceptions which kill the program. + 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. -
-
Debug Mode + + 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 Debug Mode - has compile and run-time checks for many containers. -
+
Compile Time Checking The Compile-Time diff --git a/libstdc++-v3/doc/xml/manual/using.xml b/libstdc++-v3/doc/xml/manual/using.xml index b3b0c368e444..8ac7e74034c4 100644 --- a/libstdc++-v3/doc/xml/manual/using.xml +++ b/libstdc++-v3/doc/xml/manual/using.xml @@ -1341,7 +1341,7 @@ g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 hello.cc -o test.exe or malloc_allocator. The annotations must be present on all vector operations or none, so this macro must be defined to the same value for all translation units that create, - destroy or modify vectors. + destroy, or modify vectors.