From: Simon Marchi Date: Mon, 17 May 2021 18:01:20 +0000 (-0400) Subject: gdb: add cmd_list_element::is_alias X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1be99b11f8d1a8fd4049fee1c0eeaef73b3e6d1d;p=binutils-gdb.git gdb: add cmd_list_element::is_alias Add the cmd_list_element::is_alias helper to check whether a command is an alias. I find it easier to understand the intention in: if (c->is_alias ()) than if (c->alias_target != nullptr) Change all the spots that are reading alias_target just to compare it to NULL/nullptr to use is_alias instead. gdb/ChangeLog: * cli/cli-decode.h (cmd_list_element) : New, use it. Change-Id: I26ed56f99ee47fe884fdfedf87016501631693ce --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e4305063733..b39879fcd5b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2021-05-17 Simon Marchi + + * cli/cli-decode.h (cmd_list_element) : New, use it. + 2021-05-17 Simon Marchi * cli/cli-decode.h (cmd_list_element) : Rename diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index ec579ff1961..29b4ed2f6bd 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -75,7 +75,7 @@ lookup_cmd_with_subcommands (cmd_list_element **subcommands, { /* If we found an alias, we must return the aliased command. */ - return p->alias_target ? p->alias_target : p; + return p->is_alias () ? p->alias_target : p; } q = lookup_cmd_with_subcommands (subcommands, *(p->subcommands)); @@ -405,7 +405,7 @@ static void do_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c) { /* Look past all aliases. */ - while (c->alias_target != nullptr) + while (c->is_alias ()) c = c->alias_target; help_list (*c->subcommands, c->prefixname ().c_str (), @@ -948,7 +948,7 @@ delete_cmd (const char *name, struct cmd_list_element **list, /* If this command was an alias, remove it from the list of aliases. */ - if (iter->alias_target) + if (iter->is_alias ()) { struct cmd_list_element **prevp = &iter->alias_target->aliases; struct cmd_list_element *a = *prevp; @@ -1043,7 +1043,7 @@ static void fput_alias_definition_styled (struct cmd_list_element *c, struct ui_file *stream) { - gdb_assert (c->alias_target != nullptr); + gdb_assert (c->is_alias ()); fputs_filtered (" alias ", stream); fput_command_name_styled (c, stream); fprintf_filtered (stream, " = "); @@ -1146,7 +1146,7 @@ apropos_cmd (struct ui_file *stream, /* Walk through the commands. */ for (c=commandlist;c;c=c->next) { - if (c->alias_target != nullptr) + if (c->is_alias ()) { /* Command aliases/abbreviations are skipped to ensure we print the doc of a command only once, when encountering the aliased @@ -1487,7 +1487,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass, continue; } - if (c->alias_target != nullptr && theclass != class_alias) + if (c->is_alias () && theclass != class_alias) { /* Do not show an alias, unless specifically showing the list of aliases: for all other classes, an alias is @@ -1509,7 +1509,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass, list of sub-commands of the aliased command. */ print_help_for_command (c, - recurse && (theclass != class_alias || c->alias_target == nullptr), + recurse && (theclass != class_alias || !c->is_alias ()), stream); continue; } @@ -1672,7 +1672,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist, *text += len; - if (found->alias_target) + if (found->is_alias ()) { /* We drop the alias (abbreviation) in favor of the command it is pointing to. If the alias is deprecated, though, we need to @@ -2044,7 +2044,7 @@ lookup_cmd_composition_1 (const char *text, return 0; else { - if ((*cmd)->alias_target) + if ((*cmd)->is_alias ()) { /* If the command was actually an alias, we note that an alias was used (by assigning *ALIAS) and we set *CMD. */ diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index 68a9b8586b4..8caf6023454 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -79,6 +79,10 @@ struct cmd_list_element For non-prefix commands, return an empty string. */ std::string prefixname () const; + /* Return true if this command is an alias of another command. */ + bool is_alias () const + { return this->alias_target != nullptr; } + /* Points to next command in this list. */ struct cmd_list_element *next = nullptr; diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index cb821c5b3c0..7e93a703494 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -740,7 +740,7 @@ cmd_show_list (struct cmd_list_element *list, int from_tty) /* If we find a prefix, run its list, prefixing our output by its prefix (with "show " skipped). */ - if (list->subcommands && list->alias_target == nullptr) + if (list->subcommands && !list->is_alias ()) { ui_out_emit_tuple optionlist_emitter (uiout, "optionlist"); std::string prefixname = list->prefixname (); @@ -750,7 +750,7 @@ cmd_show_list (struct cmd_list_element *list, int from_tty) uiout->field_string ("prefix", new_prefix); cmd_show_list (*list->subcommands, from_tty); } - else if (list->theclass != no_set_class && list->alias_target == nullptr) + else if (list->theclass != no_set_class && !list->is_alias ()) { ui_out_emit_tuple option_emitter (uiout, "option"); diff --git a/gdb/unittests/command-def-selftests.c b/gdb/unittests/command-def-selftests.c index 123667d3369..4a6b6789b37 100644 --- a/gdb/unittests/command-def-selftests.c +++ b/gdb/unittests/command-def-selftests.c @@ -155,7 +155,7 @@ traverse_command_structure (struct cmd_list_element **list, { /* If this command has subcommands and is not an alias, traverse the subcommands. */ - if (c->subcommands != NULL && c->alias_target == nullptr) + if (c->subcommands != NULL && !c->is_alias ()) { /* Recursively call ourselves on the subcommand list, passing the right prefix in. */