public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Python API: Type introspection of function arguments
@ 2015-09-25  4:24 Martin Ünsal
  2015-09-27 23:28 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Ünsal @ 2015-09-25  4:24 UTC (permalink / raw)
  To: gdb

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Python API: Type introspection of function arguments
  2015-09-25  4:24 Python API: Type introspection of function arguments Martin Ünsal
@ 2015-09-27 23:28 ` Simon Marchi
  2015-09-28  4:50   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2015-09-27 23:28 UTC (permalink / raw)
  To: Martin Ünsal; +Cc: gdb

On 25 September 2015 at 00:24, Martin Ünsal <munsal@nestlabs.com> wrote:
> 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

Hi Martin,

I found a bug for that in the bugzilla:

  https://sourceware.org/bugzilla/show_bug.cgi?id=18073

I tested the feature with a few releases of gdb. It appeared it 7.1
and stopped working in 7.4, so it's been broken for quite a while.

The patch attached to the bug seems to make it work again. I am
running the regression testsuite at the moment. If it's successful,
I'll try to add a test for that and submit it... unless you want to do
it, of course :).

In the mean time, I don't have any suggestions to circumvent that,
other than building your own gdb (with the patch applied) for now.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Python API: Type introspection of function arguments
  2015-09-27 23:28 ` Simon Marchi
@ 2015-09-28  4:50   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2015-09-28  4:50 UTC (permalink / raw)
  To: Martin Ünsal; +Cc: gdb

On 27 September 2015 at 19:28, Simon Marchi <simon.marchi@polymtl.ca> wrote:
> The patch attached to the bug seems to make it work again. I am
> running the regression testsuite at the moment. If it's successful,
> I'll try to add a test for that and submit it... unless you want to do
> it, of course :).

FYI, I posted the patch along with a test:

  https://sourceware.org/ml/gdb-patches/2015-09/msg00596.html

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-28  4:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-25  4:24 Python API: Type introspection of function arguments Martin Ünsal
2015-09-27 23:28 ` Simon Marchi
2015-09-28  4:50   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).