[v3,13/19] Implement completion limiting for complete_on_enum.
Commit Message
Differences in this revision:
1. Remove partial copy code from complete_on_enum
---
This is another patch to push along the conversion of location_completer
toward using add_completion. In this patch, complete_on_enum is
converted. This function is also used by several other commands, such as
integer_unlimited_completer, handle_completer, cp_abi_completer, etc.
gdb/ChangeLog
* cli/cli-decode.c (complete_on_enum): Use add_completion.
gdb/testsuite/ChangeLog
* gdb.base/completion.exp: Add tests for complete_on_enum
completion limiting using "handle signal".
---
gdb/cli/cli-decode.c | 21 +++------------------
gdb/testsuite/gdb.base/completion.exp | 12 ++++++++++++
2 files changed, 15 insertions(+), 18 deletions(-)
Comments
Keith Seitz <keiths@redhat.com> writes:
> Differences in this revision:
>
> 1. Remove partial copy code from complete_on_enum
>
> ---
>
> This is another patch to push along the conversion of location_completer
> toward using add_completion. In this patch, complete_on_enum is
> converted. This function is also used by several other commands, such as
> integer_unlimited_completer, handle_completer, cp_abi_completer, etc.
>
> gdb/ChangeLog
>
> * cli/cli-decode.c (complete_on_enum): Use add_completion.
>
> gdb/testsuite/ChangeLog
>
> * gdb.base/completion.exp: Add tests for complete_on_enum
> completion limiting using "handle signal".
LGTM
@@ -1834,24 +1834,9 @@ complete_on_enum (struct completer_data *cdata,
for (i = 0; (name = enumlist[i]) != NULL; i++)
if (strncmp (name, text, textlen) == 0)
{
- char *match;
-
- match = (char *) xmalloc (strlen (word) + strlen (name) + 1);
- if (word == text)
- strcpy (match, name);
- else if (word > text)
- {
- /* Return some portion of name. */
- strcpy (match, name + (word - text));
- }
- else
- {
- /* Return some of text plus name. */
- strncpy (match, word, text - word);
- match[text - word] = '\0';
- strcat (match, name);
- }
- VEC_safe_push (char_ptr, matchlist, match);
+ if (add_completion (cdata, &matchlist, name, text, word)
+ == ADD_COMPLETION_MAX_REACHED)
+ break;
}
return matchlist;
@@ -1042,6 +1042,18 @@ with_test_prefix "interpreter_completer reset" {
test_completion_limit "info registers " \
"info registers \[a-zA-Z0-9\]+" $max_completions
+# Test complete_on_enum.
+set signal_to_use ""
+set signal_list [split \
+ [capture_command_output "complete handle signal " ""] \
+ \r\n]
+catch {lindex [split [lindex $signal_list 0]] 2} signal_to_use
+if {$signal_to_use != ""} {
+ test_completion_limit "handle signal $signal_to_use n" \
+ "handle signal $signal_to_use n\[a-z\]+" \
+ $max_completions
+}
+
#
# Test TUI completions
#