gdb
authorTom Tromey <tromey@redhat.com>
Mon, 26 Apr 2010 18:37:14 +0000 (18:37 +0000)
committerTom Tromey <tromey@redhat.com>
Mon, 26 Apr 2010 18:37:14 +0000 (18:37 +0000)
* cli/cli-decode.c (complete_on_cmdlist): Make two passes over the
command list.
gdb/testsuite
* gdb.base/completion.exp: Add tests for completion and deprecated
commands.

gdb/ChangeLog
gdb/cli/cli-decode.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/completion.exp

index 6c112a8832cb048d92ea92ec35d164aa21c5da84..405ab221699447005390d0a21d8d863bb7cdaecc 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-26  Tom Tromey  <tromey@redhat.com>
+
+       * cli/cli-decode.c (complete_on_cmdlist): Make two passes over the
+       command list.
+
 2010-04-26  Pierre Muller  <muller@ics.u-strasbg.fr>
 
        Removal of config/i386/nm-i386sol2.h native configuration file.
index de261fa1e356f9b2ee1eb83f409950d4df12bd65..1655e0a99c5eb46102ac9a2d3b95373c7f08b60a 100644 (file)
@@ -1597,43 +1597,65 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word)
   int sizeof_matchlist;
   int matches;
   int textlen = strlen (text);
+  int pass;
+  int saw_deprecated_match = 0;
 
   sizeof_matchlist = 10;
   matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
   matches = 0;
 
-  for (ptr = list; ptr; ptr = ptr->next)
-    if (!strncmp (ptr->name, text, textlen)
-       && !ptr->abbrev_flag
-       && (ptr->func
-           || ptr->prefixlist))
-      {
-       if (matches == sizeof_matchlist)
+  /* We do one or two passes.  In the first pass, we skip deprecated
+     commands.  If we see no matching commands in the first pass, and
+     if we did happen to see a matching deprecated command, we do
+     another loop to collect those.  */
+  for (pass = 0; matches == 0 && pass < 2; ++pass)
+    {
+      for (ptr = list; ptr; ptr = ptr->next)
+       if (!strncmp (ptr->name, text, textlen)
+           && !ptr->abbrev_flag
+           && (ptr->func
+               || ptr->prefixlist))
          {
-           sizeof_matchlist *= 2;
-           matchlist = (char **) xrealloc ((char *) matchlist,
-                                           (sizeof_matchlist
-                                            * sizeof (char *)));
-         }
+           if (pass == 0)
+             {
+               if ((ptr->flags & CMD_DEPRECATED) != 0)
+                 {
+                   saw_deprecated_match = 1;
+                   continue;
+                 }
+             }
 
-       matchlist[matches] = (char *)
-         xmalloc (strlen (word) + strlen (ptr->name) + 1);
-       if (word == text)
-         strcpy (matchlist[matches], ptr->name);
-       else if (word > text)
-         {
-           /* Return some portion of ptr->name.  */
-           strcpy (matchlist[matches], ptr->name + (word - text));
-         }
-       else
-         {
-           /* Return some of text plus ptr->name.  */
-           strncpy (matchlist[matches], word, text - word);
-           matchlist[matches][text - word] = '\0';
-           strcat (matchlist[matches], ptr->name);
+           if (matches == sizeof_matchlist)
+             {
+               sizeof_matchlist *= 2;
+               matchlist = (char **) xrealloc ((char *) matchlist,
+                                               (sizeof_matchlist
+                                                * sizeof (char *)));
+             }
+
+           matchlist[matches] = (char *)
+             xmalloc (strlen (word) + strlen (ptr->name) + 1);
+           if (word == text)
+             strcpy (matchlist[matches], ptr->name);
+           else if (word > text)
+             {
+               /* Return some portion of ptr->name.  */
+               strcpy (matchlist[matches], ptr->name + (word - text));
+             }
+           else
+             {
+               /* Return some of text plus ptr->name.  */
+               strncpy (matchlist[matches], word, text - word);
+               matchlist[matches][text - word] = '\0';
+               strcat (matchlist[matches], ptr->name);
+             }
+           ++matches;
          }
-       ++matches;
-      }
+      /* If we saw no matching deprecated commands in the first pass,
+        just bail out.  */
+      if (!saw_deprecated_match)
+       break;
+    }
 
   if (matches == 0)
     {
index 7aee1ec5aceb650b74adb7c69b72088e963ea153..4c3bf836b6d2177612e26a9f45c0ed938f3de77a 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-26  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.base/completion.exp: Add tests for completion and deprecated
+       commands.
+
 2010-04-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * gdb.pascal/gdb11492.exp (print integer_array, print /d char_array)
index fbd859986674297562bea6cdf7adbae573caf4b2..5f836b601f5cdf2cca060815fe75554ddc931163 100644 (file)
@@ -847,6 +847,12 @@ gdb_expect  {
         eof             { fail "(eof) Completing non-existing component #2" }
         }
 
+# If there is a non-deprecated completion, it should be returned.
+gdb_test "complete sav" "save" "test non-deprecated completion"
+# If there is only a deprecated completion, then it should be returned.
+gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
+
+
 # Restore globals modified in this test...
 set timeout $oldtimeout1