From patchwork Thu Jan 11 17:56:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1885760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IkzKnv9T; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9sqb6mQRz1yPf for ; Fri, 12 Jan 2024 04:59:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA3903861839 for ; Thu, 11 Jan 2024 17:59:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 19A343853328 for ; Thu, 11 Jan 2024 17:58:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19A343853328 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 19A343853328 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704995922; cv=none; b=ANH0pm7cLbMX1i+xL1SMTPsvyDNTjMz3SzM8Yz5satCfvb3FeXxMS+VsswxoNvstoH+/0lJP5ciu+M4vqlptA+3oLu/dHvTTZDEPEMLGvVYW6PlMPxcnK4dURLTekW42ghS1N0cFEXNNP5JdWviGfR0FjqmyoZH6Xb7QhTzQmgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704995922; c=relaxed/simple; bh=GRWZ8S+D0egvPksTTxzQZnGYHXY90QSzf+z/9/POKU0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JNxqEiMlUeFD6bjcIMuDvBW6p29EI0Xmh2xk0Aw9/hAit6u7k/GYkSVazkOXHvp3dKLnxEUa/J3epDlXaDaBON3i5dZ+Bw9n+jmP1S8RFWVoShAKS44Ms4etcTdpnMpxKPYH9tFlQAy+L75AzdU4WFJYYv5sHqY+90gokyFt+f0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704995920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hLQytPY7JFDlDptK9ywzPCQx4GJmGE7GwN7JnwshtW4=; b=IkzKnv9TEYs1+4WXn8Cxdr7CBrfMIY/oijz6J7pQVd2OhDZ8KqqmyH8NaPCrECLgoiZ2P7 7+Z+O2Kkca+mJ4h8zbRa2OBwDTdsa2LUKq64lc1JjHIrS8BlCqGbA+YiTLjhqhDTNyrtao DTFrJ19stz/8poCbnFoJPbTZBVaNpLA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-n3yq-YCfPl-vShaLlTpk8g-1; Thu, 11 Jan 2024 12:58:38 -0500 X-MC-Unique: n3yq-YCfPl-vShaLlTpk8g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A70F3C0F385; Thu, 11 Jan 2024 17:58:38 +0000 (UTC) Received: from localhost (unknown [10.42.28.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8F2F1C066AD; Thu, 11 Jan 2024 17:58:37 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add GDB printer for std::integral_constant Date: Thu, 11 Jan 2024 17:56:46 +0000 Message-ID: <20240111175837.420604-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org I was finding it frustrating when returning from a function in GDB and the return value was shown as $1 = { }, so this makes it print std::true_type or std::false_type. There are some contexts where the output isn't ideal, e.g. a type derived from std::true_type will now show something like: $2 = {{std::integral_constant = std::true_type}}; But I think in most contexts it's an improvement. Tested aarch64-linux, pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * python/libstdcxx/v6/printers.py (StdIntegralConstantPrinter): Add printer for std::integral_constant. * testsuite/libstdc++-prettyprinters/cxx11.cc: Test it. --- libstdc++-v3/python/libstdcxx/v6/printers.py | 20 +++++++++++++++++++ .../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);