libbacktrace integration for _GLIBCXX_DEBUG mode

François Dumont frs.dumont@gmail.com
Thu Jun 6 20:33:00 GMT 2019


Here is what I come up with.


Regarding allocation in print_function I would also prefer to avoid it. 
But this patch also aim at creating a backtrace_state object in case of 
UB so the alloc is perhaps not so important. I can't use string_view as 
I need to modify it to display only a part of it through fsprintf. I 
could try to use "%.*s" however. I haven't also consider your remark 
about template parameters containing '<' yet.


>> +#if defined(_GLIBCXX_DEBUG_BACKTRACE)
>> +# if !defined(BACKTRACE_SUPPORTED)
>> +#  if defined(__has_include) && !__has_include(<backtrace-supported.h>)
>> +#   error No libbacktrace backtrace-supported.h file found.
>> +#  endif
>> +#  include <backtrace-supported.h>
>> +# endif
>> +# if !BACKTRACE_SUPPORTED
>> +#  error libbacktrace not supported.
>> +# endif
>> +# include <backtrace.h>
>> +#else
>> +# include <stdint.h> // For uintptr_t.
>
> Please use <cstdint> and std::uintptr_t.

I did so but then realized that to do so I had to be in C++11 mode. I 
used tr1/cstdint in pre-C++11 mode.

>
>> +// Extracted from libbacktrace.
>> +typedef void (*backtrace_error_callback) (void*, const char*, int);
>> +
>> +typedef int (*backtrace_full_callback) (void*, uintptr_t, const 
>> char*, int,
>> +                    const char*);
>
> These typedefs should use __reserved_names.
>
>> +struct backtrace_state;
>
> Although this one can't use a reserved name, unless we're going to
> create opaque wrappers around the libbacktrace type. Introducing t his
> non-reserved name means that defining _GLIBCXX_DEBUG makes the library
> non-conforming.
>
> It would be possible to avoid declaring this struct, by making
> _M_backtrace_state a void* and creating a wrapper function for
> backtrace_create_state, and a weak symbol in the library. I'll have to
> think about this more 

My main problem was to be able to respect the ODR even when 
!BACKTRACE_SUPPORTED. To do so I eventually realized that I had to limit 
the feature to system where uintptr_t is available which I detect thanks 
to the _GLIBCXX_USE_C99_STDINT_TR1 macro which is used both in <cstdint> 
and <tr1/cstdint>.

If you think it is fine I'll document it.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: debug_backtrace.patch
Type: text/x-patch
Size: 14112 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190606/f2d3bb7f/attachment.bin>


More information about the Libstdc++ mailing list