[v3,13/19] Implement completion limiting for complete_on_enum.

Message ID 20150806191920.32159.96756.stgit@valrhona.uglyboxes.com
State New, archived
Headers

Commit Message

Keith Seitz Aug. 6, 2015, 7:19 p.m. UTC
  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

Doug Evans Aug. 23, 2015, 4:18 a.m. UTC | #1
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
  

Patch

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 3cecc90..fa95ee6 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -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;
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 3f56a13..6c81505 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -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
 #