[python] Allow extraction of function and method arguments, as specified in the documentation.

Message ID CAEiLdJZgJOB64v1gNaBVLfb0hPYLrHX71hjYj+8zPguY=SjgJw@mail.gmail.com
State New, archived
Headers

Commit Message

Zach Riggle June 12, 2015, 7:14 p.m. UTC
  Example usage:

    >>> func = gdb.lookup_symbol('expandargv')[0]
    >>> str(func), str(func.type)
    ('expandargv', 'void (int *, char ***)')
    >>> [str(field.type) for field in func.type.fields()]
    ['int *', 'char ***']
---
 gdb/python/py-type.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Joel Brobecker June 15, 2015, 1:16 p.m. UTC | #1
Zach,

> Example usage:
> 
>     >>> func = gdb.lookup_symbol('expandargv')[0]
>     >>> str(func), str(func.type)
>     ('expandargv', 'void (int *, char ***)')
>     >>> [str(field.type) for field in func.type.fields()]
>     ['int *', 'char ***']

As explained privately, I think Doug Evans would be a better reviewer
than me, but I glanced at the patch anyway, and can provide the
following feedback.

First of all, thank you for sending in a patch! :-)

Second, I'm afraid the description is a little too terse. I would
be better, in my opinion, to be a little more verbose in what
you are trying to say. In particular, what the problem is that
you are trying to fix, and how you're fixing it. Usually, a copy/paste
of the output before and after your patch, explaining what's wrong
in it, goes a long way.

Patch submissions also require a ChangeLog entry. We actually
have a contribution Checklist:
https://sourceware.org/gdb/wiki/ContributionChecklist

I think this change deserves a regression test.

Speaking of which, did you validate this change against the GDB
testsuite? If yes, it's customary to say so, and specific which
platform this was tested on.

Thank you.

> ---
>  gdb/python/py-type.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
> index 648d8c8..bf42ff4 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -495,7 +495,9 @@ typy_get_composite (struct type *type)
>       exception.  */
>    if (TYPE_CODE (type) != TYPE_CODE_STRUCT
>        && TYPE_CODE (type) != TYPE_CODE_UNION
> -      && TYPE_CODE (type) != TYPE_CODE_ENUM)
> +      && TYPE_CODE (type) != TYPE_CODE_ENUM
> +      && TYPE_CODE (type) != TYPE_CODE_FUNC
> +      && TYPE_CODE (type) != TYPE_CODE_METHOD)
>      {
>        PyErr_SetString (PyExc_TypeError,
>         "Type is not a structure, union, or enum type.");
> -- 
> 2.2.0.rc0.207.ga3a616c
  

Patch

diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 648d8c8..bf42ff4 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -495,7 +495,9 @@  typy_get_composite (struct type *type)
      exception.  */
   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
       && TYPE_CODE (type) != TYPE_CODE_UNION
-      && TYPE_CODE (type) != TYPE_CODE_ENUM)
+      && TYPE_CODE (type) != TYPE_CODE_ENUM
+      && TYPE_CODE (type) != TYPE_CODE_FUNC
+      && TYPE_CODE (type) != TYPE_CODE_METHOD)
     {
       PyErr_SetString (PyExc_TypeError,
        "Type is not a structure, union, or enum type.");