This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Python API: Type introspection of function arguments


Hi all,

GDB Python bindings are great. I have a question though.

I'm trying to use a Python script to introspect the type of a function
argument. The GDB documentation claims this is possible:
https://sourceware.org/gdb/current/onlinedocs/gdb/Types-In-Python.html#Types-In-Python

"â Function: Type.fields ()
For structure and union types, this method returns the fields. Range
types have two fields, the minimum and maximum values. Enum types have
one field per enum constant. Function and method types have one field
per parameter."

However when I try this (in 7.8.1.20141128-cvs) I get the following error:

>>> sym = gdb.lookup_global_symbol('my_function')
>>> print sym.type.code == gdb.TYPE_CODE_FUNC
True
>>> print sym.type.fields()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Type is not a structure, union, or enum type.
>>>

I also looked in the code (gdb/python/py-type.c) and this seems to
have the same behavior in 7.10.

In light of this issue, can anyone suggest how to get function
argument type information from Python API?

Thanks,
Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]