[PATCH v3 16/19] Implement completion limiting for tui_reggroup_completer.

Keith Seitz
2015-08-06T22:03:34Z

This is a new patch in the series.

--

This patch converts the (recently introduced) TUI register/group
completer, tui_reggroup_completer, to use add_completion.

gdb/ChangeLog

* tui/tui-regs.c (tui_reggroup_completer): Use add_completion
to add completions to the completion list.

gdb/testsuite/ChangeLog

* completion.exp: Add a completion-limit test for "tui reg".
---
gdb/testsuite/gdb.base/completion.exp | 5 +++++
gdb/tui/tui-regs.c | 6 +++++-
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 1036af5..07ce660 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -1058,6 +1058,11 @@ if {$signal_to_use != ""} {
test_completion_limit "print field_test_global.a" \
"print field_test_global\\\.a\[1-9\]_field" $max_completions

+# Test TUI's reg completer
+if {![skip_tui_tests]} {
+ test_completion_limit "tui reg " "tui reg \[a-z\]+" $max_completions
+}
+
#
# Test TUI completions
#
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 756f598..17efd9f 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -683,7 +683,11 @@ tui_reggroup_completer (struct completer_data *cdata,
for (tmp = extra; *tmp != NULL; ++tmp)
{
if (strncmp (word, *tmp, len) == 0)
- VEC_safe_push (char_ptr, result, xstrdup (*tmp));
+ {
+ if (add_completion (cdata, &result, *tmp, NULL, NULL)
+ == ADD_COMPLETION_MAX_REACHED)
+ break;
+ }
}

return result;