* [patch] Add support for hooking prefix commands
@ 2011-03-09 12:35 Sorin Otescu
2011-03-09 12:58 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Sorin Otescu @ 2011-03-09 12:35 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 641 bytes --]
Hi all,
I recently needed to add a hook for the "info threads" command.
Unfortunately, this was not possible because GDB only allows hooking of
single word commands.
This patch adds support for multi-word command (prefix command) hooks.
In my case, the format of the hook commands is:
define hook-info_threads
define hookpost-info_threads
Sorin
gdb/cli/
2011-03-09 Sorin Otescu<sorinu@gmail.com>
* cli-script.c (define_command): Add support for hooking prefix commands.
Example usage: for hooking "info threads", a hook command will be defined as:
define hook-info_threads and/or define hookpost-info_threads
[-- Attachment #2: cli-script.c.patch --]
[-- Type: text/x-patch, Size: 1986 bytes --]
--- cli-script.c.orig 2010-05-17 22:28:12.000000000 +0300
+++ cli-script.c 2011-03-09 11:37:04.917093842 +0200
@@ -1416,8 +1350,9 @@
CMD_POST_HOOK
};
struct command_line *cmds;
- struct cmd_list_element *c, *newc, *hookc = 0, **list;
- char *tem, *comfull;
+ struct cmd_list_element *c, *newc, *hookc = 0, **list;
+ char *tem, *tem2, *comfull;
+ char tembuf[MAX_TMPBUF];
char tmpbuf[MAX_TMPBUF];
int hook_type = CMD_NO_HOOK;
int hook_name_size = 0;
--- cli-script.c.orig 2010-05-17 22:28:12.000000000 +0300
+++ cli-script.c 2011-03-09 11:37:04.917093842 +0200
@@ -1430,8 +1365,11 @@
comfull = comname;
list = validate_comname (&comname);
+ strncpy(tembuf, comname, MAX_TMPBUF);
+ tembuf[MAX_TMPBUF-1] = 0;
+
/* Look it up, and verify that we got an exact match. */
- tem = comname;
+ tem = tembuf;
c = lookup_cmd (&tem, *list, "", -1, 1);
if (c && strcmp (comname, c->name) != 0)
c = 0;
--- cli-script.c.orig 2010-05-17 22:28:12.000000000 +0300
+++ cli-script.c 2011-03-09 11:37:04.917093842 +0200
@@ -1465,11 +1402,26 @@
if (hook_type != CMD_NO_HOOK)
{
+ /* Convert _ characters into spaces, to allow hooking prefix commands */
+ tem = tembuf + hook_name_size;
+ tem2 = strchr(tem, '_');
+ while (tem2)
+ {
+ *tem2 = ' ';
+ tem2 = strchr(tem2+1, '_');
+ }
+
/* Look up cmd it hooks, and verify that we got an exact match. */
- tem = comname + hook_name_size;
hookc = lookup_cmd (&tem, *list, "", -1, 0);
- if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0)
+ while (hookc && *tem)
+ {
+ /* tem might point to the argument of a prefix command */
+ if (hookc->prefixlist)
+ hookc = lookup_cmd (&tem, *hookc->prefixlist, "", -1, 0);
+ else
hookc = 0;
+ }
+
if (!hookc)
{
warning (_("Your new `%s' command does not hook any existing command."),
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 12:35 [patch] Add support for hooking prefix commands Sorin Otescu
@ 2011-03-09 12:58 ` Eli Zaretskii
2011-03-09 13:36 ` Sorin Otescu
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2011-03-09 12:58 UTC (permalink / raw)
To: Sorin Otescu; +Cc: gdb-patches
> Date: Wed, 09 Mar 2011 13:15:15 +0200
> From: Sorin Otescu <sorinu@gmail.com>
>
> I recently needed to add a hook for the "info threads" command.
> Unfortunately, this was not possible because GDB only allows hooking of
> single word commands.
> This patch adds support for multi-word command (prefix command) hooks.
> In my case, the format of the hook commands is:
Thanks.
> define hook-info_threads
> define hookpost-info_threads
Can we have underscore characters in commands? If so, this
implementation would defeat hooking them.
Anyway, if this is accepted, please write a short patch for the manual
as well.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 12:58 ` Eli Zaretskii
@ 2011-03-09 13:36 ` Sorin Otescu
2011-03-09 14:01 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Sorin Otescu @ 2011-03-09 13:36 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On 03/09/2011 02:40 PM, Eli Zaretskii wrote:
>> Date: Wed, 09 Mar 2011 13:15:15 +0200
>> From: Sorin Otescu<sorinu@gmail.com>
>>
>> I recently needed to add a hook for the "info threads" command.
>> Unfortunately, this was not possible because GDB only allows hooking of
>> single word commands.
>> This patch adds support for multi-word command (prefix command) hooks.
>> In my case, the format of the hook commands is:
> Thanks.
>
>> define hook-info_threads
>> define hookpost-info_threads
> Can we have underscore characters in commands? If so, this
> implementation would defeat hooking them.
>
It is possible to define commands containing underscores, but none of
the built-in commands
contain any (they all use dash).
> Anyway, if this is accepted, please write a short patch for the manual
> as well.
>
The documentation for 7.2 suggests this functionality is already there;
the difference is that
you need to hook the last word of the command (in this case,
hook-threads). I wonder if
that's enough / better... This patch was generated from 7.0 and adapted
to 7.2.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 13:36 ` Sorin Otescu
@ 2011-03-09 14:01 ` Eli Zaretskii
2011-03-09 14:03 ` Sorin Otescu
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2011-03-09 14:01 UTC (permalink / raw)
To: Sorin Otescu; +Cc: gdb-patches
> Date: Wed, 09 Mar 2011 14:54:44 +0200
> From: Sorin Otescu <sorinu@gmail.com>
> CC: gdb-patches@sourceware.org
>
> > Can we have underscore characters in commands? If so, this
> > implementation would defeat hooking them.
> >
> It is possible to define commands containing underscores, but none of
> the built-in commands
> contain any (they all use dash).
That could be a problem. What do others think?
> > Anyway, if this is accepted, please write a short patch for the manual
> > as well.
> >
> The documentation for 7.2 suggests this functionality is already there;
> the difference is that
> you need to hook the last word of the command (in this case,
> hook-threads). I wonder if
> that's enough / better... This patch was generated from 7.0 and adapted
> to 7.2.
Are you saying that 7.2 already supports this feature? Or are you
saying that it's documented there, but doesn't work?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 14:01 ` Eli Zaretskii
@ 2011-03-09 14:03 ` Sorin Otescu
2011-03-09 14:15 ` Eli Zaretskii
2011-03-09 14:22 ` Eli Zaretskii
0 siblings, 2 replies; 8+ messages in thread
From: Sorin Otescu @ 2011-03-09 14:03 UTC (permalink / raw)
To: gdb-patches
On 03/09/2011 03:39 PM, Eli Zaretskii wrote:
>> Date: Wed, 09 Mar 2011 14:54:44 +0200
>> From: Sorin Otescu<sorinu@gmail.com>
>> CC: gdb-patches@sourceware.org
>>
>>> Can we have underscore characters in commands? If so, this
>>> implementation would defeat hooking them.
>>>
>> It is possible to define commands containing underscores, but none of
>> the built-in commands
>> contain any (they all use dash).
> That could be a problem. What do others think?
>
>>> Anyway, if this is accepted, please write a short patch for the manual
>>> as well.
>>>
>> The documentation for 7.2 suggests this functionality is already there;
>> the difference is that
>> you need to hook the last word of the command (in this case,
>> hook-threads). I wonder if
>> that's enough / better... This patch was generated from 7.0 and adapted
>> to 7.2.
> Are you saying that 7.2 already supports this feature? Or are you
> saying that it's documented there, but doesn't work?
>
It's documented there, but I can't test it ATM, because I'm using a gdb
from a toolchain and it's not
easy for me to switch to 7.2. Maybe somebody can shed a light on the issue.
I see some problems with that approach, even if it works. What happens
if two or more commands
have the same second word ? Which one would be used ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 14:03 ` Sorin Otescu
@ 2011-03-09 14:15 ` Eli Zaretskii
2011-03-09 14:22 ` Eli Zaretskii
1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2011-03-09 14:15 UTC (permalink / raw)
To: Sorin Otescu; +Cc: gdb-patches
> Date: Wed, 09 Mar 2011 15:54:41 +0200
> From: Sorin Otescu <sorinu@gmail.com>
>
> I see some problems with that approach, even if it works. What happens
> if two or more commands
> have the same second word ? Which one would be used ?
I see no problem. For hooking "target remote" you'd say
define target hook-remote
and for hooking "foo remote" you'd say
define foo hook-remote
This is what the manual says.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 14:03 ` Sorin Otescu
2011-03-09 14:15 ` Eli Zaretskii
@ 2011-03-09 14:22 ` Eli Zaretskii
2011-03-09 15:08 ` Sorin Otescu
1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2011-03-09 14:22 UTC (permalink / raw)
To: Sorin Otescu; +Cc: gdb-patches
> Date: Wed, 09 Mar 2011 15:54:41 +0200
> From: Sorin Otescu <sorinu@gmail.com>
>
> > Are you saying that 7.2 already supports this feature? Or are you
> > saying that it's documented there, but doesn't work?
> >
> It's documented there, but I can't test it ATM, because I'm using a gdb
> from a toolchain and it's not
> easy for me to switch to 7.2. Maybe somebody can shed a light on the issue.
I just tried this (with "info breakpoints") in GDB 7.2, and it worked
for me.
So I think you should upgrade when you can, and then you will have
this feature.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] Add support for hooking prefix commands
2011-03-09 14:22 ` Eli Zaretskii
@ 2011-03-09 15:08 ` Sorin Otescu
0 siblings, 0 replies; 8+ messages in thread
From: Sorin Otescu @ 2011-03-09 15:08 UTC (permalink / raw)
To: gdb-patches
On 03/09/2011 04:03 PM, Eli Zaretskii wrote:
>> Date: Wed, 09 Mar 2011 15:54:41 +0200
>> From: Sorin Otescu<sorinu@gmail.com>
>>
>>> Are you saying that 7.2 already supports this feature? Or are you
>>> saying that it's documented there, but doesn't work?
>>>
>> It's documented there, but I can't test it ATM, because I'm using a gdb
>> from a toolchain and it's not
>> easy for me to switch to 7.2. Maybe somebody can shed a light on the issue.
> I just tried this (with "info breakpoints") in GDB 7.2, and it worked
> for me.
>
> So I think you should upgrade when you can, and then you will have
> this feature.
>
Thanks ! That's what you get for using obsolete software and not RTFM :)
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-03-09 14:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-09 12:35 [patch] Add support for hooking prefix commands Sorin Otescu
2011-03-09 12:58 ` Eli Zaretskii
2011-03-09 13:36 ` Sorin Otescu
2011-03-09 14:01 ` Eli Zaretskii
2011-03-09 14:03 ` Sorin Otescu
2011-03-09 14:15 ` Eli Zaretskii
2011-03-09 14:22 ` Eli Zaretskii
2011-03-09 15:08 ` Sorin Otescu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox