This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: completion -vs- deprecated commands (Was: [RFA] target record_core -> target record-core?)


Tom> One more thing I've wanted is also making it so deprecated commands
Tom> don't show up in completion when there is a non-deprecated completion
Tom> available.  Any comments on that?

Joel> I think that would be useful indeed.

Here's the patch.  It looks big because I had to reindent a loop.

I plan to commit this early next week, barring objections or comments.

Built and regtested on x86-64 (compile farm).
New tests included.

Tom

2010-04-23  Tom Tromey  <tromey@redhat.com>

	* cli/cli-decode.c (complete_on_cmdlist): Make two passes over the
	command list.

2010-04-23  Tom Tromey  <tromey@redhat.com>

	* gdb.base/completion.exp: Add tests for completion and deprecated
	commands.

Index: cli/cli-decode.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-decode.c,v
retrieving revision 1.86
diff -u -r1.86 cli-decode.c
--- cli/cli-decode.c	1 Jan 2010 07:31:46 -0000	1.86
+++ cli/cli-decode.c	23 Apr 2010 20:17:41 -0000
@@ -1597,43 +1597,65 @@
   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)
-	  {
-	    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;
-      }
+  /* 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))
+	  {
+	    if (pass == 0)
+	      {
+		if ((ptr->flags & CMD_DEPRECATED) != 0)
+		  {
+		    saw_deprecated_match = 1;
+		    continue;
+		  }
+	      }
+
+	    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;
+	  }
+      /* If we saw no matching deprecated commands in the first pass,
+	 just bail out.  */
+      if (!saw_deprecated_match)
+	break;
+    }
 
   if (matches == 0)
     {
Index: testsuite/gdb.base/completion.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v
retrieving revision 1.44
diff -u -r1.44 completion.exp
--- testsuite/gdb.base/completion.exp	4 Apr 2010 23:47:16 -0000	1.44
+++ testsuite/gdb.base/completion.exp	23 Apr 2010 20:17:43 -0000
@@ -847,6 +847,12 @@
         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
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]