This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA/python:2/2] First script in GDB python library - command/pahole.py
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 2 Jun 2010 17:11:15 -0700
- Subject: Re: [RFA/python:2/2] First script in GDB python library - command/pahole.py
- References: <1274918921-23200-1-git-send-email-brobecker@adacore.com> <1274918921-23200-3-git-send-email-brobecker@adacore.com> <m3aarlf5n7.fsf@fleche.redhat.com>
> There is no sensible way for a user to activate such a command. With
> this patch a user would have to know the name of the command's file and
> invoke "python import gdb.command.pahole".
[...]
> One idea would be to allow some kind of auto-loading when a command is
> not found. That is, load pahole.py the first time the "pahole" command
> is used. Or even better, scan the install tree first so that command
> completion still works. (This is not ideal, though, since there is not
> actually a way to discover command names without loading the file.)
Here is an approach that should work. The idea is to rely on the
convention that the command name is the name of the python script.
Subcommands are stored inside subdirectories. For instance, let's
imagine that we're trying to execute the following command:
(gdb) prefix1 prefix2 pycommand arg1 arg2
What I propose we do is that, if a python script provides an implementation
of command "prefix1 prefix2 pycommand", then it should be stored in
GDB_PYTHON_DIR/command/prefix1/prefix2/pycommand.py
(Doug asked whether we wanted the .py extension or not; either of us
don't seem to have a strong opinion on it, although I do like it, and
most editors will likely also appreciate having it to automatically
activate the python edit mode).
pycommand.py is a python *script* (it is not expected to be a module file)
which will be executed when the "prefix1 prefix2 pycommand" command is
actually used.
I am not sure that we should search for Python commands only after
we failed to find a command. I'm thinking of the various prefix
commands that we already have such as the set command. The current
semantics of the "set" command is that it treats the arguments as
an expression if no subcommand was found. So if we looked at python
commands only after we failed to find a regular command, then it would
not allow us to add a set subcommand, at least not automatically.
That's why I suggest we scan the GDB_PYTHON_DIR/command directory
for all scripts, and create stub commands - the commands exist, but
their implementation is only loaded on-demand. The loading would
be performed using the execfile command (or its C equivalent if there
is one).
WDYT? (note that having the stub command should also allow us to
have command completion)
--
Joel