Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Thiago Jung Bauermann <bauerman@br.ibm.com>
Cc: gdb ml <gdb@sourceware.org>
Subject: Re: repo to work on python scripting support
Date: Sun, 16 Mar 2008 02:55:00 -0000	[thread overview]
Message-ID: <m3tzj7y2cz.fsf@fleche.redhat.com> (raw)
In-Reply-To: <1205538908.6643.138.camel@localhost.localdomain> (Thiago Jung Bauermann's message of "Fri\, 14 Mar 2008 20\:55\:08 -0300")

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


  reply	other threads:[~2008-03-16  0:42 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-16  0:42 Thiago Jung Bauermann
2008-03-16  2:55 ` Tom Tromey [this message]
2008-03-24 17:16   ` Thiago Jung Bauermann
2008-03-25 11:45     ` Tom Tromey
2008-03-25 13:53       ` Daniel Jacobowitz
2008-03-25 18:37         ` Jim Blandy
2008-03-25 18:52           ` Daniel Jacobowitz
2008-03-25 18:53             ` Jim Blandy
2008-03-25 19:18             ` Tom Tromey
2008-03-27  6:41               ` Jim Blandy
2008-03-27 17:57                 ` Paul Koning
2008-03-25 19:31           ` Paul Koning
2008-03-25 20:18             ` Tom Tromey
2008-03-25 20:31               ` Paul Koning
2008-03-26  3:23                 ` Tom Tromey
2008-03-26 12:55                 ` Jim Blandy
2008-03-26 17:29                   ` Paul Koning
2008-03-26 17:58                     ` Daniel Jacobowitz
2008-03-26 18:41                     ` Tom Tromey
2008-03-26 20:04                       ` Paul Koning
2008-03-26 22:45                     ` Jim Blandy
2008-03-26 18:05       ` Doug Evans
2008-03-26 18:13         ` Daniel Jacobowitz
2008-03-26 18:25           ` Tom Tromey
2008-03-26 18:41             ` Daniel Jacobowitz
2008-03-26 18:55               ` Tom Tromey
2008-03-26 20:57                 ` Daniel Jacobowitz
2008-03-26 21:01                 ` Thiago Jung Bauermann
2008-03-27 14:11           ` Jim Blandy
2008-03-27 16:49             ` Paul Koning
2008-03-26 18:23         ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3tzj7y2cz.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=bauerman@br.ibm.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox