From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14662 invoked by alias); 16 Sep 2010 07:33:14 -0000 Received: (qmail 14650 invoked by uid 22791); 16 Sep 2010 07:33:12 -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-f41.google.com (HELO mail-ww0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Sep 2010 07:33:08 +0000 Received: by wwe15 with SMTP id 15so334wwe.0 for ; Thu, 16 Sep 2010 00:33:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.128.19 with SMTP id i19mr2381412wbs.104.1284622351330; Thu, 16 Sep 2010 00:32:31 -0700 (PDT) Received: by 10.216.70.81 with HTTP; Thu, 16 Sep 2010 00:32:31 -0700 (PDT) In-Reply-To: References: Date: Thu, 16 Sep 2010 07:33:00 -0000 Message-ID: Subject: Re: Python API questions and use cases From: =?ISO-8859-1?Q?Joel_Borggr=E9n=2DFranck?= To: Tom Tromey 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/msg00090.txt.bz2 On Wed, Sep 15, 2010 at 7:56 PM, Tom Tromey wrote: >>>>>> "Joel" =3D=3D Joel Borggr=E9n-Franck writes: > > 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. > Ok. I've approached the Python API as a (eventually) complete replacement for GDB-script, so whenever I have to use parse_and_eval I feel it's an (ugly) hack. This is perhaps not the intention? > Could you file a bug report for this? > Done :) > > I think the tricky part is getting a Value holding the appropriate > constant. =A0For that you might not have anything better, at present, than > parse_and_eval. True. Then I think this would be useful: gdb.new_address(addr) - returns a new gdb.Value (of type (void *)) pointing to addr. addr is checked to be within bounds of the address space of the inferior upon creation. > Joel> Another usecase for casts would be if I wanted to mask an address > Joel> in python, given: > Joel> foo *fooP; > Joel> how do I do the equivalent of this in pyhton: > Joel> set $check =3D ((size_t)foo) & 1 > > Simplest is to do it using Python math: > > =A0foo =3D ... > =A0check =3D long (foo) & 1 > > Otherwise you can look up size_t: > > =A0check =3D foo.cast (gdb.lookup_type ('size_t')) & 1 > > If you really want to set a convenience variable, then for the time > being you will have to use parse_and_eval. =A0We don't expose those any > other way. > Oh, thanks. I had overlooked gdb.Value.address. Using that and your example I have all the tools I need in this last case (no need to set a convenience var, that was only for the example). Thanks a lot! Cheers Joel