[PATCH 03/18] Implement completion limiting for complete_on_cmdlist.

Keith Seitz keiths@redhat.com
Mon Apr 13 19:23:00 GMT 2015


This is the first of a series of smaller patches to switch over
all completion functions to using maybe_add_completion to add
completions to the completion list to be presented to the user.

Note that in order to verify that this patch works as intended,
one must override the backup completion counting in complete_line.
[This backup code will be permanently removed in a later patch.]
During testing, I have verified all patches with this planned code
removal to verify that it works.

First up is complete_on_cmdlist.  Completion limiting is already tested
in gdb.base/completion.exp, so there are no new tests.

gdb/ChangeLog

	* cli/cli-decode.c (complete_on_cmdlist): Use maybe_add_completion
	to determine whether to continue looking for completions.
---
 gdb/cli/cli-decode.c |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 286fc61..21f4c45 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1790,6 +1790,7 @@ complete_on_cmdlist (struct completer_data *cdata,
 		|| ptr->prefixlist))
 	  {
 	    char *match;
+	    enum maybe_add_completion_enum add_status;
 
 	    if (pass == 0)
 	      {
@@ -1815,7 +1816,22 @@ complete_on_cmdlist (struct completer_data *cdata,
 		match[text - word] = '\0';
 		strcat (match, ptr->name);
 	      }
-	    VEC_safe_push (char_ptr, matchlist, match);
+	    add_status = maybe_add_completion (cdata, match);
+	    switch (add_status)
+	      {
+	      case MAYBE_ADD_COMPLETION_OK:
+		VEC_safe_push (char_ptr, matchlist, match);
+		break;
+	      case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+		VEC_safe_push (char_ptr, matchlist, match);
+		return matchlist;
+	      case MAYBE_ADD_COMPLETION_MAX_REACHED:
+		xfree (match);
+		return matchlist;
+	      case MAYBE_ADD_COMPLETION_DUPLICATE:
+		xfree (match);
+		break;
+	      }
 	  }
       /* If we saw no matching deprecated commands in the first pass,
 	 just bail out.  */



More information about the Gdb-patches mailing list