From patchwork Wed May 17 11:31:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20475 Received: (qmail 74677 invoked by alias); 17 May 2017 11:31:44 -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 72584 invoked by uid 89); 17 May 2017 11:31:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pg0-f67.google.com Received: from mail-pg0-f67.google.com (HELO mail-pg0-f67.google.com) (74.125.83.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 May 2017 11:31:39 +0000 Received: by mail-pg0-f67.google.com with SMTP id h64so1498431pge.3 for ; Wed, 17 May 2017 04:31:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+XM9sBmtvU6LmmSL+VlFdnkXmmOah3gd41BOk90s+1o=; b=Kq3yUCe/jcT/7x6MGvYhW39hFfQsCkzzQLDWTSB/RwNe2+AHT0KAtHn6VWJvWP8zJC HDu2p3xno8ZL4/HyoQWmp6k7ISUQaIoDdsprnYXYMPvABFvWRGzaHPFyTpiJiZ9hMs0H XtT7LtTTkjcWuR1Jl8StqGnfoiFAD3dEb8pCXRrijQpazIqINSfxW9/gVKzZSXEeTA2C eoqKa21/ipn/saGZYKNnDPuGUaOWGuJqa0yXzmC0DCydxOlFW87Z/0MLR2E19ytXcT/j 6OGTDSoAdrqomUs8TIbHdzzkfcClUal8yuWJj+TquKEJdtybh0K5qDQusN2AAT524HCN eXog== X-Gm-Message-State: AODbwcBbghMQ8oH9kIUV4ZIrkF1BJweIjgO8JOYeGUP2X/cvjO3Is1WK /uXJF6SExSKOgrrv X-Received: by 10.99.53.12 with SMTP id c12mr2459048pga.38.1495020701359; Wed, 17 May 2017 04:31:41 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id 194sm3230971pgf.62.2017.05.17.04.31.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 May 2017 04:31:40 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Cc: simon.marchi@ericsson.com Subject: [PATCH master/8.0] Add alias command to cmd_list_element Date: Wed, 17 May 2017 12:31:37 +0100 Message-Id: <1495020697-13892-1-git-send-email-yao.qi@linaro.org> In-Reply-To: <20170516214007.ql53i6n5mz4nbpxp@localhost> References: <20170516214007.ql53i6n5mz4nbpxp@localhost> X-IsSubscribed: yes When we add alias command, we call add_alias_cmd and pass the alias name and command name. This implicitly requires the command and its prefix commands are already added to cmdlist. This may not be true, for example, add_com_alias ("tty", "set inferior-tty", class_alias, 0); "inferior-tty" command is added to setlist, but setlist may not be added to cmdlist (It depends on the order of related _initialize_XXX functions called) so that we can't find "set inferior-tty" from cmdlist. This patch fixes this problem by pass cmd_list_element of "inferior-tty" to add_alias_cmd, so that cmd_list_element of "inferior-tty" doesn't have to be reachable from cmdlist at that moment. Regression tested on x86_64-linux. gdb: 2017-05-17 Yao Qi * cli/cli-decode.c (add_alias_cmd): New function. * command.h (add_alias_cmd): Declare. * infcmd.c (_initialize_infcmd): Don't call add_com_alias, instead call add_alias_cmd. gdb/testsuite: 2017-05-17 Simon Marchi * gdb.base/set-inferior-tty.exp (test_set_inferior_tty): Add argument command. (top-level): Invoke test_set_inferior_tty. --- gdb/cli/cli-decode.c | 30 +++++++++++++++++++---------- gdb/command.h | 6 ++++++ gdb/infcmd.c | 5 ++++- gdb/testsuite/gdb.base/set-inferior-tty.exp | 10 ++++++---- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index d45733e..e1d257a 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -284,16 +284,10 @@ deprecate_cmd (struct cmd_list_element *cmd, const char *replacement) } struct cmd_list_element * -add_alias_cmd (const char *name, const char *oldname, enum command_class theclass, - int abbrev_flag, struct cmd_list_element **list) +add_alias_cmd (const char *name, cmd_list_element *old, + enum command_class theclass, int abbrev_flag, + struct cmd_list_element **list) { - const char *tmp; - struct cmd_list_element *old; - struct cmd_list_element *c; - - tmp = oldname; - old = lookup_cmd (&tmp, *list, "", 1, 1); - if (old == 0) { struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee; @@ -307,7 +301,7 @@ add_alias_cmd (const char *name, const char *oldname, enum command_class theclas return 0; } - c = add_cmd (name, theclass, NULL, old->doc, list); + struct cmd_list_element *c = add_cmd (name, theclass, NULL, old->doc, list); /* If OLD->DOC can be freed, we should make another copy. */ if (old->doc_allocated) @@ -330,6 +324,22 @@ add_alias_cmd (const char *name, const char *oldname, enum command_class theclas return c; } +struct cmd_list_element * +add_alias_cmd (const char *name, const char *oldname, + enum command_class theclass, int abbrev_flag, + struct cmd_list_element **list) +{ + const char *tmp; + struct cmd_list_element *old; + struct cmd_list_element *c; + + tmp = oldname; + old = lookup_cmd (&tmp, *list, "", 1, 1); + + return add_alias_cmd (name, old, theclass, abbrev_flag, list); +} + + /* Like add_cmd but adds an element for a command prefix: a name that should be followed by a subcommand to be looked up in another command list. PREFIXLIST should be the address of the variable diff --git a/gdb/command.h b/gdb/command.h index ae20021..aa179e9 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -141,6 +141,12 @@ extern struct cmd_list_element *add_alias_cmd (const char *, const char *, enum command_class, int, struct cmd_list_element **); +extern struct cmd_list_element *add_alias_cmd (const char *, + cmd_list_element *, + enum command_class, int, + struct cmd_list_element **); + + extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class, cmd_cfunc_ftype *fun, const char *, diff --git a/gdb/infcmd.c b/gdb/infcmd.c index f42c6d1..09060b5 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -3210,7 +3210,10 @@ is restored."), set_inferior_tty_command, show_inferior_tty_command, &setlist, &showlist); - add_com_alias ("tty", "set inferior-tty", class_alias, 0); + cmd_name = "inferior-tty"; + c = lookup_cmd (&cmd_name, setlist, "", -1, 1); + gdb_assert (c != NULL); + add_alias_cmd ("tty", c, class_alias, 0, &cmdlist); cmd_name = "args"; add_setshow_string_noescape_cmd (cmd_name, class_run, diff --git a/gdb/testsuite/gdb.base/set-inferior-tty.exp b/gdb/testsuite/gdb.base/set-inferior-tty.exp index d84d4a3..480cffa 100644 --- a/gdb/testsuite/gdb.base/set-inferior-tty.exp +++ b/gdb/testsuite/gdb.base/set-inferior-tty.exp @@ -21,20 +21,22 @@ if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == return -1 } -proc test_set_inferior_tty { } { +proc test_set_inferior_tty { command } { global binfile clean_restart ${binfile} - gdb_test_no_output "set inferior-tty hello" "set inferior-tty to hello" + gdb_test_no_output "$command hello" "set inferior-tty to hello" gdb_test "show inferior-tty" \ "Terminal for future runs of program being debugged is \"hello\"." \ "show inferior-tty shows hello" - gdb_test_no_output "set inferior-tty" "set inferior-tty to empty" + gdb_test_no_output "$command" "set inferior-tty to empty" gdb_test "show inferior-tty" \ "Terminal for future runs of program being debugged is \"\"." \ "show inferior-tty shows empty" } -test_set_inferior_tty +foreach_with_prefix command {"set inferior-tty" "tty"} { + test_set_inferior_tty $command +}