From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 39349 invoked by alias); 27 Sep 2015 23:28:49 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 39339 invoked by uid 89); 27 Sep 2015 23:28:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f47.google.com Received: from mail-qg0-f47.google.com (HELO mail-qg0-f47.google.com) (209.85.192.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 27 Sep 2015 23:28:46 +0000 Received: by qgx61 with SMTP id 61so108402967qgx.3 for ; Sun, 27 Sep 2015 16:28:44 -0700 (PDT) X-Received: by 10.140.216.202 with SMTP id m193mr20414438qhb.30.1443396524679; Sun, 27 Sep 2015 16:28:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.75.85 with HTTP; Sun, 27 Sep 2015 16:28:15 -0700 (PDT) In-Reply-To: References: From: Simon Marchi Date: Sun, 27 Sep 2015 23:28:00 -0000 Message-ID: Subject: Re: Python API: Type introspection of function arguments To: =?UTF-8?Q?Martin_=C3=9Cnsal?= Cc: "gdb@sourceware.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00027.txt.bz2 On 25 September 2015 at 00:24, Martin =C3=9Cnsal wrot= e: > 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#Ty= pes-In-Python > > "=E2=80=94 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 =3D gdb.lookup_global_symbol('my_function') >>>> print sym.type.code =3D=3D gdb.TYPE_CODE_FUNC > True >>>> print sym.type.fields() > Traceback (most recent call last): > File "", line 1, in > 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=3D18073 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