This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: source command for python scripts
- From: Tom Tromey <tromey at redhat dot com>
- To: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- Cc: Paul Pluzhnikov <ppluzhnikov at google dot com>, archer at sourceware dot org
- Date: Wed, 05 Nov 2008 11:13:08 -0700
- Subject: Re: source command for python scripts
- References: <20081104192834.32F4D3A6B0B@localhost><1225907783.20764.60.camel@localhost.localdomain>
- Reply-to: Tom Tromey <tromey at redhat dot com>
Tom> (gdb) python execfile('simple.py')
Thiago> I was wondering if it would be useful to have a command in GDB to source
Thiago> Python scripts, something like "source -p foo.py". But the command above
Thiago> is short enough that we wouldn't need a separate command. What do you
Thiago> think?
How about the appended? :-)
This isn't quite as nice as "source -p", but it was simpler to
implement.
A couple ideas I've had for improved commands-in-python:
* Make it possible to rename existing gdb commands, or have Python
objects wrap the underlying command structure.
This would let us write a new "source" (e.g.) in Python that could
delegate to the old "source" when needed.
I have a use for this with "backtrace" too...
For this to work well I think we'd also need to fix the existing gdb
crash involving redefining commands with aliases.
* Put interesting commands into a Python module, like gdb.commands.
Ship a bunch of them with gdb -- but not activated. Then users
could pick the ones they like:
python import gdb.commands.PSource
python import gdb.commands.FancyBacktrace
Tom
import gdb
class PSource(gdb.Command):
"Read a file and evaluate its contents as Python code."
def __init__(self):
super(PSource, self).__init__("psource",
gdb.COMMAND_OBSCURE,
gdb.COMPLETE_FILENAME)
def invoke(self, arg, from_tty):
self.dont_repeat()
execfile(arg)
PSource()