8sa1-binutils-gdb/gdb/python
Hannes Domani b3f9469bfa 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.
2020-12-18 22:02:13 +01:00
..
lib/gdb
py-all-events.def
py-arch.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-auto-load.c
py-block.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-bpevent.c
py-breakpoint.c
py-cmd.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-continueevent.c
py-event-types.def
py-event.c
py-event.h Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-events.h Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-evtregistry.c
py-evts.c
py-exitedevent.c
py-finishbreakpoint.c
py-frame.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-framefilter.c
py-function.c
py-gdb-readline.c
py-inferior.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-infevents.c
py-infthread.c
py-instruction.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-instruction.h
py-lazy-string.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-linetable.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-newobjfileevent.c
py-objfile.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-param.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-prettyprint.c
py-progspace.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-record-btrace.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-record-btrace.h
py-record-full.c
py-record-full.h
py-record.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-record.h Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-ref.h
py-registers.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-signalevent.c
py-stopevent.c
py-stopevent.h
py-symbol.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-symtab.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-threadevent.c
py-tui.c
py-type.c Fix accessing a method's fields from Python 2020-12-18 22:02:13 +01:00
py-unwind.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-utils.c
py-value.c Remove redundant typedefs 2020-12-04 13:12:56 -07:00
py-varobj.c Change varobj_item::value to a value_ref_ptr 2020-12-11 09:33:40 -07:00
py-xmethods.c
python-config.py
python-internal.h Change varobj_dynamic::child_iter to unique_ptr 2020-12-11 09:33:40 -07:00
python.c
python.h