From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 53A383857701 for ; Thu, 11 Jan 2024 17:58:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53A383857701 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 53A383857701 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=YUh7xct0+VT0vcbyeEofEmoh4JoZZ5Ec8kBE/lw4Yuj7AebsfX0iXNk2XgJHKh+RQ9QvKeHWEO72RMip+l85/FQlSUj63aVKn3gspIa8k2qjvjP8Oz57RzSBxHsSSPFkVWEhOhgBVOP7RdTcOvo2tx43asvPCBlOFBZ+QnCpkhE= 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=rlhbgxAu4vDArhNM2MZVzIt3SlKsyj38/Z2qMxj7VMaUJ+b/OefHkDSuI6ylxRQbG4i1+WF9GoDNTuXOabyATyIO4TFr3MDNXpUVV2zfoFZuRueV464OPBkhUmyGcNMi6o/Ohhw3sx5mdF8e2VvKfyYMCJCoaeQox4QXfTfwHY0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704995919; 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=VbGopfb+FQQRIKZhO8pZGeLgNbKrykO4HaDRjsXVRJV8gjzpvaaixQQWAolBMW3CLh41Mx P3OljRRT74c243bVn6NSeYyNfJCAvpH+nQJngZ+fI738U0cqeXJ6tkgQHYrhkciSEY5ZjN YHZsyKa4sCNIinnWCrzKRxUcS6HLMMU= 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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 List-Id: 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); -- 2.43.0