From patchwork Tue May 16 20:49:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20471 Received: (qmail 83892 invoked by alias); 16 May 2017 20:50:02 -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 83875 invoked by uid 89); 16 May 2017 20:50:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=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=Hx-spam-relays-external:sk:mail-wr, timeline, H*RU:sk:mail-wr, HX-HELO:sk:mail-wr X-HELO: mail-wr0-f179.google.com Received: from mail-wr0-f179.google.com (HELO mail-wr0-f179.google.com) (209.85.128.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 May 2017 20:50:00 +0000 Received: by mail-wr0-f179.google.com with SMTP id l50so83469907wrc.3 for ; Tue, 16 May 2017 13:50:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=JrCcunRMFkBWoncLEOKZdm4v/ZbPsK6Stt8ELgAT7P8=; b=sbSJImcFy4rZ4a+NC0oRJytaSHtF6RPbb52fE/SeabMRyiNwb/mxv2zjkAPiKORYp6 oLR5mmjF8yL0u5qw+IBPGtSSRC5Jy2/KCzkxbdxhUULhMTPBFeVn6pHFOoeFZTSvVQ2o L8vDy6N1nEsgv+GB3dpGnjxkWCSxHhu1F+KXJVSm7hv2OzzokTCQuao0JhrCg6pYq2pQ VbHrTt7IBF21j8G54LowtyfBcf/ABY4f/Q1GK8C5R+haxjO2WsmVDlhoHIPwJfBtHHhY HmjLccCXT10TCZaqE3W5Q/ghY+mxL9we8nN9w1ouIjdFPR6kbb8HgGhIb23SwbYpmS4y 5n7A== X-Gm-Message-State: AODbwcAkxicqLx1BjEpWOfL7OiGmOavM1OyKFzVawiQ4a2Wg81LACyFn KRxjdmuo2okaKg== X-Received: by 10.223.165.71 with SMTP id j7mr10728482wrb.35.1494967801281; Tue, 16 May 2017 13:50:01 -0700 (PDT) Received: from localhost ([2a02:c7d:8e8d:100:1dee:4877:4bfc:e432]) by smtp.gmail.com with ESMTPSA id x133sm10569493wme.0.2017.05.16.13.50.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 May 2017 13:50:00 -0700 (PDT) Date: Tue, 16 May 2017 21:49:54 +0100 From: Yao Qi To: Simon Marchi Cc: Joel Brobecker , gdb-patches@sourceware.org Subject: Re: GDB 7.99.91 available for testing Message-ID: <20170516204954.zbv35vjzsqa3qenf@localhost> References: <20170504194442.63AAF60B72@joel.gnat.com> <1f06c802305c02d92e0806b6174d7963@polymtl.ca> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1f06c802305c02d92e0806b6174d7963@polymtl.ca> User-Agent: NeoMutt/20161104 (1.7.1) X-IsSubscribed: yes On 17-05-16 09:51:42, Simon Marchi wrote: > > So indeed, the problem is due to the ordering of the _initialize functions > that changed, _initialize_printcmd used to be called before > _initialize_infcmd, now it's the reverse. > > When it works, the timeline of events to be able to get the tty alias > working is the following: > > 1. The "set" command is registered as a prefix command in printcmd.c, which > adds it to the global command list (cmdlist). setlist is the list of its > subcommands. > 2. The "set inferior-tty" command is added as a child of "set" (i.e. it's > inserted into setlist) in infcmd.c. > 3. The "tty" alias is created for "set inferior-tty" in infcmd.c. This > looks up "set" in cmdlist, then "inferior-tty" in the subcommands of "set". > It's found and everyone is happy. > > With the _initialize functions called in a different order, steps are > executed in the order 2-3-1. When we try to create the alias, the "set" > command has not been created and is therefore not part of cmdlist. We can't > find the "set inferior-tty" command, so the alias is not created. When we try to create the alias (in step 3), setlist is already created in step 2, but it is not linked with cmdlist. The command "set inferior-tty" is created in step 2 too. Since step 2 and step 3 are close to each other (in _initialize_infcmd), we can pass the "set inferior-tty" cmd_list_element to the place we create alias, like this, 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); this makes sure we add alias "tty" under cmdlist, and it is alias to "set inferior-tty". Step 1 just links setlist and cmdlist together. > > I think the core issue is that it's currently possible to create subcommands > for prefixes that have not been created yet. We need some way of ensuring > some kind of ordering. Here are some ideas: > How is the patch below? I run regress tests yet, and it still needs some comments. diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index d45733e..bec5e36 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,21 @@ 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,