From b3f9469bfa42ef352e1d96f8733817242dd41a2e Mon Sep 17 00:00:00 2001 From: Hannes Domani Date: Fri, 18 Dec 2020 16:17:46 +0100 Subject: Fix accessing a method's fields from Python Considering this example: struct C { int func() { return 1; } } c; int main() { return c.func(); } Accessing the fields of C::func, when requesting the function by its type, works: (gdb) py print(gdb.parse_and_eval('C::func').type.fields()[0].type) C * const But when trying to do the same via a class instance, it fails: (gdb) py print(gdb.parse_and_eval('c')['func'].type.fields()[0].type) Traceback (most recent call last): File "", line 1, in TypeError: Type is not a structure, union, enum, or function type. Error while executing Python code. The difference is that in the former the function type is TYPE_CODE_FUNC: (gdb) py print(gdb.parse_and_eval('C::func').type.code == gdb.TYPE_CODE_FUNC) True And in the latter the function type is TYPE_CODE_METHOD: (gdb) py print(gdb.parse_and_eval('c')['func'].type.code == gdb.TYPE_CODE_METHOD) True So this adds the functionality for TYPE_CODE_METHOD as well. gdb/ChangeLog: 2020-12-18 Hannes Domani * python/py-type.c (typy_get_composite): Add TYPE_CODE_METHOD. gdb/testsuite/ChangeLog: 2020-12-18 Hannes Domani * gdb.python/py-type.exp: Add tests for TYPE_CODE_METHOD. --- gdb/python/py-type.c | 1 + 1 file changed, 1 insertion(+) (limited to 'gdb/python') diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 1c7cacb..3fc0f61 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -471,6 +471,7 @@ typy_get_composite (struct type *type) if (type->code () != TYPE_CODE_STRUCT && type->code () != TYPE_CODE_UNION && type->code () != TYPE_CODE_ENUM + && type->code () != TYPE_CODE_METHOD && type->code () != TYPE_CODE_FUNC) { PyErr_SetString (PyExc_TypeError, -- cgit v1.1