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: 187471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1655283dyi; Thu, 11 Jan 2024 10:58:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeoJxyS4uaaLp8oF33QN6S0WEnQynkJ8H2OPsOXnkXl6ZNRPzjfZB9FPd77fFjSNlQR/jR X-Received: by 2002:a05:620a:438f:b0:783:2970:97d1 with SMTP id a15-20020a05620a438f00b00783297097d1mr389058qkp.32.1704999527067; Thu, 11 Jan 2024 10:58:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704999527; cv=pass; d=google.com; s=arc-20160816; b=CQ5Z+z3eJAi6jt/x4Rw+LC4/f0Bn9sjJDAJoOH3nnhzqyNeMq6E5yd9a5R005zlojp /q0Wey8kRfyc7WhoiR+5BCHrnFmUmpsX6o3FbhZ83SCNXDg3rL/+JDsJVbMNjvWTTP39 RgICxWPhCg5zM6kkgoVi1G+FBLJ45NJnHUI5Su4BJWjRvQUwY/jZw35tSyi8lH+aJzNw dEuTtw83mzkwrD4aUIdQOJFe6stltT2MBC+kqrW6GBrQoiFvEe+yegBI9Hox5pSW/4IK wGkRZuEjm3VIV0oWjF/IJGgAAsH9dmvQkFExz0LHKslqFleN3+UFty2TF1ELWsaULyUG YeDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=hLQytPY7JFDlDptK9ywzPCQx4GJmGE7GwN7JnwshtW4=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=dLTGE3WOhnT0DnH2N3dj40+7IVglny9j2298EKPTVFIWi4/m6Brlb4qK741Wg/x1k4 E5rZfdXXezhwBCMAnwfNYJvGa+Vrir8uQPnyaXVq6QMt/L5wAY9WHdE3RlAtVebQap+S ak1u2eC/cV3aI3xNHzVFLRMltI2sifBaSd4lHiolzcyaBT0GZKkpCGdv4n2THsXy3Y9g 9LWm1bS0qooVMroLqmTwdK7cRrwi+DonUvrExWkZ9IUrXzrkCGQwfZOK7vMgcGIvxFxc GX6foiDDmrFcr0DbjZgS4+v6teXTgNqyWD0zKbCArR2qfdzeMR8QBkhVIZ57GqJQahjU m79Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IkzKnv9T; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bp7-20020a05620a458700b007833c44d78csi1592592qkb.265.2024.01.11.10.58.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 10:58:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IkzKnv9T; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E834E38618B3 for ; Thu, 11 Jan 2024 17:59:29 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787821583984359069 X-GMAIL-MSGID: 1787821583984359069 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);