From patchwork Wed May 22 20:53:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 32811 Received: (qmail 130727 invoked by alias); 22 May 2019 20:53:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 130515 invoked by uid 89); 22 May 2019 20:53:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 May 2019 20:53:44 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1BB3F63162 for ; Wed, 22 May 2019 20:53:43 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 987341001E67 for ; Wed, 22 May 2019 20:53:42 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 15/24] Introduce rename_cmd Date: Wed, 22 May 2019 21:53:18 +0100 Message-Id: <20190522205327.2568-16-palves@redhat.com> In-Reply-To: <20190522205327.2568-1-palves@redhat.com> References: <20190522205327.2568-1-palves@redhat.com> A following patch will introduce options for the "backtrace" command, based on some "set print" and "set backtrace" settings. There's one setting in particular that is a bit annoying if we want to describe the backtrace options and the settings commands using the same data structures: "set print raw frame-arguments" The problem is that space between "raw" and "frame-arguments". Calling the option "bt -raw frame-arguments" would be odd. So I'm calling the option "bt -raw-frame-arguments" instead. IMO, It would be better if the setting was called "set print raw-frame-arguments" instead too, but that ship might have sailed already. This is the only odd case I found so far, so I'm handling this by describing the option/setting as "raw-frame-arguments" in the option_def, and then renaming the set command. Hence this commit, which includes the new rename_cmd function. It'll then be used by the "backtrace" patch. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * cli/cli-decode.c (insert_cmd): New, factored out from ... (do_add_cmd): ... this. (unlink_cmd): New, factored out from ... (delete_cmd): ... this. Reimplement. (rename_cmd): New. * command.h (rename_cmd): Declare. --- gdb/cli/cli-decode.c | 104 +++++++++++++++++++++++++++++++++++---------------- gdb/command.h | 5 +++ 2 files changed, 77 insertions(+), 32 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index be38d9b287a..1a6bea41480 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -171,6 +171,27 @@ set_cmd_completer_handle_brkchars (struct cmd_list_element *cmd, cmd->completer_handle_brkchars = func; } + +/* Insert element C in LIST. */ + +static void +insert_cmd (cmd_list_element *c, cmd_list_element **list) +{ + if (*list == NULL || strcmp ((*list)->name, c->name) >= 0) + { + c->next = *list; + *list = c; + } + else + { + cmd_list_element *p = *list; + while (p->next && strcmp (p->next->name, c->name) <= 0) + p = p->next; + c->next = p->next; + p->next = c; + } +} + /* Add element named NAME. Space for NAME and DOC must be allocated by the caller. CLASS is the top level category into which commands are broken down @@ -195,13 +216,12 @@ do_add_cmd (const char *name, enum command_class theclass, { struct cmd_list_element *c = new struct cmd_list_element (name, theclass, doc); - struct cmd_list_element *p, *iter; /* Turn each alias of the old command into an alias of the new command. */ c->aliases = delete_cmd (name, list, &c->hook_pre, &c->hookee_pre, &c->hook_post, &c->hookee_post); - for (iter = c->aliases; iter; iter = iter->alias_chain) + for (cmd_list_element *iter = c->aliases; iter; iter = iter->alias_chain) iter->cmd_pointer = c; if (c->hook_pre) c->hook_pre->hookee_pre = c; @@ -212,22 +232,7 @@ do_add_cmd (const char *name, enum command_class theclass, if (c->hookee_post) c->hookee_post->hook_post = c; - if (*list == NULL || strcmp ((*list)->name, name) >= 0) - { - c->next = *list; - *list = c; - } - else - { - p = *list; - while (p->next && strcmp (p->next->name, name) <= 0) - { - p = p->next; - } - c->next = p->next; - p->next = c; - } - + insert_cmd (c, list); return c; } @@ -851,15 +856,13 @@ add_setshow_zuinteger_cmd (const char *name, enum command_class theclass, set_cmd_completer (show, nullptr); } -/* Remove the command named NAME from the command list. Return the - list commands which were aliased to the deleted command. If the - command had no aliases, return NULL. The various *HOOKs are set to - the pre- and post-hook commands for the deleted command. If the - command does not have a hook, the corresponding out parameter is - set to NULL. */ +/* Remove the command named NAME from the command list, and return it. + The various *HOOKs are set to the pre- and post-hook commands for + the removed command. If the command does not have a hook, the + corresponding out parameter is set to NULL. */ -static struct cmd_list_element * -delete_cmd (const char *name, struct cmd_list_element **list, +static cmd_list_element * +unlink_cmd (const char *name, struct cmd_list_element **list, struct cmd_list_element **prehook, struct cmd_list_element **prehookee, struct cmd_list_element **posthook, @@ -867,7 +870,6 @@ delete_cmd (const char *name, struct cmd_list_element **list, { struct cmd_list_element *iter; struct cmd_list_element **previous_chain_ptr; - struct cmd_list_element *aliases = NULL; *prehook = NULL; *prehookee = NULL; @@ -893,8 +895,6 @@ delete_cmd (const char *name, struct cmd_list_element **list, /* Update the link. */ *previous_chain_ptr = iter->next; - aliases = iter->aliases; - /* If this command was an alias, remove it from the list of aliases. */ if (iter->cmd_pointer) @@ -910,17 +910,57 @@ delete_cmd (const char *name, struct cmd_list_element **list, *prevp = iter->alias_chain; } - delete iter; - /* We won't see another command with the same name. */ - break; + return iter; } else previous_chain_ptr = &iter->next; } + return nullptr; +} + +/* Remove the command named NAME from the command list and delete it. + Return the list commands which were aliased to the deleted command. + If the command had no aliases, return NULL. The various *HOOKs are + set to the pre- and post-hook commands for the deleted command. If + the command does not have a hook, the corresponding out parameter + is set to NULL. */ + +static cmd_list_element * +delete_cmd (const char *name, cmd_list_element **list, + cmd_list_element **prehook, + cmd_list_element **prehookee, + cmd_list_element **posthook, + cmd_list_element **posthookee) +{ + cmd_list_element *cmd = unlink_cmd (name, list, + prehook, prehookee, + posthook, posthookee); + if (cmd == nullptr) + return nullptr; + + cmd_list_element *aliases = cmd->aliases; + delete cmd; return aliases; } + +/* See command.h. */ + +void +rename_cmd (const char *old_name, cmd_list_element **old_list, + const char *new_name, cmd_list_element **new_list) +{ + cmd_list_element *prehook, *prehookee, *posthook, *posthookee; + cmd_list_element *c = unlink_cmd (old_name, old_list, + &prehook, &prehookee, + &posthook, &posthookee); + + c->name = new_name; + insert_cmd (c, new_list); + set_cmd_prefix (c, new_list); +} + /* Shorthands to the commands above. */ diff --git a/gdb/command.h b/gdb/command.h index 35006cc339e..ed848114b85 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -439,6 +439,11 @@ extern void struct cmd_list_element **set_list, struct cmd_list_element **show_list); +/* Move command OLD_NAME from OLD_LIST to NEW_LIST and rename it from + OLD_NAME to NEW_NAME. */ +extern void rename_cmd (const char *old_name, cmd_list_element **old_list, + const char *new_name, cmd_list_element **new_list); + /* Do a "show" command for each thing on a command list. */ extern void cmd_show_list (struct cmd_list_element *, int, const char *);