aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Vrany <jan.vrany@labware.com>2024-11-21 12:31:20 +0000
committerJan Vrany <jan.vrany@labware.com>2024-11-21 13:49:11 +0000
commitf44e78463de1c614ccb744f40e00c884b38473d6 (patch)
tree3a712845d309bc7765029d900fe2f9c5acd8b11d
parent329c759de023078987c29bdb5e710c0e63f57794 (diff)
downloadfsf-binutils-gdb-f44e78463de1c614ccb744f40e00c884b38473d6.zip
fsf-binutils-gdb-f44e78463de1c614ccb744f40e00c884b38473d6.tar.gz
fsf-binutils-gdb-f44e78463de1c614ccb744f40e00c884b38473d6.tar.bz2
gdb/python: make gdb.Symtab comparable for equality
Like previous patch, but for gdb.Symtab.
-rw-r--r--gdb/python/py-symtab.c3
-rw-r--r--gdb/testsuite/gdb.python/py-symtab.exp21
2 files changed, 23 insertions, 1 deletions
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 99a5094..5330b15 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -579,7 +579,8 @@ PyTypeObject symtab_object_type = {
"GDB symtab object", /*tp_doc */
0, /*tp_traverse */
0, /*tp_clear */
- 0, /*tp_richcompare */
+ gdbpy_richcompare<symtab_object, symtab, &symtab_object::symtab>,
+ /*tp_richcompare */
0, /*tp_weaklistoffset */
0, /*tp_iter */
0, /*tp_iternext */
diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp
index 4765ef5..9caa5f1 100644
--- a/gdb/testsuite/gdb.python/py-symtab.exp
+++ b/gdb/testsuite/gdb.python/py-symtab.exp
@@ -89,6 +89,27 @@ gdb_test_multiple "python print (\"simple_struct\" in static_symbols)" \
}
}
}
+# Test comparison for equality and non-equality
+gdb_test "python print (symtab == symtab)"\
+ "True" \
+ "test symtab equality with itself"
+gdb_test "python print (symtab == sal.symtab)"\
+ "True" \
+ "test symtab equality with other symtab object referring to the same symtab"
+gdb_test "python print (symtab == 123 )"\
+ "False" \
+ "test symtab equality with non-symtab"
+
+gdb_test "python print (symtab != symtab)"\
+ "False" \
+ "test symtab non-equality with itself"
+gdb_test "python print (symtab != sal.symtab)"\
+ "False" \
+ "test symtab non-equality with other symtab object referring to the same symtab"
+gdb_test "python print (symtab != 123 )"\
+ "True" \
+ "test symtab non-equality with non-symtab"
+
# Test is_valid when the objfile is unloaded. This must be the last
# test as it unloads the object file in GDB.