public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb/testsuite: add new test for comparing char types in Python
Date: Mon,  7 Mar 2022 19:42:37 +0000 (GMT)	[thread overview]
Message-ID: <20220307194237.A8BE83857C72@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f99e1c6dc8144bfdf1e38b02006a739862a039a3

commit f99e1c6dc8144bfdf1e38b02006a739862a039a3
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Feb 25 11:03:03 2022 +0000

    gdb/testsuite: add new test for comparing char types in Python
    
    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.

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.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
   }
 }


                 reply	other threads:[~2022-03-07 19:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220307194237.A8BE83857C72@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).