From: Sorin Otescu <sorinu@gmail.com>
To: gdb-patches@sourceware.org
Subject: [patch] Add support for hooking prefix commands
Date: Wed, 09 Mar 2011 12:35:00 -0000 [thread overview]
Message-ID: <4D776143.4000200@gmail.com> (raw)
[-- 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."),
next reply other threads:[~2011-03-09 11:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-09 12:35 Sorin Otescu [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D776143.4000200@gmail.com \
--to=sorinu@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox