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.133.124]) by sourceware.org (Postfix) with ESMTPS id DF4F73857C4E for ; Fri, 25 Feb 2022 11:31:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF4F73857C4E Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-n1hE_I_1O6aeD2AhaXeuqQ-1; Fri, 25 Feb 2022 06:31:24 -0500 X-MC-Unique: n1hE_I_1O6aeD2AhaXeuqQ-1 Received: by mail-wm1-f71.google.com with SMTP id n31-20020a05600c3b9f00b003812242973aso1206254wms.4 for ; Fri, 25 Feb 2022 03:31:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OvYSwCmzZ6jBg2t2ieUuJOJznbDbqqAAtmkHmiRLQZw=; b=415LiBUdRqc59RVJurR5uPH/eDqGcipqT6CfQRQ+jTL/g0q+A8VEl81lKAD6JgT2tm GSqEuV4hhEXYNa65yz5FZkMkyeoRU7AdU5wpRlV2Yag1dK8Gscsnp4vJR/F7ati75M5I 319KFsGvxVnOGNfReqZoJaGSrBC7Bx3LFnSII6mlpjr1C/vjYu4bSvVY9JCpN5F2t6NH oJMWFZdW0tNbHoVMxR87Xh4BWUS4gCri1sooOG2vRzcqYnfX9uI5z+6EyZ9s3YzXKz0j pPNtmOLqhI50PqfIiFqTT3BU8x3nexls39eCMt6AT7f6w64nzNwL7bayLjpsZ5ahSsy0 R8AA== X-Gm-Message-State: AOAM533evbub+YbrDXlwavr+QUWnYk5KEc0aMXkc5PyLgXjC0FLwlfbC +TsQbfmbytt5CIXAwP9AxED0v1ZKF01t8JmIiPQtNt+7ibjBdMi9FCzek8nOCuJxEn5RxSPgsmQ QY70RyRS+8Ho+EempUmXRSlHN2FpelANocTSsSfvKXawIjrhrYl0MTqiRZJ4W5OntmHsVUA== X-Received: by 2002:a05:600c:6c5:b0:380:dda2:d562 with SMTP id b5-20020a05600c06c500b00380dda2d562mr2395562wmn.138.1645788682955; Fri, 25 Feb 2022 03:31:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyY3/k5D0/zCCwJI4H3YPlJAqRkxUJkzIb96ECtgNxEjUoL2E2b3KF5CxSLH2QSjix9XMt1Ig== X-Received: by 2002:a05:600c:6c5:b0:380:dda2:d562 with SMTP id b5-20020a05600c06c500b00380dda2d562mr2395529wmn.138.1645788682588; Fri, 25 Feb 2022 03:31:22 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id z3-20020a1cf403000000b0037d1f4a2201sm2211175wma.21.2022.02.25.03.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 03:31:22 -0800 (PST) From: Andrew Burgess To: binutils@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 3/3] gdb/testsuite: add new test for comparing char types in Python Date: Fri, 25 Feb 2022 11:31:12 +0000 Message-Id: <1892ab4cd52d291aea57acafa22b70e0cc089ec3.1645788436.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-11.9 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_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Feb 2022 11:31:27 -0000 There's an interesting property of the 'char' type in C and C++, the three types 'char', 'unsigned char', and 'signed char', are all considered distinct. In contrast, and 'int' is signed by default, and so 'int' and 'signed int' are considered the same type. This commit adds a test to ensure that this edge case is visible to a user from Python. It is worth noting that for any particular compiler implementation (or the flags a compiler was invoked with), a 'char' will be either signed or unsigned; it has to be one or the other, and a user can access this information by using the Type.is_signed property. However, for something like function overload resolution, the 'char' type is considered distinct from the signed and unsigned variants. There's no change to GDB with this commit, this is just adding a new test to guard some existing functionality. --- gdb/testsuite/gdb.python/py-type.exp | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index 86cf8f3ff69..5613bc024f6 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -296,6 +296,38 @@ proc test_is_signed {lang} { gdb_test "python print(gdb.parse_and_eval ('&uu').type.is_signed == False)" "True" } +# Compare the types of different symbols from the inferior, we're +# checking that the types of different sybols of the same declared +# type, are equal (in Python). +proc test_type_equality {} { + + foreach_with_prefix type { char int } { + gdb_test_no_output "python v1 = gdb.parse_and_eval('global_unsigned_${type}')" + gdb_test_no_output "python v2 = gdb.parse_and_eval('global_${type}')" + gdb_test_no_output "python v3 = gdb.parse_and_eval('global_signed_${type}')" + + gdb_test_no_output "python t1 = v1.type" + gdb_test_no_output "python t2 = v2.type" + gdb_test_no_output "python t3 = v3.type" + + if { $type == "char" } { + # In C/C++ there's an interesting property of 'char' based types; + # 'signed char', 'unsigned char', and 'char' are all distinct + # types. Weird, right? Here we check that this property is + # visible to Python code. + gdb_test "python print(t1 != t2)" "True" + gdb_test "python print(t1 != t3)" "True" + gdb_test "python print(t2 != t3)" "True" + } else { + # For 'int' type, when neither signed or unsigned is given + # we expect the type to be signed by default. + gdb_test "python print(t1 != t2)" "True" + gdb_test "python print(t1 != t3)" "True" + gdb_test "python print(t2 == t3)" "True" + } + } +} + # Test the gdb.Type.is_scalar property. proc test_is_scalar { lang } { if {$lang == "c++"} { @@ -347,6 +379,7 @@ if { [build_inferior "${binfile}" "c"] == 0 } { test_enums test_is_scalar "c" test_is_signed "c" + test_type_equality } } @@ -362,5 +395,6 @@ if { [build_inferior "${binfile}-cxx" "c++"] == 0 } { test_enums test_is_scalar "c++" test_is_signed "c++" + test_type_equality } } -- 2.25.4