[_GLIBCXX_DEBUG] Enhance rendering of assert message

François Dumont frs.dumont@gmail.com
Sat May 22 20:08:29 GMT 2021


Here is the part of the libbacktrace patch with the enhancement to the 
rendering of assert message.

It only contains one real fix, the rendering of address. In 2 places it 
was done with "0x%p", so resulting in something like: 0x0x012345678

Otherwise it is just enhancements, mostly avoiding intermediate buffering.

I am adding the _Parameter::_Named type to help on the rendering. I 
hesitated in doing the same for the _M_iterator type but eventually 
managed it with a template function.

     libstdc++: [_GLIBCXX_DEBUG] Enhance rendering of assert message

     Avoid building an intermediate buffer to print to stderr, push 
directly to stderr.

     libstdc++-v3/ChangeLog:

             * include/debug/formatter.h
             (_Error_formatter::_Parameter::_Named): New.
             (_Error_formatter::_Parameter::_Type): Inherit latter.
             (_Error_formatter::_Parameter::_M_integer): Likewise.
             (_Error_formatter::_Parameter::_M_string): Likewise.
             * src/c++11/debug.cc: Include <cstring>.
             (_Print_func_t): New.
             (print_raw(PrintContext&, const char*, ptrdiff_t)): New.
             (print_word): Use '%.*s' format in fprintf to render only 
expected number of chars.
             (pretty_print(PrintContext&, const char*, _Print_func_t)): New.
             (print_type): Rename in...
             (print_type_info): ...this. Use pretty_print.
             (print_address, print_integer): New.
             (print_named_name, print_iterator_constness, 
print_iterator_state): New.
             (print_iterator_seq_type): New.
             (print_named_field, print_type_field, print_instance_field, 
print_iterator_field): New.
             (print_field): Use latters.
             (print_quoted_named_name, print_type_type, print_type, 
print_instance): New.
             (print_string(PrintContext&, const char*, const 
_Parameter*, size_t)):
             Change signature to...
             (print_string(PrintContext&, const char*, ptrdiff_t, const 
_Parameter*, size_t)):
             ...this and adapt. Remove intermediate buffer to render 
input string.
             (print_string(PrintContext&, const char*, ptrdiff_t)): New.

Ok to commit ?

François

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


More information about the Libstdc++ mailing list