[PATCH] Add _GLIBCXX_DEBUG backtrace generation

François Dumont frs.dumont@gmail.com
Wed Aug 31 05:05:17 GMT 2022


After a second thought here is an even cleaner version. No more function 
rename, current pretty_print is fine.

     libstdc++: [_GLIBCXX_DEBUG] Add backtrace generation on demand

       Add _GLIBCXX_DEBUG_BACKTRACE macro to activate backtrace 
generation on
     _GLIBCXX_DEBUG assertions. Prerequisite is to have configure the 
lib with:

     --enable-libstdcxx-backtrace=yes

     libstdc++-v3/ChangeLog:

             * include/debug/formatter.h
             [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): Declare.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_create_state): Declare.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_callback): Define.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_error_callback): Define.
[_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_func): Define.
             [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full): Declare.
[_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_state): New.
[_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_full): New.
             * src/c++11/debug.cc 
[_GLIBCXX_HAVE_STACKTRACE](print_backtrace): New.
             (_Error_formatter::_M_error()): Adapt.
             * src/libbacktrace/Makefile.am: Add backtrace.c.
             * src/libbacktrace/Makefile.in: Regenerate.
             * src/libbacktrace/backtrace-rename.h (backtrace_full): New.
             * 
testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc: New test.
             * doc/xml/manual/debug_mode.xml: Document 
_GLIBCXX_DEBUG_BACKTRACE.
             * doc/xml/manual/using.xml: Likewise.
Ok to commit ?

François

On 09/08/22 10:07, François Dumont wrote:
> On 08/08/22 15:29, Jonathan Wakely wrote:
>> On Wed, 13 Jul 2022 at 18:28, François Dumont via Libstdc++
>> <libstdc++@gcc.gnu.org> wrote:
>>> libstdc++: [_GLIBCXX_DEBUG] Add backtrace generation on demand
>>>
>>>     Add _GLIBCXX_DEBUG_BACKTRACE macro to activate backtrace generation
>>> on _GLIBCXX_DEBUG assertions. Prerequisite is to have configure the lib
>>> with:
>>>
>>>     --enable-libstdcxx-backtrace=yes
>>>
>>>     libstdc++-v3/ChangeLog:
>>>
>>>     * include/debug/formatter.h
>>>     [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): Declare.
>>> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_create_state): Declare.
>>> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_callback): Define.
>>> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_error_callback): Define.
>>>     [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_func): Define.
>>>     [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full): Declare.
>>> [_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_state): New.
>>> [_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_full): New.
>>>     * src/c++11/debug.cc (pretty_print): Rename into...
>>>     (print_function): ...that.
>> This does more than just rename it, what are the other changes for?
>
> Nothing, I'm starting to remember what you did on this, reverted.
>
>
>>
>>
>>> [_GLIBCXX_HAVE_STACKTRACE](print_backtrace): New.
>>>     (_Error_formatter::_M_error()): Adapt.
>>>     * src/libbacktrace/Makefile.am: Add backtrace.c.
>>>     * src/libbacktrace/Makefile.in: Regenerate.
>>>     * src/libbacktrace/backtrace-rename.h (backtrace_full): New.
>>>     * testsuite/23_containers/vector/debug/assign4_neg.cc: Add 
>>> backtrace
>>>       generation.
>>>     * doc/xml/manual/debug_mode.xml: Document _GLIBCXX_DEBUG_BACKTRACE.
>>>     * doc/xml/manual/using.xml: Likewise.
>>>
>>> Tested under Linux x86_64 normal and _GLIBCXX_DEBUG modes.
>>>
>>> Ok to commit ?
>>
>>> --- a/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_neg.cc
>>> +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_neg.cc
>>> @@ -16,6 +16,7 @@
>>> // <http://www.gnu.org/licenses/>.
>>> //
>>> // { dg-do run { xfail *-*-* } }
>>> +// { dg-options "-D_GLIBCXX_DEBUG_BACKTRACE -lstdc++_libbacktrace" }
>>>
>>> #include <debug/vector>
>>> #include <debug/checks.h>
>> This will fail to link if the static lib isn't available.
>>
> Good point ! So I am introducing a new test case with the necessary dg 
> directive.
>
> It is a 'run' test case even if what is really tested is only the 
> compilation/link part. For the run part someone has to look at the log 
> file.
>
> François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: debug_backtrace.patch
Type: text/x-patch
Size: 10705 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20220831/b5056df8/attachment-0001.bin>


More information about the Libstdc++ mailing list