aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-17 14:01:20 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-17 14:01:20 -0400
commit1be99b11f8d1a8fd4049fee1c0eeaef73b3e6d1d (patch)
tree01897c887dc34c9be242b85d95adce5a5787a96e /gdb/cli
parent9985872497e2b8c86424fcb97cd9a065f406a5c5 (diff)
downloadgdb-1be99b11f8d1a8fd4049fee1c0eeaef73b3e6d1d.zip
gdb-1be99b11f8d1a8fd4049fee1c0eeaef73b3e6d1d.tar.gz
gdb-1be99b11f8d1a8fd4049fee1c0eeaef73b3e6d1d.tar.bz2
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) <is_alias>: New, use it. Change-Id: I26ed56f99ee47fe884fdfedf87016501631693ce
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-decode.c18
-rw-r--r--gdb/cli/cli-decode.h4
-rw-r--r--gdb/cli/cli-setshow.c4
3 files changed, 15 insertions, 11 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index ec579ff..29b4ed2 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 68a9b85..8caf602 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 cb821c5..7e93a70 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");