This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 09/18] Implement completion limiting for interpreter_completer.
- From: Keith Seitz <keiths at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 13 Apr 2015 12:23:23 -0700
- Subject: [PATCH 09/18] Implement completion limiting for interpreter_completer.
- Authentication-results: sourceware.org; auth=none
- References: <20150413192235 dot 29172 dot 13097 dot stgit at valrhona dot uglyboxes dot com>
This is another simple patch which converts interpreter_completer
to use maybe_add_completion and adds some tests to make sure
that everything is working properly.
gdb/ChangeLog
* interps.c (interpreter_completer): Use maybe_add_completion.
gdb/testsuite/ChangeLog
* gdb.base/completion.exp: Test completion limiting on
interpreter name with "interpreter-exec".
---
gdb/interps.c | 19 ++++++++++++++++++-
gdb/testsuite/gdb.base/completion.exp | 16 ++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/gdb/interps.c b/gdb/interps.c
index ac1b512..085cac5 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -451,6 +451,7 @@ interpreter_completer (struct completer_data *cdata,
if (strncmp (interp->name, text, textlen) == 0)
{
char *match;
+ enum maybe_add_completion_enum add_status;
match = (char *) xmalloc (strlen (word) + strlen (interp->name) + 1);
if (word == text)
@@ -467,7 +468,23 @@ interpreter_completer (struct completer_data *cdata,
match[text - word] = '\0';
strcat (match, interp->name);
}
- VEC_safe_push (char_ptr, matches, match);
+
+ add_status = maybe_add_completion (cdata, match);
+ switch (add_status)
+ {
+ case MAYBE_ADD_COMPLETION_OK:
+ VEC_safe_push (char_ptr, matches, match);
+ break;
+ case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+ VEC_safe_push (char_ptr, matches, match);
+ return matches;
+ case MAYBE_ADD_COMPLETION_MAX_REACHED:
+ xfree (match);
+ return matches;
+ case MAYBE_ADD_COMPLETION_DUPLICATE:
+ xfree (match);
+ break;
+ }
}
}
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 90cdb36..d07ca86 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -1021,3 +1021,19 @@ if {$num_signals > $max_completions} {
append msg "limiting in signal_handler ($num_signals)"
untested $msg
}
+
+# Test interpreter_completer. There are only four completions
+# available for this, so temporarily set max-completions to 3.
+with_test_prefix "interpreter_completer" {
+ set old_max $max_completions
+ set max_completions 3
+ gdb_test_no_output "set max-completions $max_completions"
+}
+
+test_completion_limit "interpreter-exec m" \
+ "interpreter-exec mi\[1-3\]?" $max_completions
+
+with_test_prefix "interpreter_completer reset" {
+ set max_completions $old_max
+ gdb_test_no_output "set max-completions $max_completions"
+}