On 5/29/19 12:06 AM, Jonathan Wakely wrote:
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?

What I want to avoid is PR  saying that despite _GLIBCXX_DEBUG_BACKTRACE being defined there isn't any backtrace displayed in the assertion message.

Maybe I can still fail to compile if I can't include backtrace-supported.h to make clear that the -I... option is missing but ignore if !BACKTRACE_SUPPORTED. Would it be fine ?


    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.

Yes, I forgot to say that I made an effort to clean a little the demangle names but I think you saw it already.

I was surprised to see that the content of the __PRETTY_FUNCTION__ macro is quite different from the demangling of the same symbol, too bad.


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.


Ok, I'll consider your suggestions accordingly and complete this chapter.


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

Indeed, no ABI breaking change.


Reply via email to