From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30437 invoked by alias); 9 Mar 2011 11:15:26 -0000 Received: (qmail 30426 invoked by uid 22791); 9 Mar 2011 11:15:24 -0000 X-SWARE-Spam-Status: No, hits=-0.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-fx0-f41.google.com (HELO mail-fx0-f41.google.com) (209.85.161.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Mar 2011 11:15:16 +0000 Received: by fxm5 with SMTP id 5so424706fxm.0 for ; Wed, 09 Mar 2011 03:15:13 -0800 (PST) Received: by 10.223.81.79 with SMTP id w15mr4255424fak.12.1299669313849; Wed, 09 Mar 2011 03:15:13 -0800 (PST) Received: from [172.21.0.61] ([86.125.99.77]) by mx.google.com with ESMTPS id f16sm824187faa.14.2011.03.09.03.15.12 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Mar 2011 03:15:12 -0800 (PST) Message-ID: <4D776143.4000200@gmail.com> Date: Wed, 09 Mar 2011 12:35:00 -0000 From: Sorin Otescu User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [patch] Add support for hooking prefix commands Content-Type: multipart/mixed; boundary="------------050702080901090907010107" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00589.txt.bz2 This is a multi-part message in MIME format. --------------050702080901090907010107 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 641 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 * 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 --------------050702080901090907010107 Content-Type: text/x-patch; name="cli-script.c.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cli-script.c.patch" Content-length: 1986 --- 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."), --------------050702080901090907010107--