Fix accessing a method's fields from Python
authorHannes Domani <ssbssa@yahoo.de>
Fri, 18 Dec 2020 15:17:46 +0000 (16:17 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Fri, 18 Dec 2020 21:02:13 +0000 (22:02 +0100)
commitb3f9469bfa42ef352e1d96f8733817242dd41a2e
tree07def32995663d9caa9b5e4bca93573a6ec8a34e
parenta9e48095a8e595f04042f9455a50ce6acbd5232c
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 "<string>", line 1, in <module>
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  <ssbssa@yahoo.de>

* python/py-type.c (typy_get_composite): Add TYPE_CODE_METHOD.

gdb/testsuite/ChangeLog:

2020-12-18  Hannes Domani  <ssbssa@yahoo.de>

* gdb.python/py-type.exp: Add tests for TYPE_CODE_METHOD.
gdb/ChangeLog
gdb/python/py-type.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-type.exp
This page took 0.025585 seconds and 4 git commands to generate.