From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id A8BE83857C72; Mon, 7 Mar 2022 19:42:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8BE83857C72 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: add new test for comparing char types in Python X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 551b380fbdad4082bc8520b1b61de883e8e4bf49 X-Git-Newrev: f99e1c6dc8144bfdf1e38b02006a739862a039a3 Message-Id: <20220307194237.A8BE83857C72@sourceware.org> Date: Mon, 7 Mar 2022 19:42:37 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Mar 2022 19:42:37 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df99e1c6dc814= 4bfdf1e38b02006a739862a039a3 commit f99e1c6dc8144bfdf1e38b02006a739862a039a3 Author: Andrew Burgess Date: Fri Feb 25 11:03:03 2022 +0000 gdb/testsuite: add new test for comparing char types in Python =20 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. =20 In contrast, and 'int' is signed by default, and so 'int' and 'signed int' are considered the same type. =20 This commit adds a test to ensure that this edge case is visible to a user from Python. =20 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. =20 There's no change to GDB with this commit, this is just adding a new test to guard some existing functionality. Diff: --- 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.pytho= n/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 =3D= =3D False)" "True" } =20 +# 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 =3D gdb.parse_and_eval('global_unsigned_${t= ype}')" + gdb_test_no_output "python v2 =3D gdb.parse_and_eval('global_${type}')" + gdb_test_no_output "python v3 =3D gdb.parse_and_eval('global_signed_${typ= e}')" + + gdb_test_no_output "python t1 =3D v1.type" + gdb_test_no_output "python t2 =3D v2.type" + gdb_test_no_output "python t3 =3D v3.type" + + if { $type =3D=3D "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 !=3D t2)" "True" + gdb_test "python print(t1 !=3D t3)" "True" + gdb_test "python print(t2 !=3D 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 !=3D t2)" "True" + gdb_test "python print(t1 !=3D t3)" "True" + gdb_test "python print(t2 =3D=3D t3)" "True" + } + } +} + # Test the gdb.Type.is_scalar property. proc test_is_scalar { lang } { if {$lang =3D=3D "c++"} { @@ -347,6 +379,7 @@ if { [build_inferior "${binfile}" "c"] =3D=3D 0 } { test_enums test_is_scalar "c" test_is_signed "c" + test_type_equality } } =20 @@ -362,5 +395,6 @@ if { [build_inferior "${binfile}-cxx" "c++"] =3D=3D 0 }= { test_enums test_is_scalar "c++" test_is_signed "c++" + test_type_equality } }