This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Define python hooks
- From: Doug Evans <xdje42 at gmail dot com>
- To: nojhan <nojhan at nojhan dot net>
- Cc: gdb <gdb at sourceware dot org>
- Date: Wed, 29 Oct 2014 11:39:19 -0700
- Subject: Re: Define python hooks
- Authentication-results: sourceware.org; auth=none
- References: <CAJRERJWv4EnUSM-LGnAVaRJwZ=gimcQ7e1MZvLdqTsGc6R3rnA at mail dot gmail dot com> <CAP9bCMRuOuDzXUcnuCGuGixT373HZv0LPt4UWERoNjbBWMXzYw at mail dot gmail dot com> <CAJRERJXcawq3mQmWHpodjj10Z_T6-0TKmtCprehDskdCh3R-4g at mail dot gmail dot com> <CAP9bCMSduJBd4er4ZzGYtp8fv6XGuO1KKobkZ-zYJ7p=DoZATQ at mail dot gmail dot com> <CAJRERJX7PabS0hZ5rhk1p3uftFZHFXudKy9LyawoNzthsBSU2A at mail dot gmail dot com>
On Tue, Oct 28, 2014 at 6:17 AM, nojhan <nojhan@nojhan.net> wrote:
> The documentation states that "It is valid for a hook to call the
> command which it hooks. If this occurs, the hook is not re-executed,
> thereby avoiding infinite recursion."
> But this does not seems to be true for the python API.
>
> Here what I tried:
> 1) Defining the hook as a python function that would gdb.execute the
> same command. Failed, because then the command is executed twice.
You mean the hook is executed twice, right?
The docs say the hook won't be executed twice, but executing the
command twice is ok.
I tried a trivial example and couldn't reproduce symptoms of the hook
being executed twice.
This is with current sources and 7.8 (release and branch).
(gdb) define foo
echo Hi there.\n
end
(gdb) define hookpost-foo
echo Me again.\n
python gdb.execute("foo")
end
(gdb) foo
Hi there.
Me again.
Hi there.
(gdb)
> Additionally, I did not find how to access the arguments of the
> command.
I'm not sure what you mean here.
Access the arguments of the command from the hook?
I don't think we support that.
> 2) Overload the existing command with a python class binded on the
> same command name. Failed because of infinite recursion.
Infinite recursion because command -> hook -> command -> hook -> ...
or something else?
Just trying to understand if and how this is different from (1).
If it's easy, providing an example so that we can see it for ourselves
will help.
> 3) Use a named pipe to communicate. Failed (sort of) because one
> should sleep a variable amount of time waiting for the pipe to be
> consumed before returning to the prompt.
I don't understand how this relates to (1) and (2).
Communicate what between whom?