[PATCH][_GLIBCXX_DEBUG] libbacktrace integration

François Dumont frs.dumont@gmail.com
Sat Apr 24 13:46:41 GMT 2021


     Here is the patch to add backtrace generation on _GLIBCXX_DEBUG 
assertions thanks to libbacktrace.

     In addition to this integration I am also improving the generation 
of the assertion message thanks to the "%.*s" printf format, it avoids 
an intermediate buffer most of the time. I am also removing the "__" 
used for uglification to get a nicer output. I can propose it in a 
dedicated patch if you prefer.

     I am adding GLIBCXX_3.4.30 abi version to properly export the 2 new 
weak symbols. Let me know if it isn't necessary.

     libstdc++: [_GLIBCXX_DEBUG] Add backtrace generation thanks to 

       Add _GLIBCXX_DEBUG_BACKTRACE macro to activate backtrace 
generation on
     _GLIBCXX_DEBUG assertions using libbacktrace.

             * config/abi/pre/gnu.ver: Add GLIBCXX_3.4.30 version and 
new exports.
             * include/debug/formatter.h [_GLIBCXX_DEBUG_BACKTRACE]:
             Include <backtrace-supported.h>.
             Include <backtrace.h>.
             _GLIBCXX_USE_C99_STDINT_TR1]: Include <stdint.h>.
             (__gnu_debug::__create_backtrace_state): New.
             (__gnu_debug::__render_backtrace): New.
             (_Error_formatter::_Error_formatter): Outline definition.
             * src/c++11/debug.cc: Include <cstring>.
             (_Print_func_t): New.
             (print_word): Use '%.*s' format in fprintf to render only 
             number of chars.
             (print_raw(PrintContext&, const char*, ptrdiff_t)): New.
             (print_function(PrintContext&, const char*, 
_Print_func_t)): New.
             (print_type): Use latter.
             (print_string(PrintContext&, const char*, const 
_Parameter*, size_t)):
             Change signature to...
             (print_string(PrintContext&, const char*, ptrdiff_t, const 
             size_t)): ...this and adapt. Remove intermediate buffer to 
render input
             (print_string(PrintContext&, const char*, ptrdiff_t)): New.
             (print_backtrace(void*, uintptr_t, const char*, int, const 
char*)): New.
             (_Error_formatter::_M_error()): Adapt.
             (__gnu_debug::__create_backtrace_state): New, weak symbol.
             (__gnu_debug::__render_backtrace): New, weak symbol.
             * testsuite/util/testsuite_abi.cc: Add new symbol version.
             * doc/xml/manual/debug_mode.xml: Document 
             * doc/xml/manual/using.xml: Likewise.

Tested under Linux x86_64.

Ok to commit ?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: libbacktrace.patch
Type: text/x-patch
Size: 17131 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210424/d86f5dca/attachment.bin>

More information about the Libstdc++ mailing list