This is the mail archive of the
mailing list for the GDB project.
Re: repo to work on python scripting support
- From: Tom Tromey <tromey at redhat dot com>
- To: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- Cc: gdb ml <gdb at sourceware dot org>
- Date: Sat, 15 Mar 2008 17:49:32 -0600
- Subject: Re: repo to work on python scripting support
- References: <firstname.lastname@example.org>
- Reply-to: tromey at redhat dot com
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
python print 23
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
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"
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.
# Set up a python function to do the work.
from __future__ import with_statement
with open(filename, 'w') as file:
for bp in gdb.breakpoints():
if not bp:
if not bp.is_valid():
print >> file, "break", bp.get_location(),
cond = bp.get_condition()
print >> file, " if", cond,
print >> file
commands = bp.get_commands()
print >> file, "commands"
print >> file, commands,
print >> file, "end"
if not bp.is_enabled():
print >> file, "disable $bpnum"
# And now the gdb user command.
# Try: save_breakpoints /tmp/out
# Silly quoting games...