From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2106 invoked by alias); 16 Mar 2008 00:42:40 -0000 Received: (qmail 2092 invoked by uid 22791); 16 Mar 2008 00:42:39 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 16 Mar 2008 00:42:21 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m2G0gHTB007958; Sat, 15 Mar 2008 20:42:17 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m2G0gHpv011607; Sat, 15 Mar 2008 20:42:17 -0400 Received: from opsy.redhat.com (vpn-248-6.boston.redhat.com [10.13.248.6]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m2G0gGXf021563; Sat, 15 Mar 2008 20:42:17 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 3F479C8803D; Sat, 15 Mar 2008 17:49:32 -0600 (MDT) To: Thiago Jung Bauermann Cc: gdb ml Subject: Re: repo to work on python scripting support References: <1205538908.6643.138.camel@localhost.localdomain> From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Sun, 16 Mar 2008 02:55:00 -0000 In-Reply-To: <1205538908.6643.138.camel@localhost.localdomain> (Thiago Jung Bauermann's message of "Fri\, 14 Mar 2008 20\:55\:08 -0300") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-03/txt/msg00145.txt.bz2 I did some hacking on the Python integration over the last couple of days, enough to warrant a status update. You can evaluate python, either as a block, as a one-liner, or as an expression. I cleaned up the code so that it works properly in other block structures, like commands or loops. The expression evaluation code makes an attempt to convert python values to gdb values as appropriate (strings, ints, and floating-point types). Some contrived examples... Block form: python print 23 end One liner: python print 23 Expression: break foo if $(23 > 5) There is minimal hook-up to frames. You can get the name of the function at any frame depth and the number of frames. This area needs an OO rewrite. I haven't tried out the value support at all yet (sorry Thiago and Volodya). Breakpoints are now visible as objects and some of their properties are inspectable. Some properties can be set from Python as well. Enough works that I was able to write a simple "save my breakpoints" script -- it is appended. Breakpoints need some more plumbing. I want to make it so you can write: new gdb.Breakpoint('location') and have it do the right thing. (This looks pretty easy.) You can set Python hooks on a few events but this is not documented and not tested yet. There's also a Python command to pass any string to the gdb CLI, and another one to get the value of any "set/show" variable. As you can see it is pretty rough still, but I think it is coming along rather well. It is not very hard to add new functionality. There are a few things I don't understand about hooking this code to gdb, I'll ask in a separate thread. Comments, constructive criticism, etc, welcome. Tom # Set up a python function to do the work. python from __future__ import with_statement import os def gdb_save_breakpoints(filename): with open(filename, 'w') as file: for bp in gdb.breakpoints(): if not bp: continue if not bp.is_valid(): continue print >> file, "break", bp.get_location(), cond = bp.get_condition() if cond: print >> file, " if", cond, print >> file commands = bp.get_commands() if commands: print >> file, "commands" print >> file, commands, print >> file, "end" if not bp.is_enabled(): print >> file, "disable $bpnum" end # And now the gdb user command. # Try: save_breakpoints /tmp/out define save_breakpoints dont-repeat # Silly quoting games... python gdb_save_breakpoints('$arg0') end