This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Define python hooks
- From: nojhan <nojhan at nojhan dot net>
- To: gdb <gdb at sourceware dot org>
- Date: Tue, 28 Oct 2014 14:17:56 +0100
- 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>
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.
Additionally, I did not find how to access the arguments of the
command.
2) Overload the existing command with a python class binded on the
same command name. Failed because of infinite recursion.
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.
Should I fill a feature request/bug report for points 1 and/or 2?
--
nojhan
On Tue, Oct 28, 2014 at 12:22 AM, Doug Evans <xdje42@gmail.com> wrote:
> gdb.execute (command, to_string=True) will return the output as a python string.
>
> As for what's the best way to go, I'm not sure.
>
> On Mon, Oct 27, 2014 at 2:17 AM, nojhan <nojhan@nojhan.net> wrote:
>> Thanks.
>> I would want to manipulate the output of several existing commands with python.
>>
>> Is there a way to get the output of the command in python (something
>> like a gdb.execute that would return the output)?
>> Or should I use a redirection to a named pipe to communicate with gdb?
>> Or maybe it would be a better option to overload existing commands
>> with a python class that would execute them?
>>
>> --
>> nojhan
>>
>> On Sun, Oct 26, 2014 at 12:57 AM, Doug Evans <xdje42@gmail.com> wrote:
>>> On Sat, Oct 25, 2014 at 2:08 AM, nojhan <nojhan@nojhan.net> wrote:
>>>> Hello,
>>>>
>>>> I'm currently using several of hook-* and hookpost-* functions with
>>>> shell commands.
>>>> I was wondering if there was a way to define such hooks in pure python.
>>>>
>>>> For instance, I would like to import a module at startup and use it
>>>> across all the hooks to manipulate the output of the hooked commands.
>>>
>>> Hi.
>>>
>>> While one can't directly define hooks in python, one can still invoke
>>> python from hooks.
>>>
>>> E.g.
>>>
>>> define hookpost-step
>>> python
>>> ... python code ...
>>> end
>>> end