]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Make std::error_code printer more robust
authorJonathan Wakely <jwakely@redhat.com>
Thu, 17 Feb 2022 17:23:36 +0000 (17:23 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 4 Apr 2022 11:45:31 +0000 (12:45 +0100)
commitffd135934a4653e359642812c388ec4a64fdd624
tree95f1f65bf34f1948d4cdb95fa91a979058dd64ba
parent20f2303b0ce6bbe412e852e6423daabd04c39ebb
libstdc++: Make std::error_code printer more robust

This attempts to implement a partial workaround for the GDB bug
https://sourceware.org/bugzilla/show_bug.cgi?id=28856 which causes GDB
to crash when printing a frame with a std::error_code argument.

By recognising the known error categories defined in the library and
hardcoding their names we do not need to call cat->name() on the
category.  This has the additional benefit of also working when
debugging a core file rather than a running process. For those known
categories we can also cast the int value to the corresponding error
code enum (e.g. future_errc) so that we show an enumerator instead of
just an integer.

For program-defined categories we just use the name of the dynamic type
to identify the category, and print the value as an integer. Once the
GDB bug is fixed and the virtual name() function can be called safely,
that would be preferable. For now it's better to have an imperfect
printer that doesn't crash GDB.

This rewritten StdErrorCodePrinter needs gdb.Value.dynamic_type, so is
only registered if that is supported, which means GDB 7.7 and later.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdErrorCodePrinter): Replace
code that call cat->name() on std::error_category objects.
Identify known categories by symbol name and use a hardcoded
name. Print error code values as enumerators where appopriate.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Adjust expected
name of custom category. Check io_errc and future_errc errors.

(cherry picked from commit 36100e0e952b92a6cd819620fcef851f0069ac8f)
libstdc++-v3/python/libstdcxx/v6/printers.py
libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc