aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2020-05-10 20:21:51 +0200
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2020-05-15 22:17:45 +0200
commit7c05caf72d31d7382819f1113fdcf13c45729a8d (patch)
tree4baa0c3c7e840e40efa84c744ae591b3aac88de5 /gdb/cli
parent3b3aaacba15292f185b6e8ba5faba1ed89c9f908 (diff)
downloadgdb-7c05caf72d31d7382819f1113fdcf13c45729a8d.zip
gdb-7c05caf72d31d7382819f1113fdcf13c45729a8d.tar.gz
gdb-7c05caf72d31d7382819f1113fdcf13c45729a8d.tar.bz2
Fix/improve 'apropos' output
Similarly to 'help CLASS', apropos possibly shows several times the same help (for the command and for each of its aliases). This patch changes 'apropos' so that the help for a command and all its aliases is shown once. So, apropos_cmd now skips all aliases/abbreviations, as these are printed as part of the help of the aliased command. When 'apropos' prints the help of a command, function 'help_cmd' now unconditionally print the command name and its possible aliases (as we must indicate to the user the command/aliases for which the help is printed). When 'help somecommand' prints the help of a command, if the command is not aliased, the command name is not printed (to avoid a useless first line), but if it has aliases, then the command name and all its aliases are now printed. In addition to provide to the user the choice of the best way to type a command, it also avoids the strange behaviour that the output of 'help somealias' does not mention somealias. gdb/ChangeLog 2020-05-15 Philippe Waroquiers <philippe.waroquiers@skynet.be> * cli/cli-decode.c (apropos_cmd): Produce output for aliases when their aliased command is traversed. (help_cmd): Add fput_command_names_styled call to output command name and aliases when command has an alias. gdb/testsuite/ChangeLog 2020-05-15 Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.base/help.exp: Test apropos and help for commands having aliases. Fixed comments not starting with an upper-case letter or not finishing with a dot.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-decode.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 093692e..2b24e57 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1078,9 +1078,7 @@ print_doc_of_command (struct cmd_list_element *c, const char *prefix,
if (verbose)
fputs_filtered ("\n", stream);
- fprintf_styled (stream, title_style.style (),
- "%s%s", prefix, c->name);
- fputs_filtered (" -- ", stream);
+ fput_command_names_styled (c, true, " -- ", stream);
if (verbose)
fputs_highlighted (c->doc, highlight, stream);
else
@@ -1106,6 +1104,14 @@ apropos_cmd (struct ui_file *stream,
/* Walk through the commands. */
for (c=commandlist;c;c=c->next)
{
+ if (c->cmd_pointer != nullptr)
+ {
+ /* Command aliases/abbreviations are skipped to ensure we print the
+ doc of a command only once, when encountering the aliased
+ command. */
+ continue;
+ }
+
returnvalue = -1; /* Needed to avoid double printing. */
if (c->name != NULL)
{
@@ -1115,6 +1121,17 @@ apropos_cmd (struct ui_file *stream,
returnvalue = regex.search (c->name, name_len, 0, name_len, NULL);
if (returnvalue >= 0)
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)
+ {
+ name_len = strlen (iter->name);
+ returnvalue = regex.search (iter->name, name_len, 0, name_len, NULL);
+ if (returnvalue >= 0)
+ print_doc_of_command (c, prefix, verbose, regex, stream);
+ }
}
if (c->doc != NULL && returnvalue < 0)
{
@@ -1124,10 +1141,8 @@ apropos_cmd (struct ui_file *stream,
if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0)
print_doc_of_command (c, prefix, verbose, regex, stream);
}
- /* Check if this command has subcommands and is not an
- abbreviation. We skip listing subcommands of abbreviations
- in order to avoid duplicates in the output. */
- if (c->prefixlist != NULL && !c->abbrev_flag)
+ /* Check if this command has subcommands. */
+ if (c->prefixlist != NULL)
{
/* Recursively call ourselves on the subcommand list,
passing the right prefix in. */
@@ -1150,7 +1165,7 @@ apropos_cmd (struct ui_file *stream,
void
help_cmd (const char *command, struct ui_file *stream)
{
- struct cmd_list_element *c;
+ struct cmd_list_element *c, *alias, *prefix_cmd, *c_cmd;
if (!command)
{
@@ -1164,11 +1179,14 @@ help_cmd (const char *command, struct ui_file *stream)
return;
}
+ const char *orig_command = command;
c = lookup_cmd (&command, cmdlist, "", 0, 0);
if (c == 0)
return;
+ lookup_cmd_composition (orig_command, &alias, &prefix_cmd, &c_cmd);
+
/* There are three cases here.
If c->prefixlist is nonzero, we have a prefix command.
Print its documentation, then list its subcommands.
@@ -1181,6 +1199,9 @@ help_cmd (const char *command, struct ui_file *stream)
number of this class so that the commands in the class will be
listed. */
+ /* If the user asked 'help somecommand' and there is no alias,
+ the false indicates to not output the (single) command name. */
+ fput_command_names_styled (c, false, "\n", stream);
fputs_filtered (c->doc, stream);
fputs_filtered ("\n", stream);