From: Jan Vrany Date: Thu, 21 Nov 2024 12:31:20 +0000 (+0000) Subject: gdb/python: make gdb.Symbol comparable for equality X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=329c759de023078987c29bdb5e710c0e63f57794;p=thirdparty%2Fbinutils-gdb.git gdb/python: make gdb.Symbol comparable for equality 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. --- diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 38eead9cb3a..44bed85481b 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -767,7 +767,8 @@ PyTypeObject symbol_object_type = { "GDB symbol object", /*tp_doc */ 0, /*tp_traverse */ 0, /*tp_clear */ - 0, /*tp_richcompare */ + gdbpy_richcompare, + /*tp_richcompare */ 0, /*tp_weaklistoffset */ 0, /*tp_iter */ 0, /*tp_iternext */ diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index 2a74c97a137..1bfa17b4e91 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -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++