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 | 3 ++-
gdb/testsuite/gdb.python/py-symbol.exp | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
@@ -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 */
@@ -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++