gdb: add cmd_list_element::is_prefix
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 14 May 2021 19:38:49 +0000 (15:38 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 17 May 2021 18:01:26 +0000 (14:01 -0400)
Same idea as the previous patch, but for prefix instead of alias.

gdb/ChangeLog:

* cli/cli-decode.h (cmd_list_element) <is_prefix>: New, use it.

Change-Id: I76a9d2e82fc8d7429904424674d99ce6f9880e2b

gdb/auto-load.c
gdb/cli/cli-cmds.c
gdb/cli/cli-decode.c
gdb/cli/cli-decode.h
gdb/cli/cli-script.c
gdb/cli/cli-setshow.c
gdb/completer.c
gdb/guile/scm-cmd.c
gdb/python/py-cmd.c
gdb/top.c
gdb/unittests/command-def-selftests.c

index 7745aa65b0367a59db4468b6a694118d23044abc..9cd70f174c3c3c19f381c35a45000428d6a9cbd8 100644 (file)
@@ -1465,7 +1465,7 @@ info_auto_load_cmd (const char *args, int from_tty)
     {
       ui_out_emit_tuple option_emitter (uiout, "option");
 
-      gdb_assert (!list->subcommands);
+      gdb_assert (!list->is_prefix ());
       gdb_assert (list->type == not_set_cmd);
 
       uiout->field_string ("name", list->name);
index c29e5979acb427c11ebccafe7593ead43bae8c5c..0bf418e510eaa5bd3720e5adfe8cf19227b05c30 100644 (file)
@@ -1625,7 +1625,7 @@ show_user (const char *args, int from_tty)
     {
       for (c = cmdlist; c; c = c->next)
        {
-         if (cli_user_command_p (c) || c->subcommands != NULL)
+         if (cli_user_command_p (c) || c->is_prefix ())
            show_user_1 (c, "", c->name, gdb_stdout);
        }
     }
@@ -1900,7 +1900,7 @@ alias_command (const char *args, int from_tty)
       /* We've already tried to look up COMMAND.  */
       gdb_assert (c_command != NULL
                  && c_command != (struct cmd_list_element *) -1);
-      gdb_assert (c_command->subcommands != NULL);
+      gdb_assert (c_command->is_prefix ());
       c_alias = lookup_cmd_1 (& alias_prefix, cmdlist, NULL, NULL, 1);
       if (c_alias != c_command)
        error (_("ALIAS and COMMAND prefixes do not match."));
index 29b4ed2f6bd7f266222b1d61ccb43fcbe92531bb..785e726a81f6903522605546e13f9663c12e0a07 100644 (file)
@@ -69,8 +69,9 @@ lookup_cmd_with_subcommands (cmd_list_element **subcommands,
     {
       struct cmd_list_element *q;
 
-      if (p->subcommands == NULL)
+      if (!p->is_prefix ())
        continue;
+
       else if (p->subcommands == subcommands)
        {
          /* If we found an alias, we must return the aliased
@@ -163,7 +164,7 @@ set_cmd_completer_handle_brkchars (struct cmd_list_element *cmd,
 std::string
 cmd_list_element::prefixname () const
 {
-  if (this->subcommands == nullptr)
+  if (!this->is_prefix ())
     /* Not a prefix command.  */
     return "";
 
@@ -369,7 +370,7 @@ update_prefix_field_of_prefixed_commands (struct cmd_list_element *c)
         'auto-load' command was not yet reachable by
            lookup_cmd_for_subcommands (list, cmdlist)
            that searches from the top level 'cmdlist'.  */
-      if (p->subcommands != nullptr)
+      if (p->is_prefix ())
        update_prefix_field_of_prefixed_commands (p);
     }
 }
@@ -1184,7 +1185,7 @@ apropos_cmd (struct ui_file *stream,
            print_doc_of_command (c, prefix, verbose, regex, stream);
        }
       /* Check if this command has subcommands.  */
-      if (c->subcommands != NULL)
+      if (c->is_prefix ())
        {
          /* Recursively call ourselves on the subcommand list,
             passing the right prefix in.  */
@@ -1249,12 +1250,13 @@ help_cmd (const char *command, struct ui_file *stream)
   fputs_filtered (c->doc, stream);
   fputs_filtered ("\n", stream);
 
-  if (c->subcommands == 0 && c->func != NULL)
+  if (!c->is_prefix () && c->func != NULL)
     return;
+
   fprintf_filtered (stream, "\n");
 
   /* If this is a prefix command, print it's subcommands.  */
-  if (c->subcommands)
+  if (c->is_prefix ())
     help_list (*c->subcommands, c->prefixname ().c_str (),
               all_commands, stream);
 
@@ -1446,7 +1448,7 @@ print_help_for_command (struct cmd_list_element *c,
   fput_aliases_definition_styled (c, stream);
 
   if (recurse
-      && c->subcommands != 0
+      && c->is_prefix ()
       && c->abbrev_flag == 0)
     /* Subcommands of a prefix command typically have 'all_commands'
        as class.  If we pass CLASS to recursive invocation,
@@ -1516,7 +1518,7 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass,
 
       if (recurse
          && (theclass == class_user || theclass == class_alias)
-         && c->subcommands != NULL)
+         && c->is_prefix ())
        {
          /* User-defined commands or aliases may be subcommands.  */
          help_cmd_list (*c->subcommands, theclass, recurse, stream);
@@ -1694,7 +1696,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
     }
   /* If we found a prefix command, keep looking.  */
 
-  if (found->subcommands)
+  if (found->is_prefix ())
     {
       c = lookup_cmd_1 (text, *found->subcommands, result_list, default_args,
                        ignore_help_classes, lookup_for_completion_p);
@@ -1865,7 +1867,7 @@ lookup_cmd (const char **line, struct cmd_list_element *list,
       while (**line == ' ' || **line == '\t')
        (*line)++;
 
-      if (c->subcommands && **line && !c->allow_unknown)
+      if (c->is_prefix () && **line && !c->allow_unknown)
        undef_cmd_error (c->prefixname ().c_str (), *line);
 
       /* Seems to be what he wants.  Return it.  */
@@ -2056,7 +2058,7 @@ lookup_cmd_composition_1 (const char *text,
       text += len;
       text = skip_spaces (text);
 
-      if ((*cmd)->subcommands != nullptr && *text != '\0')
+      if ((*cmd)->is_prefix () && *text != '\0')
        {
          cur_list = *(*cmd)->subcommands;
          *prefix_cmd = *cmd;
@@ -2123,7 +2125,7 @@ complete_on_cmdlist (struct cmd_list_element *list,
        if (!strncmp (ptr->name, text, textlen)
            && !ptr->abbrev_flag
            && (!ignore_help_classes || ptr->func
-               || ptr->subcommands))
+               || ptr->is_prefix ()))
          {
            if (pass == 0)
              {
index 8caf6023454892319c2c97efe31134228e6f2a30..6204ed745e00a6c02ee034dd5a3bb7d91938330a 100644 (file)
@@ -83,6 +83,10 @@ struct cmd_list_element
   bool is_alias () const
   { return this->alias_target != nullptr; }
 
+  /* Return true if this command is a prefix command.  */
+  bool is_prefix () const
+  { return this->subcommands != nullptr; }
+
   /* Points to next command in this list.  */
   struct cmd_list_element *next = nullptr;
 
index 5ddfab9674a096b089c6a12445666b491393f3fd..ff93523f4daae1bb463d503155ec7f34adcdb412 100644 (file)
@@ -1350,7 +1350,7 @@ validate_comname (const char **comname)
       const char *tem = prefix.c_str ();
 
       c = lookup_cmd (&tem, cmdlist, "", NULL, 0, 1);
-      if (c->subcommands == NULL)
+      if (!c->is_prefix ())
        error (_("\"%s\" is not a prefix command."), prefix.c_str ());
 
       list = c->subcommands;
@@ -1414,7 +1414,7 @@ do_define_command (const char *comname, int from_tty,
          /* if C is a prefix command that was previously defined,
             tell the user its subcommands will be kept, and ask
             if ok to redefine the command.  */
-         if (c->subcommands != nullptr)
+         if (c->is_prefix ())
            q = (c->user_commands.get () == nullptr
                 || query (_("Keeping subcommands of prefix command \"%s\".\n"
                             "Redefine command \"%s\"? "), c->name, c->name));
@@ -1595,7 +1595,7 @@ define_prefix_command (const char *comname, int from_tty)
   if (c != nullptr && c->theclass != class_user)
     error (_("Command \"%s\" is built-in."), comfull);
 
-  if (c != nullptr && c->subcommands != nullptr)
+  if (c != nullptr && c->is_prefix ())
     {
       /* c is already a user defined prefix command.  */
       return;
@@ -1665,7 +1665,7 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name,
       struct command_line *cmdlines = c->user_commands.get ();
 
       fprintf_filtered (stream, "User %scommand \"",
-                       c->subcommands == NULL ? "" : "prefix ");
+                       c->is_prefix () ? "prefix" : "");
       fprintf_styled (stream, title_style.style (), "%s%s",
                      prefix, name);
       fprintf_filtered (stream, "\":\n");
@@ -1676,12 +1676,12 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name,
        }
     }
 
-  if (c->subcommands != NULL)
+  if (c->is_prefix ())
     {
       const std::string prefixname = c->prefixname ();
 
       for (c = *c->subcommands; c != NULL; c = c->next)
-       if (c->theclass == class_user || c->subcommands != NULL)
+       if (c->theclass == class_user || c->is_prefix ())
          show_user_1 (c, prefixname.c_str (), c->name, gdb_stdout);
     }
 
index 7e93a70349421d78f04601fa2e951e001442ab88..82008ca8eed6923bae3abb34cb4d469c38045bdf 100644 (file)
@@ -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->is_alias ())
+      if (list->is_prefix () && !list->is_alias ())
        {
          ui_out_emit_tuple optionlist_emitter (uiout, "optionlist");
          std::string prefixname = list->prefixname ();
@@ -758,7 +758,7 @@ cmd_show_list (struct cmd_list_element *list, int from_tty)
            {
              /* If we find a prefix, output it (with "show " skipped).  */
              std::string prefixname = list->prefix->prefixname ();
-             prefixname = (list->prefix->subcommands == nullptr ? ""
+             prefixname = (!list->prefix->is_prefix () ? ""
                            : strstr (prefixname.c_str (), "show ") + 5);
              uiout->text (prefixname.c_str ());
            }
index 6d39435c6ca3151ce04ff617a7e281e19fa09ee4..6ad788b4344cb3b5085a820ed52720dbc1d6cef6 100644 (file)
@@ -1456,7 +1456,7 @@ complete_line_internal_1 (completion_tracker &tracker,
            {
              /* The command is followed by whitespace; we need to
                 complete on whatever comes after command.  */
-             if (c->subcommands)
+             if (c->is_prefix ())
                {
                  /* It is a prefix command; what comes after it is
                     a subcommand (e.g. "info ").  */
@@ -1524,7 +1524,7 @@ complete_line_internal_1 (completion_tracker &tracker,
        {
          /* There is non-whitespace beyond the command.  */
 
-         if (c->subcommands && !c->allow_unknown)
+         if (c->is_prefix () && !c->allow_unknown)
            {
              /* It is an unrecognized subcommand of a prefix command,
                 e.g. "info adsfkdj".  */
index fc7dc2b7d0bedcabd11f0a4c7e91292240c1895e..39c915e0ab226e525e6f0df812ecce8323a5f0ed 100644 (file)
@@ -524,7 +524,7 @@ gdbscm_parse_command_name (const char *name,
                                 gdbscm_scm_from_c_string (name), msg);
     }
 
-  if (elt->subcommands)
+  if (elt->is_prefix ())
     {
       xfree (prefix_text);
       *base_list = elt->subcommands;
index c2c0df5798dad40f9785c1f27ac23cc6e2ddc124..4f01fc0b5f35d71cf2b22665da8ea5a914d45c42 100644 (file)
@@ -111,7 +111,7 @@ cmdpy_function (struct cmd_list_element *command,
     error (_("Invalid invocation of Python command object."));
   if (! PyObject_HasAttr ((PyObject *) obj, invoke_cst))
     {
-      if (obj->command->subcommands != nullptr)
+      if (obj->command->is_prefix ())
        {
          /* A prefix command does not need an invoke method.  */
          return;
@@ -393,7 +393,7 @@ gdbpy_parse_command_name (const char *name,
       return NULL;
     }
 
-  if (elt->subcommands)
+  if (elt->is_prefix ())
     {
       *base_list = elt->subcommands;
       return result;
index a391e9359de01be444163b741f1a0c522cd51072..a1a932ae93e96c2a566553cd6b52a56cbbf81c95 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -647,7 +647,7 @@ execute_command (const char *p, int from_tty)
       if (c->theclass == class_user && c->user_commands)
        execute_user_command (c, arg);
       else if (c->theclass == class_user
-              && c->subcommands && !c->allow_unknown)
+              && c->is_prefix () && !c->allow_unknown)
        /* If this is a user defined prefix that does not allow unknown
           (in other words, C is a prefix command and not a command
           that can be followed by its args), report the list of
index 4a6b6789b370cf6c562b344187a595e21e132152..e99eb9bbb75dfd418b176c671f08fbceb447e395 100644 (file)
@@ -83,7 +83,7 @@ check_doc (struct cmd_list_element *commandlist, const char *prefix)
       /* Check if this command has subcommands and is not an
         abbreviation.  We skip checking subcommands of abbreviations
         in order to avoid duplicates in the output.  */
-      if (c->subcommands != NULL && !c->abbrev_flag)
+      if (c->is_prefix () && !c->abbrev_flag)
        {
          /* Recursively call ourselves on the subcommand list,
             passing the right prefix in.  */
@@ -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->is_alias ())
+      if (c->is_prefix () && !c->is_alias ())
        {
          /* Recursively call ourselves on the subcommand list,
             passing the right prefix in.  */
This page took 0.034823 seconds and 4 git commands to generate.