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 10/18] Implement completion limiting for cmdpy_completer.


This patch converts cmdpy_completer, used by commands written in
python.  It also adds tests for some untested python functionality
related to completion.

gdb/ChangeLog

	* python/py-cmd.c (cmdpy_completer) Use maybe_add_completion.

gdb/testsuite/ChangeLog

	* gdb.python/py-completion.exp: Test completion functions,
	with and without completion limiting.
---
 gdb/python/py-cmd.c                        |   24 ++++++++++++++-
 gdb/testsuite/gdb.python/py-completion.exp |   45 ++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 21d842e..ed97ce5 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -370,13 +370,15 @@ cmdpy_completer (struct completer_data *cdata,
     {
       PyObject *iter = PyObject_GetIter (resultobj);
       PyObject *elt;
+      int stop = 0;
 
       if (iter == NULL)
 	goto done;
 
-      while ((elt = PyIter_Next (iter)) != NULL)
+      while (!stop && (elt = PyIter_Next (iter)) != NULL)
 	{
 	  char *item;
+	  enum maybe_add_completion_enum add_status;
 
 	  if (! gdbpy_is_string (elt))
 	    {
@@ -392,7 +394,25 @@ cmdpy_completer (struct completer_data *cdata,
 	      PyErr_Clear ();
 	      continue;
 	    }
-	  VEC_safe_push (char_ptr, result, item);
+
+	  add_status = maybe_add_completion (cdata, item);
+	  switch (add_status)
+	    {
+	    case MAYBE_ADD_COMPLETION_OK:
+	      VEC_safe_push (char_ptr, result, item);
+	      break;
+	    case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+	      VEC_safe_push (char_ptr, result, item);
+	      stop = 1;
+	      break;
+	    case MAYBE_ADD_COMPLETION_MAX_REACHED:
+	      xfree (item);
+	      stop = 1;
+	      break;
+	    case MAYBE_ADD_COMPLETION_DUPLICATE:
+	      xfree (item);
+	      break;
+	    }
 	}
 
       Py_DECREF (iter);
diff --git a/gdb/testsuite/gdb.python/py-completion.exp b/gdb/testsuite/gdb.python/py-completion.exp
index 5e45087..f7f23a3 100644
--- a/gdb/testsuite/gdb.python/py-completion.exp
+++ b/gdb/testsuite/gdb.python/py-completion.exp
@@ -128,3 +128,48 @@ if {[readline_is_used]} {
 	    "completelimit2 cl29"
 	}
 }
+
+# The terminal at the end of the complete command
+set end "\\\*\\\*\\\* List may be truncated, "
+append end "max-completions reached\\\. \\\*\\\*\\\*"
+
+set max_completions 3
+gdb_test_no_output "set max-completions $max_completions"
+set seen 0
+
+set testname "limit completions of 'complete completel'"
+gdb_test_multiple "complete completel" $testname {
+    "complete completel" { exp_continue }
+
+    -re "completelimit\[1-9\]+\r\n" {
+	incr seen
+	exp_continue
+    }
+
+    -re "completel $end\r\n$gdb_prompt $" {
+	if {$seen == $max_completions} {
+	    pass $testname
+	} else {
+	    fail "$testname ($seen/$max_completions)"
+	}
+    }
+}
+
+set testname "limit completions of 'complete completelimit1 c'"
+set seen 0
+gdb_test_multiple "complete completelimit1 c" $testname {
+    "complete completelimit1 c" { exp_continue }
+
+    -re "completelimit1 cl1\[1-9\]+\r\n" {
+	incr seen
+	exp_continue
+    }
+
+    -re "completelimit1 c $end\r\n$gdb_prompt $" {
+	if {$seen == $max_completions} {
+	    pass $testname
+	} else {
+	    fail "$testname ($seen/$max_completions)"
+	}
+    }
+}


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