This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: repo to work on python scripting support


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]