From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id F30D8385842F for ; Wed, 1 Dec 2021 16:41:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F30D8385842F X-ASG-Debug-ID: 1638376894-0c856e2e463ea1b0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id nnvzEdIF8TMw5kT1 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 01 Dec 2021 11:41:34 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 9E7FF441B21; Wed, 1 Dec 2021 11:41:34 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 1/3] gdb: use intrusive_list for cmd_list_element aliases list Date: Wed, 1 Dec 2021 11:41:31 -0500 X-ASG-Orig-Subj: [PATCH 1/3] gdb: use intrusive_list for cmd_list_element aliases list Message-Id: <20211201164133.686599-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1638376894 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 8352 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.94332 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2021 16:41:43 -0000 Change the manually-implemented linked list to use intrusive_list. This is not strictly necessary, but it makes the code much simpler. Change-Id: Idd08090ebf2db8bdcf68e85ef72a9635f1584ccc --- gdb/cli/cli-decode.c | 82 ++++++++++++++++++++------------------------ gdb/cli/cli-decode.h | 18 +++++++--- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 030cba443386..39f9eb54dc20 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -30,12 +30,10 @@ static void undef_cmd_error (const char *, const char *); -static struct cmd_list_element *delete_cmd (const char *name, - struct cmd_list_element **list, - struct cmd_list_element **prehook, - struct cmd_list_element **prehookee, - struct cmd_list_element **posthook, - struct cmd_list_element **posthookee); +static cmd_list_element::aliases_list_type 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); static struct cmd_list_element *find_cmd (const char *command, int len, @@ -171,20 +169,24 @@ 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) - iter->alias_target = c; + + for (cmd_list_element &alias : c->aliases) + alias.alias_target = c; + if (c->hook_pre) c->hook_pre->hookee_pre = c; + if (c->hookee_pre) c->hookee_pre->hook_pre = c; + if (c->hook_post) c->hook_post->hookee_post = c; + if (c->hookee_post) c->hookee_post->hook_post = c; @@ -195,7 +197,7 @@ do_add_cmd (const char *name, enum command_class theclass, } else { - p = *list; + cmd_list_element *p = *list; while (p->next && strcmp (p->next->name, name) <= 0) { p = p->next; @@ -296,8 +298,7 @@ add_alias_cmd (const char *name, cmd_list_element *target, c->allow_unknown = target->allow_unknown; c->abbrev_flag = abbrev_flag; c->alias_target = target; - c->alias_chain = target->aliases; - target->aliases = c; + target->aliases.push_front (*c); return c; } @@ -1195,14 +1196,13 @@ add_setshow_zuinteger_cmd (const char *name, command_class theclass, show_list); } -/* 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. Return the list + commands which were aliased to the deleted command. 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 struct cmd_list_element * +static cmd_list_element::aliases_list_type delete_cmd (const char *name, struct cmd_list_element **list, struct cmd_list_element **prehook, struct cmd_list_element **prehookee, @@ -1211,7 +1211,7 @@ 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; + cmd_list_element::aliases_list_type aliases; *prehook = NULL; *prehookee = NULL; @@ -1238,21 +1238,14 @@ delete_cmd (const char *name, struct cmd_list_element **list, /* Update the link. */ *previous_chain_ptr = iter->next; - aliases = iter->aliases; + aliases = std::move (iter->aliases); /* If this command was an alias, remove it from the list of aliases. */ if (iter->is_alias ()) { - struct cmd_list_element **prevp = &iter->alias_target->aliases; - struct cmd_list_element *a = *prevp; - - while (a != iter) - { - prevp = &a->alias_chain; - a = *prevp; - } - *prevp = iter->alias_chain; + auto it = iter->alias_target->aliases.iterator_to (*iter); + iter->alias_target->aliases.erase (it); } delete iter; @@ -1351,11 +1344,9 @@ static void fput_aliases_definition_styled (struct cmd_list_element *cmd, struct ui_file *stream) { - for (cmd_list_element *iter = cmd->aliases; - iter != nullptr; - iter = iter->alias_chain) - if (!iter->default_args.empty ()) - fput_alias_definition_styled (iter, stream); + for (cmd_list_element &alias : cmd->aliases) + if (!alias.default_args.empty ()) + fput_alias_definition_styled (&alias, stream); } @@ -1370,17 +1361,17 @@ fput_command_names_styled (struct cmd_list_element *c, bool always_fput_c_name, const char *postfix, struct ui_file *stream) { - if (always_fput_c_name || c->aliases != nullptr) + if (always_fput_c_name || !c->aliases.empty ()) fput_command_name_styled (c, stream); - for (cmd_list_element *iter = c->aliases; iter; iter = iter->alias_chain) + for (cmd_list_element &alias : c->aliases) { fputs_filtered (", ", stream); wrap_here (" "); - fput_command_name_styled (iter, stream); + fput_command_name_styled (&alias, stream); } - if (always_fput_c_name || c->aliases != nullptr) + if (always_fput_c_name || !c->aliases.empty ()) fputs_filtered (postfix, stream); } @@ -1453,14 +1444,15 @@ apropos_cmd (struct ui_file *stream, print_doc_of_command (c, prefix, verbose, regex, stream); /* Try to match against the name of the aliases. */ - for (cmd_list_element *iter = c->aliases; - returnvalue < 0 && iter; - iter = iter->alias_chain) + for (const cmd_list_element &alias : c->aliases) { - name_len = strlen (iter->name); - returnvalue = regex.search (iter->name, name_len, 0, name_len, NULL); + name_len = strlen (alias.name); + returnvalue = regex.search (alias.name, name_len, 0, name_len, NULL); if (returnvalue >= 0) - print_doc_of_command (c, prefix, verbose, regex, stream); + { + print_doc_of_command (c, prefix, verbose, regex, stream); + break; + } } } if (c->doc != NULL && returnvalue < 0) diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index f7945ba2bf5f..1d3a3db786ef 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -26,6 +26,7 @@ #include "gdb_regex.h" #include "cli-script.h" #include "completer.h" +#include "gdbsupport/intrusive_list.h" /* Not a set/show command. Note that some commands which begin with "set" or "show" might be in this category, if their syntax does @@ -246,11 +247,18 @@ struct cmd_list_element aliased command can be located in case it has been hooked. */ struct cmd_list_element *alias_target = nullptr; - /* Start of a linked list of all aliases of this command. */ - struct cmd_list_element *aliases = nullptr; - - /* Link pointer for aliases on an alias list. */ - struct cmd_list_element *alias_chain = nullptr; + /* Node to link aliases on an alias list. */ + using aliases_list_node_type + = intrusive_list_node; + aliases_list_node_type aliases_list_node; + + /* Linked list of all aliases of this command. */ + using aliases_list_member_node_type + = intrusive_member_node; + using aliases_list_type + = intrusive_list; + aliases_list_type aliases; /* If non-null, the pointer to a field in 'struct cli_suppress_notification', which will be set to true in cmd_func -- 2.33.1