libbacktrace integration for _GLIBCXX_DEBUG mode
Jonathan Wakely
jwakely@redhat.com
Tue May 28 22:06:00 GMT 2019
On 23/05/19 07:39 +0200, François Dumont wrote:
>Hi
>
>Â Â Â So here what I come up with.
>
>Â Â Â _GLIBCXX_DEBUG_BACKTRACE controls the feature. If the user define
Thanks for making this opt-in.
>it and there is a detectable issue with libbacktrace then I generate a
>compilation error. I want to avoid users defining it but having no
>backtrace in the end in the debug assertion.
Why do you want to avoid that?
This means users can't just define the macro in their makefiles
unconditionally, they have to check if libbacktrace is installed and
supported. That might mean having platform-specific conditionals in
the makefile to only enable it sometimes.
What harm does it do to just ignore the _GLIBCXX_DEBUG_BACKTRACE macro
if backtraces can't be enabled? Or just use #warning instead of
#error?
>Â Â Â With this new setup I manage to run testsuite with it like that:
>
>export LD_LIBRARY_PATH=/home/fdt/dev/gcc/install/lib/
>make CXXFLAGS='-D_GLIBCXX_DEBUG_BACKTRACE
>-I/home/fdt/dev/gcc/install/include -lbacktrace' check-debug
>
>Â Â Â An example of result:
>
>/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/vector:606:
>In function:
>Â Â Â std::__debug::vector<_Tp, _Allocator>::iterator
>Â Â Â std::__debug::vector<_Tp,
>_Allocator>::insert(std::__debug::vector<_Tp,
>Â Â Â _Allocator>::const_iterator, _InputIterator, _InputIterator) [with
>Â Â Â _InputIterator = int*; <template-parameter-2-2> = void; _Tp = int;
>Â Â Â _Allocator = std::allocator<int>; std::__debug::vector<_Tp,
>Â Â Â _Allocator>::iterator =
>__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<int*, std::
>Â Â Â vector<int> >, std::__debug::vector<int>,
>Â Â Â std::random_access_iterator_tag>; typename
>std::iterator_traits<typename
>Â Â Â std::vector<_Tp, _Alloc>::iterator>::iterator_category =
>Â Â Â std::random_access_iterator_tag; typename std::vector<_Tp,
>Â Â Â _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*,
>std::vector<int>
>Â Â Â >; std::__debug::vector<_Tp, _Allocator>::const_iterator =
>__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<const int*,
>Â Â Â std::vector<int> >, std::__debug::vector<int>,
>Â Â Â std::random_access_iterator_tag>; typename
>std::iterator_traits<typename
>Â Â Â std::vector<_Tp, _Alloc>::const_iterator>::iterator_category =
>Â Â Â std::random_access_iterator_tag; typename std::vector<_Tp,
>Â Â Â _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const int*,
>std::
>Â Â Â vector<int> >]
>
>Backtrace:
>Â Â Â 0x402718
>__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<int*,
>std::vector<int> >> std::__debug::vector<int>::insert<int*,
>void>(__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<int
>const*, std::vector<int> >>, int*, int*)
>/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/vector:606
>Â Â Â 0x402718 test01()
>/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/23_containers/vector/debug/57779_neg.cc:29
>Â Â Â 0x401428 main
>/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/23_containers/vector/debug/57779_neg.cc:34
>
>Error: attempt to insert with an iterator range [__first, __last) from this
>container.
>
>Objects involved in the operation:
>Â Â Â iterator "__first" @ 0x0x7fff730b96b0 {
>Â Â Â Â Â type = int* (mutable iterator);
>Â Â Â }
>Â Â Â iterator "__last" @ 0x0x7fff730b96b8 {
>Â Â Â Â Â type = int* (mutable iterator);
>Â Â Â }
>Â Â Â sequence "this" @ 0x0x7fff730b9720 {
>Â Â Â Â Â type = std::__debug::vector<int>;
>Â Â Â }
This is nice.
>diff --git a/libstdc++-v3/doc/xml/manual/debug_mode.xml b/libstdc++-v3/doc/xml/manual/debug_mode.xml
>index 570c17ba28a..27873151dae 100644
>--- a/libstdc++-v3/doc/xml/manual/debug_mode.xml
>+++ b/libstdc++-v3/doc/xml/manual/debug_mode.xml
>@@ -104,9 +104,11 @@
> <para>The following library components provide extra debugging
> capabilities in debug mode:</para>
> <itemizedlist>
>+ <listitem><para><code>std::array</code> (no safe iterators)</para></listitem>
> <listitem><para><code>std::basic_string</code> (no safe iterators and see note below)</para></listitem>
> <listitem><para><code>std::bitset</code></para></listitem>
> <listitem><para><code>std::deque</code></para></listitem>
>+ <listitem><para><code>std::forward_list</code></para></listitem>
> <listitem><para><code>std::list</code></para></listitem>
> <listitem><para><code>std::map</code></para></listitem>
> <listitem><para><code>std::multimap</code></para></listitem>
>@@ -160,6 +162,13 @@ which always works correctly.
> <code>GLIBCXX_DEBUG_MESSAGE_LENGTH</code> can be used to request a
> different length.</para>
>
>+<para>Starting with GCC 10 libstdc++ has integrated
I think "integrated" is the wrong word, because you haven't made
libbacktrace and libstdc++ into a single thing. You've just added the
ability for libstdc++ to use libbacktrace.
I suggest "libstdc++ is able to use"
>+ <link xmlns:xlink="http://www.w3.org/1999/xlink"
>+ xlink:href="https://github.com/ianlancetaylor/libbacktrace">libbacktrace</link>
>+ to produce backtrace on error. Use <code>-D_GLIBCXX_DEBUG_BACKTRACE</code> to
Should be "produce backtraces".
>+ activate it. Note that if not properly installed or if libbacktrace is not
>+ supported compilation will fail. You'll also have to use the
Comma after "supported". Remove "the" at the end of the line.
>+ <code>-lbacktrace</code> to build your application.</para>
> </section>
The new _GLIBCXX_DEBUG_BACKTRACE macro should be documented in
doc/xml/manual/using.xml too. I think we also have a table in that
chapter which lists relevant GCC options, so -lbacktrace could go in
there too.
Enabling backtrace support doesn't alter the ABI of the debug mode
containers, right? It only affects the size of the _Error_formatter
type, which is not a member of any container or iterator.
More information about the Libstdc++
mailing list