Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 06/18] Implement completion limiting for condition_completer.
Date: Mon, 13 Apr 2015 19:23:00 -0000	[thread overview]
Message-ID: <20150413192316.29172.89247.stgit@valrhona.uglyboxes.com> (raw)
In-Reply-To: <20150413192235.29172.13097.stgit@valrhona.uglyboxes.com>

This patch converts the condition completer to use maybe_add_completion.
A side-effect of this is the similar conversion of complete_internalvar.

Tests have been added to exercise this new behavior.

gdb/ChangeLog

	* breakpoint.c (condition_completer): Pass completer_data to
	complete_internalvar.
	Use maybe_add_completion.
	* value.c: Include completer.h.
	(complete_internalvar): Add completer_data argument.
	Use maybe_add_completion.
	* value.h (complete_internalvar): Add completer_data argument.

gdb/testsuite/ChangeLog

	* gdb.base/condbreak.exp (test_completion): New procedure.
	Add more completion tests, with and without limiting.
---
 gdb/breakpoint.c                     |   24 +++++++++++-
 gdb/testsuite/gdb.base/condbreak.exp |   70 ++++++++++++++++++++++++++++++++++
 gdb/value.c                          |   21 +++++++++-
 gdb/value.h                          |    3 +
 4 files changed, 113 insertions(+), 5 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 095fdf2..04dc734 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1052,7 +1052,7 @@ condition_completer (struct completer_data *cdata,
 	  /* We don't support completion of history indices.  */
 	  if (isdigit (text[1]))
 	    return NULL;
-	  return complete_internalvar (&text[1]);
+	  return complete_internalvar (cdata, &text[1]);
 	}
 
       /* We're completing the breakpoint number.  */
@@ -1065,7 +1065,27 @@ condition_completer (struct completer_data *cdata,
 	  xsnprintf (number, sizeof (number), "%d", b->number);
 
 	  if (strncmp (number, text, len) == 0)
-	    VEC_safe_push (char_ptr, result, xstrdup (number));
+	    {
+	      enum maybe_add_completion_enum add_status;
+	      char *completion = xstrdup (number);
+
+	      add_status = maybe_add_completion (cdata, completion);
+	      switch (add_status)
+		{
+		case MAYBE_ADD_COMPLETION_OK:
+		  VEC_safe_push (char_ptr, result, completion);
+		  break;
+		case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+		  VEC_safe_push (char_ptr, result, completion);
+		  return result;
+		case MAYBE_ADD_COMPLETION_MAX_REACHED:
+		  xfree (completion);
+		  return result;
+		case MAYBE_ADD_COMPLETION_DUPLICATE:
+		  xfree (completion);
+		  break;
+		}
+	    }
 	}
 
       return result;
diff --git a/gdb/testsuite/gdb.base/condbreak.exp b/gdb/testsuite/gdb.base/condbreak.exp
index fa40a5f..5630ede 100644
--- a/gdb/testsuite/gdb.base/condbreak.exp
+++ b/gdb/testsuite/gdb.base/condbreak.exp
@@ -246,3 +246,73 @@ gdb_test "complete cond 1" "cond 1"
 gdb_test "set variable \$var = 1"
 gdb_test "complete cond \$v" "cond \\\$var"
 gdb_test "complete cond 1 values\[0\].a" "cond 1 values.0..a_field"
+
+# Test non-trivial completion and completion-limiting
+
+# Delete all breakpoints and create a bunch of new ones.
+delete_breakpoints
+for {set i 0} {$i < 20} {incr i} {
+    with_test_prefix "set breakpoint $i" {
+	gdb_breakpoint "factorial"
+    }
+}
+
+# While the completer function does traverse breakpoints in the order
+# they were created, don't assume that is required for the test.
+# We only count the number of completions found.  In this case,
+# this test will create breakpoints 9-19, giving "complete cond 1"
+# ten total completion possibilities.
+
+# A convenience procedure to automate test completion lists.
+proc test_completion {cmd exp total {limit 0}} {
+    global gdb_prompt
+
+    if {$limit} {
+	set end "\\\*\\\*\\\* List may be truncated, "
+	append end "max-completions reached\\\. \\\*\\\*\\\*\r\n"
+	set testname "limit '$cmd'"
+    } else {
+	set end ""
+	set testname $cmd
+    }
+
+    set seen 0
+    gdb_test_multiple $cmd $testname {
+	"$cmd\r\n" { exp_continue }
+
+	-re "cond $exp\[0-9\]+\r\n" {
+	    incr seen
+	    exp_continue
+	}
+
+	-re ".*$end$gdb_prompt $" {
+	    if {$seen == $total} {
+		pass $testname
+	    } else {
+		fail "$testname ($seen/$total)"
+	    }
+	}
+    }
+}
+
+# Test completion of breakpoint number.
+with_test_prefix "completion test:" {
+    test_completion "complete cond 1" "1" 10
+}
+
+# Test completion of breakpoint number using internal variable.
+for {set i 0} {$i < 10} {incr i} {
+    gdb_test_no_output "set variable \$var_bp_$i = $i"
+}
+
+test_completion "complete cond \$var_bp" "\\\$var_bp_" 10
+
+# Run the above tests with completion limiting.
+set max_completions 4
+gdb_test_no_output "set max-completions $max_completions"
+
+with_test_prefix "completion test:" {
+    test_completion "complete cond 1" "1" $max_completions 1
+}
+
+test_completion "complete cond \$var_bp" "\\\$var_bp_" $max_completions 1
diff --git a/gdb/value.c b/gdb/value.c
index cb56849..8519b91 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -40,6 +40,7 @@
 #include "tracepoint.h"
 #include "cp-abi.h"
 #include "user-regs.h"
+#include "completer.h"
 
 /* Prototypes for exported functions.  */
 
@@ -2029,7 +2030,7 @@ lookup_only_internalvar (const char *name)
    were found.  */
 
 VEC (char_ptr) *
-complete_internalvar (const char *name)
+complete_internalvar (struct completer_data *cdata, const char *name)
 {
   VEC (char_ptr) *result = NULL;
   struct internalvar *var;
@@ -2041,8 +2042,24 @@ complete_internalvar (const char *name)
     if (strncmp (var->name, name, len) == 0)
       {
 	char *r = xstrdup (var->name);
+	enum maybe_add_completion_enum add_status;
 
-	VEC_safe_push (char_ptr, result, r);
+	add_status = maybe_add_completion (cdata, r);
+	switch (add_status)
+	  {
+	  case MAYBE_ADD_COMPLETION_OK:
+	    VEC_safe_push (char_ptr, result, r);
+	    break;
+	  case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+	    VEC_safe_push (char_ptr, result, r);
+	    return result;
+	  case MAYBE_ADD_COMPLETION_MAX_REACHED:
+	    xfree (r);
+	    return result;
+	  case MAYBE_ADD_COMPLETION_DUPLICATE:
+	    xfree (r);
+	    break;
+	  }
       }
 
   return result;
diff --git a/gdb/value.h b/gdb/value.h
index 21baa32..41aec1b 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -872,7 +872,8 @@ extern struct internalvar *lookup_only_internalvar (const char *name);
 
 extern struct internalvar *create_internalvar (const char *name);
 
-extern VEC (char_ptr) *complete_internalvar (const char *name);
+extern VEC (char_ptr) *complete_internalvar (struct completer_data *cdata,
+					     const char *name);
 
 /* An internalvar can be dynamically computed by supplying a vector of
    function pointers to perform various operations.  */


  parent reply	other threads:[~2015-04-13 19:23 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 19:23 [PATCH 00/18] Implement full completer limiting Keith Seitz
2015-04-13 19:23 ` [PATCH 03/18] Implement completion limiting for complete_on_cmdlist Keith Seitz
2015-04-13 19:23 ` [PATCH 01/18] Add struct completer_data to the completion API Keith Seitz
2015-04-13 19:23 ` [PATCH 04/18] Implement completion limiting for add_filename_to_list Keith Seitz
2015-04-13 19:23 ` [PATCH 05/18] Implement completion limiting for ada_make_symbol_completion_list Keith Seitz
2015-04-13 19:23 ` [PATCH 08/18] Implement completion limiting for signal_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 11/18] Implement completion limiting for reg_or_group_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 02/18] Remove completion_tracker_t from the public completion API Keith Seitz
2015-04-13 19:23 ` [PATCH 17/18] Use the hashtable to accumulate completion results Keith Seitz
2015-04-13 19:23 ` [PATCH 15/18] Implement completion limiting for scmcmd_add_completion Keith Seitz
2015-04-13 19:23 ` [PATCH 10/18] Implement completion limiting for cmdpy_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 13/18] Implement completion limiting for complete_on_enum Keith Seitz
2015-04-13 19:23 ` [PATCH 12/18] Implement completion limiting for sim_command_completer Keith Seitz
2015-04-14 15:28   ` Mike Frysinger
2015-05-05 15:03     ` Keith Seitz
2015-05-05 15:34       ` Mike Frysinger
2015-05-05 15:53         ` Keith Seitz
2015-04-13 19:23 ` Keith Seitz [this message]
2015-04-13 19:23 ` [PATCH 18/18] Remove the vector return result from the completion API Keith Seitz
2015-04-13 19:23 ` [PATCH 09/18] Implement completion limiting for interpreter_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 16/18] Make the completion API completely opaque Keith Seitz
2015-04-13 19:23 ` [PATCH 07/18] Implement completion limiting for filename_completer Keith Seitz
2015-04-13 19:23 ` [PATCH 14/18] Implement completion limiting in add_struct_fields Keith Seitz
2015-04-20  3:21 ` [PATCH 00/18] Implement full completer limiting Doug Evans
2015-04-29 19:19   ` Keith Seitz
2015-04-30  0:26     ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150413192316.29172.89247.stgit@valrhona.uglyboxes.com \
    --to=keiths@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox