From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2695 invoked by alias); 16 Sep 2010 06:13:51 -0000 Received: (qmail 2685 invoked by uid 22791); 16 Sep 2010 06:13:50 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-ww0-f43.google.com (HELO mail-ww0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Sep 2010 06:13:45 +0000 Received: by wwi14 with SMTP id 14so1039664wwi.12 for ; Wed, 15 Sep 2010 23:13:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.38.71 with SMTP id z49mr6255903wea.76.1284617623450; Wed, 15 Sep 2010 23:13:43 -0700 (PDT) Received: by 10.216.70.81 with HTTP; Wed, 15 Sep 2010 23:13:43 -0700 (PDT) In-Reply-To: <4C9118CE.9020606@redhat.com> References: <4C9118CE.9020606@redhat.com> Date: Thu, 16 Sep 2010 06:13:00 -0000 Message-ID: Subject: Re: Python API questions and use cases From: =?ISO-8859-1?Q?Joel_Borggr=E9n=2DFranck?= To: Phil Muldoon Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2010-09/txt/msg00089.txt.bz2 On Wed, Sep 15, 2010 at 9:04 PM, Phil Muldoon wrote: > On 09/15/2010 06:56 PM, Tom Tromey wrote: >>>>>>> "Joel" =3D=3D Joel Borggr=E9n-Franck writes: >> >> Joel> 1) Getting the value of a global >> Joel> foo myGlobalFoo; >> Joel> in some C file, how do I access the value of myGlobalFoo from >> Joel> python? >> >> Joel> The only working solution I have at the moment is to escape to >> Joel> gdb-script with: >> Joel> gdb.parse_and_eval("myGlobalFoo") >> Joel> is this intended? >> >> This is simplest. >> >> Joel> I know I can iterate over symbols in the symbol table, but I >> Joel> haven't found a way to go from symbol to value. >> >> Hmm, we don't seem to expose a way to do that. =A0Sorry about that. >> Could you file a bug report for this? > > If you have the frame, you can use .read_var and pass the symbol as an > argument. =A0You can read the value behind the symbol then (as we know > what frame; can you divine it otherwise, just from the symbol?) > This is a global symbol, so that should not work. If you can get to global symbols through a frame you have to devise a some way of telling the programmer if she got the value for a frame-local symbol with the same name or the global symbol. IMHO it is better to just add a Symbol.getGlobalValue that returns Nil or raises if used on a frame-local symbol. Cheers /Joel