From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78159 invoked by alias); 17 May 2017 13:36:51 -0000 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 Received: (qmail 78089 invoked by uid 89); 17 May 2017 13:36:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 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-pf0-f195.google.com Received: from mail-pf0-f195.google.com (HELO mail-pf0-f195.google.com) (209.85.192.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 May 2017 13:36:46 +0000 Received: by mail-pf0-f195.google.com with SMTP id f27so1806428pfe.0 for ; Wed, 17 May 2017 06:36:49 -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:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=8nKlZxSuYyctNt4+uaLOr55lMvF/+Y39TKYI4K57V0Q=; b=Ile60MrchTU6MCTPc8SYkYcqkkKnHwRYoqsQa9+r2CMZiY42U7R/GGX/4ew1myuxZG dreUR78iYaTpuxDSr7DAG0lzxDidm/P67NQ7UoVDRF0XIQw9/3NVFXB4ZCi7FOnWjJoo gEThVHFI6aKMRS8JkQIR6qt0OYWRqhFu0APM047YVLY7tL6HCHdeoT0TZUOTJa0jqMqV uhDyCcUANWwapE1KQLGGnElKyINjpeicN4/sx3cJlQe2VVok+ylOcKgGhBAPPYLpqaQ8 UbUhIluhDdnWPfHHKoJ1TdU6YsSRp+YY82C1Lsiqn56zKsM5zGrC8d0shBFUEdGf9RQO 2sTw== X-Gm-Message-State: AODbwcC2gJ7PfQ100wLDl05VfSiFrk9g4e21azqzxNHoXvSofWDkcZpK dmcF+IwCzAy8HQ== X-Received: by 10.84.130.67 with SMTP id 61mr4451320plc.150.1495028207961; Wed, 17 May 2017 06:36:47 -0700 (PDT) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id m24sm4098401pfi.129.2017.05.17.06.36.45 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 17 May 2017 06:36:47 -0700 (PDT) From: Yao Qi To: Simon Marchi Cc: gdb-patches@sourceware.org, simon.marchi@ericsson.com Subject: Re: [PATCH master/8.0] Add alias command to cmd_list_element References: <20170516214007.ql53i6n5mz4nbpxp@localhost> <1495020697-13892-1-git-send-email-yao.qi@linaro.org> <0d03dc5b2bba05ef0a4e50b087b22f92@polymtl.ca> Date: Wed, 17 May 2017 13:36:00 -0000 In-Reply-To: <0d03dc5b2bba05ef0a4e50b087b22f92@polymtl.ca> (Simon Marchi's message of "Wed, 17 May 2017 08:16:28 -0400") Message-ID: <86shk38v10.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg00390.txt.bz2 Simon Marchi writes: Hi Simon, Thanks for the quick review. >> This patch fixes this problem by pass cmd_list_element of >> "inferior-tty" > > "by passing" > Fixed. >> +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; > > c is now unused. Removed. > > Otherwise, LGTM. Thanks! Patch below is pushed to both master and 8.0 branch. --=20 Yao (=E9=BD=90=E5=B0=A7) From: Yao Qi Date: Wed, 17 May 2017 14:22:04 +0100 Subject: [PATCH] Add alias command to cmd_list_element 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 passing 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. 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. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f2068d2..fdc2a40 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +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. + 2017-05-17 Pedro Alves =20 * Makefile.in (nat_extra_makefile_frag): Rename to ... diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index d45733e..d386d02 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 ch= ar *replacement) } =20 struct cmd_list_element * -add_alias_cmd (const char *name, const char *oldname, enum command_class t= heclass, - 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 =3D oldname; - old =3D lookup_cmd (&tmp, *list, "", 1, 1); - if (old =3D=3D 0) { struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee; @@ -307,7 +301,7 @@ add_alias_cmd (const char *name, const char *oldname, e= num command_class theclas return 0; } =20 - c =3D add_cmd (name, theclass, NULL, old->doc, list); + struct cmd_list_element *c =3D add_cmd (name, theclass, NULL, old->doc, = list); =20 /* If OLD->DOC can be freed, we should make another copy. */ if (old->doc_allocated) @@ -330,6 +324,21 @@ add_alias_cmd (const char *name, const char *oldname, = enum command_class theclas return c; } =20 +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; + + tmp =3D oldname; + old =3D 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 c= har *, const char *, enum command_class, int, struct cmd_list_element **); =20 +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 =3D "inferior-tty"; + c =3D lookup_cmd (&cmd_name, setlist, "", -1, 1); + gdb_assert (c !=3D NULL); + add_alias_cmd ("tty", c, class_alias, 0, &cmdlist); =20 cmd_name =3D "args"; add_setshow_string_noescape_cmd (cmd_name, class_run, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b672df3..91712e2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +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. + 2017-05-04 Pedro Alves =20 * gdb.python/py-record-btrace-threads.exp (check_insn_for_thread): diff --git a/gdb/testsuite/gdb.base/set-inferior-tty.exp b/gdb/testsuite/gd= b.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}] =3D=3D return -1 } =20 -proc test_set_inferior_tty { } { +proc test_set_inferior_tty { command } { global binfile =20 clean_restart ${binfile} =20 - 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" =20 - 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" } =20 -test_set_inferior_tty +foreach_with_prefix command {"set inferior-tty" "tty"} { + test_set_inferior_tty $command +}