]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/cli/cli-decode.c
Rename make_symbol_completion_list_fn -> symbol_completer
[thirdparty/binutils-gdb.git] / gdb / cli / cli-decode.c
index 4d0d5a99c5e0bd25022887a70f8c53ba018230fa..0a78f4e5a8e866f374b908cf0c64dc785037132d 100644 (file)
@@ -1,6 +1,6 @@
 /* Handle lists of commands, their decoding and documentation, for GDB.
 
-   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+   Copyright (C) 1986-2017 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 #include "ui-out.h"
 #include "cli/cli-cmds.h"
 #include "cli/cli-decode.h"
+#include "common/gdb_optional.h"
 
 /* Prototypes for local functions.  */
 
@@ -192,8 +193,7 @@ struct cmd_list_element *
 add_cmd (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
         const char *doc, struct cmd_list_element **list)
 {
-  struct cmd_list_element *c
-    = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
+  struct cmd_list_element *c = XNEW (struct cmd_list_element);
   struct cmd_list_element *p, *iter;
 
   /* Turn each alias of the old command into an alias of the new
@@ -244,7 +244,7 @@ add_cmd (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
   c->allow_unknown = 0;
   c->prefix = NULL;
   c->abbrev_flag = 0;
-  set_cmd_completer (c, make_symbol_completion_list_fn);
+  set_cmd_completer (c, symbol_completer);
   c->completer_handle_brkchars = NULL;
   c->destroyer = NULL;
   c->type = not_set_cmd;
@@ -254,6 +254,7 @@ add_cmd (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
   c->user_commands = NULL;
   c->cmd_pointer = NULL;
   c->alias_chain = NULL;
+  c->suppress_notification = NULL;
 
   return c;
 }
@@ -283,16 +284,10 @@ deprecate_cmd (struct cmd_list_element *cmd, const char *replacement)
 }
 
 struct cmd_list_element *
-add_alias_cmd (const char *name, const char *oldname, enum command_class theclass,
-              int abbrev_flag, struct cmd_list_element **list)
+add_alias_cmd (const char *name, cmd_list_element *old,
+              enum command_class theclass, int abbrev_flag,
+              struct cmd_list_element **list)
 {
-  const char *tmp;
-  struct cmd_list_element *old;
-  struct cmd_list_element *c;
-
-  tmp = oldname;
-  old = lookup_cmd (&tmp, *list, "", 1, 1);
-
   if (old == 0)
     {
       struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee;
@@ -306,7 +301,7 @@ add_alias_cmd (const char *name, const char *oldname, enum command_class theclas
       return 0;
     }
 
-  c = add_cmd (name, theclass, NULL, old->doc, list);
+  struct cmd_list_element *c = add_cmd (name, theclass, NULL, old->doc, list);
 
   /* If OLD->DOC can be freed, we should make another copy.  */
   if (old->doc_allocated)
@@ -329,6 +324,21 @@ add_alias_cmd (const char *name, const char *oldname, enum command_class theclas
   return c;
 }
 
+struct cmd_list_element *
+add_alias_cmd (const char *name, const char *oldname,
+              enum command_class theclass, int abbrev_flag,
+              struct cmd_list_element **list)
+{
+  const char *tmp;
+  struct cmd_list_element *old;
+
+  tmp = oldname;
+  old = lookup_cmd (&tmp, *list, "", 1, 1);
+
+  return add_alias_cmd (name, old, theclass, abbrev_flag, list);
+}
+
+
 /* Like add_cmd but adds an element for a command prefix: a name that
    should be followed by a subcommand to be looked up in another
    command list.  PREFIXLIST should be the address of the variable
@@ -856,7 +866,7 @@ delete_cmd (const char *name, struct cmd_list_element **list,
 struct cmd_list_element *
 add_info (const char *name, cmd_cfunc_ftype *fun, const char *doc)
 {
-  return add_cmd (name, no_class, fun, doc, &infolist);
+  return add_cmd (name, class_info, fun, doc, &infolist);
 }
 
 /* Add an alias to the list of info subcommands.  */
@@ -864,7 +874,7 @@ add_info (const char *name, cmd_cfunc_ftype *fun, const char *doc)
 struct cmd_list_element *
 add_info_alias (const char *name, const char *oldname, int abbrev_flag)
 {
-  return add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
+  return add_alias_cmd (name, oldname, class_run, abbrev_flag, &infolist);
 }
 
 /* Add an element to the list of commands.  */
@@ -884,7 +894,22 @@ add_com_alias (const char *name, const char *oldname, enum command_class theclas
 {
   return add_alias_cmd (name, oldname, theclass, abbrev_flag, &cmdlist);
 }
-\f
+
+/* Add an element with a suppress notification to the list of commands.  */
+
+struct cmd_list_element *
+add_com_suppress_notification (const char *name, enum command_class theclass,
+                              cmd_cfunc_ftype *fun, const char *doc,
+                              int *suppress_notification)
+{
+  struct cmd_list_element *element;
+
+  element = add_cmd (name, theclass, fun, doc, &cmdlist);
+  element->suppress_notification = suppress_notification;
+
+  return element;
+}
+
 /* Recursively walk the commandlist structures, and print out the
    documentation of commands that match our regex in either their
    name, or their documentation.
@@ -892,7 +917,7 @@ add_com_alias (const char *name, const char *oldname, enum command_class theclas
 void 
 apropos_cmd (struct ui_file *stream, 
             struct cmd_list_element *commandlist,
-            struct re_pattern_buffer *regex, const char *prefix)
+            compiled_regex &regex, const char *prefix)
 {
   struct cmd_list_element *c;
   int returnvalue;
@@ -903,9 +928,10 @@ apropos_cmd (struct ui_file *stream,
       returnvalue = -1; /* Needed to avoid double printing.  */
       if (c->name != NULL)
        {
+         size_t name_len = strlen (c->name);
+
          /* Try to match against the name.  */
-         returnvalue = re_search (regex, c->name, strlen(c->name),
-                                  0, strlen (c->name), NULL);
+         returnvalue = regex.search (c->name, name_len, 0, name_len, NULL);
          if (returnvalue >= 0)
            {
              print_help_for_command (c, prefix, 
@@ -914,8 +940,10 @@ apropos_cmd (struct ui_file *stream,
        }
       if (c->doc != NULL && returnvalue < 0)
        {
+         size_t doc_len = strlen (c->doc);
+
          /* Try to match against documentation.  */
-         if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0)
+         if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0)
            {
              print_help_for_command (c, prefix, 
                                      0 /* don't recurse */, stream);
@@ -1176,7 +1204,7 @@ print_help_for_command (struct cmd_list_element *c, const char *prefix,
  * all sublists of LIST.
  * PREFIX is the prefix to print before each command name.
  * STREAM is the stream upon which the output should be written.
- * CLASS should be:
+ * THECLASS should be:
  *      A non-negative class number to list only commands in that
  * class.
  *      ALL_COMMANDS to list all commands in list.
@@ -1193,15 +1221,18 @@ help_cmd_list (struct cmd_list_element *list, enum command_class theclass,
   struct cmd_list_element *c;
 
   for (c = list; c; c = c->next)
-    {      
+    {
       if (c->abbrev_flag == 0
+         && !c->cmd_deprecated
          && (theclass == all_commands
              || (theclass == all_classes && c->func == NULL)
              || (theclass == c->theclass && c->func != NULL)))
        {
          print_help_for_command (c, prefix, recurse, stream);
        }
-      else if (c->abbrev_flag == 0 && recurse
+      else if (c->abbrev_flag == 0
+              && recurse
+              && !c->cmd_deprecated
               && theclass == class_user && c->prefixlist != NULL)
        /* User-defined commands may be subcommands.  */
        help_cmd_list (*c->prefixlist, theclass, c->prefixname,
@@ -1220,7 +1251,7 @@ find_cmd (const char *command, int len, struct cmd_list_element *clist,
 {
   struct cmd_list_element *found, *c;
 
-  found = (struct cmd_list_element *) NULL;
+  found = NULL;
   *nfound = 0;
   for (c = clist; c; c = c->next)
     if (!strncmp (command, c->name, len)
@@ -1237,7 +1268,9 @@ find_cmd (const char *command, int len, struct cmd_list_element *clist,
   return found;
 }
 
-static int
+/* Return the length of command name in TEXT.  */
+
+int
 find_command_name_length (const char *text)
 {
   const char *p = text;
@@ -1313,7 +1346,7 @@ valid_user_defined_cmd_name_p (const char *name)
    if no prefix command was ever found.  For example, in the case of "info a",
    "info" matches without ambiguity, but "a" could be "args" or "address", so
    *RESULT_LIST is set to the cmd_list_element for "info".  So in this case
-   RESULT_LIST should not be interpeted as a pointer to the beginning of a
+   RESULT_LIST should not be interpreted as a pointer to the beginning of a
    list; it simply points to a specific command.  In the case of an ambiguous
    return *TEXT is advanced past the last non-ambiguous prefix (e.g.
    "info t" can be "info types" or "info target"; upon return *TEXT has been
@@ -1360,19 +1393,6 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
   nfound = 0;
   found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
 
-  /* We didn't find the command in the entered case, so lower case it
-     and search again.  */
-  if (!found || nfound == 0)
-    {
-      for (tmp = 0; tmp < len; tmp++)
-       {
-         char x = command[tmp];
-
-         command[tmp] = isupper (x) ? tolower (x) : x;
-       }
-      found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
-    }
-
   /* If nothing matches, we have a simple failure.  */
   if (nfound == 0)
     return 0;
@@ -1472,7 +1492,8 @@ undef_cmd_error (const char *cmdtype, const char *q)
    the function field of the struct cmd_list_element is 0).  */
 
 struct cmd_list_element *
-lookup_cmd (const char **line, struct cmd_list_element *list, char *cmdtype,
+lookup_cmd (const char **line, struct cmd_list_element *list,
+           const char *cmdtype,
            int allow_unknown, int ignore_help_classes)
 {
   struct cmd_list_element *last_list = 0;
@@ -1713,20 +1734,6 @@ lookup_cmd_composition (const char *text,
       nfound = 0;
       *cmd = find_cmd (command, len, cur_list, 1, &nfound);
       
-      /* We didn't find the command in the entered case, so lower case
-        it and search again.
-      */
-      if (!*cmd || nfound == 0)
-       {
-         for (tmp = 0; tmp < len; tmp++)
-           {
-             char x = command[tmp];
-
-             command[tmp] = isupper (x) ? tolower (x) : x;
-           }
-         *cmd = find_cmd (command, len, cur_list, 1, &nfound);
-       }
-      
       if (*cmd == CMD_LIST_AMBIGUOUS)
        {
          return 0;              /* ambiguous */
@@ -1883,7 +1890,14 @@ void
 cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
 {
   if (cmd_func_p (cmd))
-    (*cmd->func) (cmd, args, from_tty);
+    {
+      gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
+
+      if (cmd->suppress_notification != NULL)
+       restore_suppress.emplace (cmd->suppress_notification, 1);
+
+      (*cmd->func) (cmd, args, from_tty);
+    }
   else
     error (_("Invalid command"));
 }