From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25762 invoked by alias); 21 Feb 2012 22:52:20 -0000 Received: (qmail 25749 invoked by uid 22791); 21 Feb 2012 22:52:18 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_RG X-Spam-Check-By: sourceware.org Received: from mail-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Feb 2012 22:52:04 +0000 Received: by wibhj13 with SMTP id hj13so5147590wib.0 for ; Tue, 21 Feb 2012 14:52:03 -0800 (PST) Received-SPF: pass (google.com: domain of zamfir.epfl@gmail.com designates 10.180.109.198 as permitted sender) client-ip=10.180.109.198; Authentication-Results: mr.google.com; spf=pass (google.com: domain of zamfir.epfl@gmail.com designates 10.180.109.198 as permitted sender) smtp.mail=zamfir.epfl@gmail.com Received: from mr.google.com ([10.180.109.198]) by 10.180.109.198 with SMTP id hu6mr30760398wib.16.1329864723203 (num_hops = 1); Tue, 21 Feb 2012 14:52:03 -0800 (PST) Received: by 10.180.109.198 with SMTP id hu6mr25655079wib.16.1329864723140; Tue, 21 Feb 2012 14:52:03 -0800 (PST) Received: from dslabpc24.epfl.ch (dslabpc24.epfl.ch. [128.178.77.224]) by mx.google.com with ESMTPS id cs4sm61931055wib.8.2012.02.21.14.52.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Feb 2012 14:52:01 -0800 (PST) Subject: Re: Python API iterate through the arguments of a frame Mime-Version: 1.0 (Apple Message framework v1257) Content-Type: text/plain; charset=us-ascii From: Cristian Zamfir In-Reply-To: <87obsst5o4.fsf@fleche.redhat.com> Date: Tue, 21 Feb 2012 22:52:00 -0000 Cc: Content-Transfer-Encoding: quoted-printable Message-Id: References: <3EDCC9ED-AD12-42B4-854E-3404A8EBCF70@epfl.ch> <87obsst5o4.fsf@fleche.redhat.com> To: Tom Tromey X-IsSubscribed: yes 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 X-SW-Source: 2012-02/txt/msg00057.txt.bz2 On Feb 21, 2012, at 7:14 PM, Tom Tromey wrote: >>>>>> "Cristian" =3D=3D Cristian Zamfir writes: >=20 > Cristian> I would like to write a Python script that iterates through the > Cristian> arguments of a frame. I was hoping I can retrieve these argumen= ts from > Cristian> a Frame object, but I did not find a way to do this, unless I k= now the > Cristian> name of the variables. Similarly, I would like to iterate throu= gh all > Cristian> the locals of the frame. >=20 > Cristian> Is this possible with the current Python API? If not, can you p= lease > Cristian> point me to where I could add additional functions to the Pytho= n API? >=20 > You can find the locals and arguments via Frame.block. Great, this worked. >=20 > I see that gdb.Block is under-documented in this area. Sorry about > that, I will write a patch. Thank you, that would be very useful. Is there a quick way to see the name= s of all available API functions, just in case there are more undocumented = ones, other than looking into the gdb/python/ directory and infer from the= Python bindings (e.g., py-block.c)? Somehow unrelated to this, I just noticed that I can retrieve the type of a= symbol while running a program inside gdb, but not when loading a dumped c= ore. In the latter case I get this error:=20 AttributeError: 'gdb.Symbol' object has no attribute 'type'.=20 I can however still retrieve the name and the value of the symbol when load= ing a core. Is it possible to also get the type? I should mention that I also see these two warnings when loading the core: warning: core file may not match specified executable file. warning: Can't read pathname for load map: Input/output error. Thanks,=20 Cristi >=20 > Here's a quick example: >=20 > (top-gdb) start > [...] > Temporary breakpoint 3, main (argc=3D > During symbol reading, incomplete CFI data; unspecified registers (e.g., = rax) at 0x488914. > 1, argv=3D0x7fffffffe558) at ../../archer/gdb/gdb.c:26 > (top-gdb) python >> for sym in gdb.newest_frame().block(): >> print sym >> end > argc > argv > args >=20 >=20 > In order to find all the locals in scope, and the arguments, you may > have to iterate upwards over blocks via Block.superblock. The block > with a non-None 'function' attribute will hold the arguments. >=20 > Tom