]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: make gdb.Symbol comparable for equality
authorJan Vrany <jan.vrany@labware.com>
Thu, 21 Nov 2024 12:31:20 +0000 (12:31 +0000)
committerJan Vrany <jan.vrany@labware.com>
Thu, 21 Nov 2024 13:49:11 +0000 (13:49 +0000)
In subsequent patches, it will be useful to be able to compare two
gdb.Symbols. This patch makes gdb.Symbols equal iff both refer to the
same underlying struct symtab.

gdb/python/py-symbol.c
gdb/testsuite/gdb.python/py-symbol.exp

index 38eead9cb3aefba78211135e8af9f1b5775eac80..44bed85481b2600bd4c10bd2d6324d094a7dadf5 100644 (file)
@@ -767,7 +767,8 @@ PyTypeObject symbol_object_type = {
   "GDB symbol object",           /*tp_doc */
   0,                             /*tp_traverse */
   0,                             /*tp_clear */
-  0,                             /*tp_richcompare */
+  gdbpy_richcompare<symbol_object, symbol, &symbol_object::symbol>,
+                                   /*tp_richcompare */
   0,                             /*tp_weaklistoffset */
   0,                             /*tp_iter */
   0,                             /*tp_iternext */
index 2a74c97a137e53031ba1f46ea475eaa73336c98c..1bfa17b4e912144eeeedc2578939b4fab2a34a31 100644 (file)
@@ -201,6 +201,27 @@ if { [is_remote host] } {
 }
 gdb_test "python print (t\[0\].symtab)" "${py_symbol_c}" "get symtab"
 
+# Test comparison for equality and non-equality
+gdb_test "python print (t\[0\] == t\[0\] )"\
+        "True" \
+        "test symbol equality with itself"
+gdb_test "python print (t\[0\] == a\[0\] )"\
+        "False" \
+        "test symbol equality with other symbol"
+gdb_test "python print (t\[0\] == 123 )"\
+        "False" \
+        "test symbol equality with non-symbol"
+
+gdb_test "python print (t\[0\] != t\[0\] )"\
+        "False" \
+        "test symbol non-equality with itself"
+gdb_test "python print (t\[0\] != a\[0\] )"\
+        "True" \
+        "test symbol non-equality with other symbol"
+gdb_test "python print (t\[0\] != 123 )"\
+        "True" \
+        "test symbol non-equality with non-symbol"
+
 # C++ tests
 # Recompile binary.
 lappend opts c++