From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 3B0913858005; Thu, 11 Jan 2024 17:56:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B0913858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704995806; bh=xfIZgwjp1PTfMFVZtysf/ncTPoTkWqbAvTkzX4WT+gw=; h=From:To:Subject:Date:From; b=a5Xpg6uwYaXH+5RXe9vyH0Sdwjrx6RKolIwIe78ixW0bOEZdpveAR60ddnJ4bvgFC jR0JVpw/03X+RcaZdWKIs37uWcnT6HuQgwa5VK5Y3WOKUcOREn+jUM1bkRKrjezrw6 TWYIkvw+5zI9pSWBv2w5XKa3GziKK4fUpKONBbQo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-7147] libstdc++: Add GDB printer for std::integral_constant X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: f50f2efae9fb0965d8ccdb62cfdb698336d5a933 X-Git-Newrev: cd2022f39297198adad0e284f8780cb3d83d0f85 Message-Id: <20240111175646.3B0913858005@sourceware.org> Date: Thu, 11 Jan 2024 17:56:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cd2022f39297198adad0e284f8780cb3d83d0f85 commit r14-7147-gcd2022f39297198adad0e284f8780cb3d83d0f85 Author: Jonathan Wakely Date: Wed Jan 10 10:53:43 2024 +0000 libstdc++: Add GDB printer for std::integral_constant libstdc++-v3/ChangeLog: * python/libstdcxx/v6/printers.py (StdIntegralConstantPrinter): Add printer for std::integral_constant. * testsuite/libstdc++-prettyprinters/cxx11.cc: Test it. Diff: --- libstdc++-v3/python/libstdcxx/v6/printers.py | 20 ++++++++++++++++++++ .../testsuite/libstdc++-prettyprinters/cxx11.cc | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index bf0dc52ab8c..032a7aa58a2 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -2306,6 +2306,23 @@ class StdLocalePrinter(printer_base): mod = ' with "{}={}"'.format(cat, other) return 'std::locale = "{}"{}'.format(name, mod) +class StdIntegralConstantPrinter(printer_base): + """Print a std::true_type or std::false_type.""" + + def __init__(self, typename, val): + self._val = val + self._typename = typename + + def to_string(self): + value_type = self._val.type.template_argument(0) + value = self._val.type.template_argument(1) + if value_type.code == gdb.TYPE_CODE_BOOL: + if value: + return "std::true_type" + else: + return "std::false_type" + typename = strip_versioned_namespace(self._typename) + return "{}<{}, {}>".format(typename, value_type, value) # A "regular expression" printer which conforms to the # "SubPrettyPrinter" protocol from gdb.printing. @@ -2788,6 +2805,9 @@ def build_libstdcxx_dictionary(): # vector libstdcxx_printer.add_version('std::', 'locale', StdLocalePrinter) + libstdcxx_printer.add_version('std::', 'integral_constant', + StdIntegralConstantPrinter) + if hasattr(gdb.Value, 'dynamic_type'): libstdcxx_printer.add_version('std::', 'error_code', StdErrorCodePrinter) diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc index bc869fd4122..f867ea18306 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc @@ -207,6 +207,13 @@ main() std::atomic av{{8, 9}}; // { dg-final { note-test av {std::atomic = { {i = 8, j = 9} }} } } + std::integral_constant one; + // { dg-final { note-test one {std::integral_constant} } } + std::integral_constant truth; + // { dg-final { note-test truth {std::true_type} } } + std::integral_constant lies; + // { dg-final { note-test lies {std::false_type} } } + placeholder(""); // Mark SPOT use(efl); use(fl);