aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-17 14:01:32 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-17 14:01:32 -0400
commit034dce7a47652cf0a5f8fbcc403ca995171cc417 (patch)
tree7e0e13041428cac10deee758fbd2883dc0ce928b /gdb/cli
parent3d0b35641081d0f57d32583093f3297ff39b7379 (diff)
downloadgdb-034dce7a47652cf0a5f8fbcc403ca995171cc417.zip
gdb-034dce7a47652cf0a5f8fbcc403ca995171cc417.tar.gz
gdb-034dce7a47652cf0a5f8fbcc403ca995171cc417.tar.bz2
gdb: add cmd_list_element::is_command_class_help
Same idea as the previous patches, but for whether a command is a "command class help" command. I think this one is particularly useful, because it's not obvious when reading code what "c->func == NULL" means. Remove the cmd_func_p function, which does kind of the same thing as cmd_list_element::is_command_class_help (except it doesn't give a clue about the semantic of a NULL func value). gdb/ChangeLog: * cli/cli-decode.h (cmd_list_element) <is_command_class_help>: New, use it. * command.h (cmd_func_p): Remove. * cli/cli-decode.c (cmd_func_p): Remove. Change-Id: I521a3e1896dc93a5babe1493d18f5eb071e1b3b7
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-decode.c25
-rw-r--r--gdb/cli/cli-decode.h6
2 files changed, 14 insertions, 17 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 785e726a..fbead70 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1250,7 +1250,7 @@ help_cmd (const char *command, struct ui_file *stream)
fputs_filtered (c->doc, stream);
fputs_filtered ("\n", stream);
- if (!c->is_prefix () && c->func != NULL)
+ if (!c->is_prefix () && !c->is_command_class_help ())
return;
fprintf_filtered (stream, "\n");
@@ -1261,7 +1261,7 @@ help_cmd (const char *command, struct ui_file *stream)
all_commands, stream);
/* If this is a class name, print all of the commands in the class. */
- if (c->func == NULL)
+ if (c->is_command_class_help ())
help_list (cmdlist, "", c->theclass, stream);
if (c->hook_pre || c->hook_post)
@@ -1362,7 +1362,7 @@ help_all (struct ui_file *stream)
/* If this is a class name, print all of the commands in the
class. */
- if (c->func == NULL)
+ if (c->is_command_class_help ())
{
fprintf_filtered (stream, "\nCommand class: %s\n\n", c->name);
help_cmd_list (cmdlist, c->theclass, true, stream);
@@ -1498,8 +1498,8 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass,
}
if (theclass == all_commands
- || (theclass == all_classes && c->func == NULL)
- || (theclass == c->theclass && c->func != NULL))
+ || (theclass == all_classes && c->is_command_class_help ())
+ || (theclass == c->theclass && !c->is_command_class_help ()))
{
/* show C when
- showing all commands
@@ -1545,7 +1545,7 @@ find_cmd (const char *command, int len, struct cmd_list_element *clist,
*nfound = 0;
for (c = clist; c; c = c->next)
if (!strncmp (command, c->name, len)
- && (!ignore_help_classes || c->func))
+ && (!ignore_help_classes || !c->is_command_class_help ()))
{
found = c;
(*nfound)++;
@@ -2124,7 +2124,7 @@ complete_on_cmdlist (struct cmd_list_element *list,
for (ptr = list; ptr; ptr = ptr->next)
if (!strncmp (ptr->name, text, textlen)
&& !ptr->abbrev_flag
- && (!ignore_help_classes || ptr->func
+ && (!ignore_help_classes || !ptr->is_command_class_help ()
|| ptr->is_prefix ()))
{
if (pass == 0)
@@ -2174,20 +2174,11 @@ complete_on_enum (completion_tracker &tracker,
tracker.add_completion (make_completion_match_str (name, text, word));
}
-
-/* Check function pointer. */
-int
-cmd_func_p (struct cmd_list_element *cmd)
-{
- return (cmd->func != NULL);
-}
-
-
/* Call the command function. */
void
cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty)
{
- if (cmd_func_p (cmd))
+ if (!cmd->is_command_class_help ())
{
gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 6204ed7..9328659 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -87,6 +87,12 @@ struct cmd_list_element
bool is_prefix () const
{ return this->subcommands != nullptr; }
+ /* Return true if this command is a "command class help" command. For
+ instance, a "stack" dummy command is registered so that one can do
+ "help stack" and show help for all commands of the "stack" class. */
+ bool is_command_class_help () const
+ { return this->func == nullptr; }
+
/* Points to next command in this list. */
struct cmd_list_element *next = nullptr;