From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12775 invoked by alias); 15 Sep 2010 13:43:59 -0000 Received: (qmail 12759 invoked by uid 22791); 15 Sep 2010 13:43:59 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-ew0-f41.google.com (HELO mail-ew0-f41.google.com) (209.85.215.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Sep 2010 13:43:51 +0000 Received: by ewy28 with SMTP id 28so85639ewy.0 for ; Wed, 15 Sep 2010 06:43:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.6.195 with SMTP id 45mr5257997wen.86.1284558228751; Wed, 15 Sep 2010 06:43:48 -0700 (PDT) Received: by 10.216.70.81 with HTTP; Wed, 15 Sep 2010 06:43:48 -0700 (PDT) Date: Wed, 15 Sep 2010 13:43:00 -0000 Message-ID: Subject: Python API questions and use cases From: =?ISO-8859-1?Q?Joel_Borggr=E9n=2DFranck?= To: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 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/msg00085.txt.bz2 Hi I'm testing out the new Python API for GDB, and have a couple of use cases that I don't know how to solve entirely from python. I hope this is the right mailing list. In all these cases I'm working on debugging a core. 1) Getting the value of a global given: typedef struct foo { int bar; int baz; } foo; foo myGlobalFoo; in some C file, how do I access the value of myGlobalFoo from python? The only working solution I have at the moment is to escape to gdb-script with: gdb.parse_and_eval("myGlobalFoo") is this intended? I know I can iterate over symbols in the symbol table, but I haven't found a way to go from symbol to value. 2) Casts given that I know that at address 0xdeadbeef there will be a struct of type foo how do I get that struct (or a pointer to that struct) as a gdb.Value object? Currently i have written a cast function: def cast(type_string, address): """Returns a gdb.Value object with type 'type_string' from memory starting at 'address'.""" return gdb.parse_and_eval("(%s)((void *)%s)" % (type_string, address)) that I think works, but is there some other way? Another usecase for casts would be if I wanted to mask an address in python, given: foo *fooP; how do I do the equivalent of this in pyhton: set $check = ((size_t)foo) & 1 I know there is the a cast in the API but that requires that I have a gdb.Type which I don't know how to get. I'd be happy to help out adding solutions to these use-cases! Cheers Joel