This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 12/18] Implement completion limiting for sim_command_completer.
- From: Keith Seitz <keiths at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 13 Apr 2015 12:23:31 -0700
- Subject: [PATCH 12/18] Implement completion limiting for sim_command_completer.
- Authentication-results: sourceware.org; auth=none
- References: <20150413192235 dot 29172 dot 13097 dot stgit at valrhona dot uglyboxes dot com>
This patch converts sim_command_completer to use maybe_add_completion.
It does not add any tests, since the `sim' command is highly
target-dependent and unimplemented for the majority of simulators.
gdb/ChangeLog
* remote-sim.c: Include completer.h.
(sim_command_completer): Use maybe_add_completion.
---
gdb/remote-sim.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 2bcb19e..5056a13 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -39,6 +39,7 @@
#include "arch-utils.h"
#include "readline/readline.h"
#include "gdbthread.h"
+#include "completer.h"
/* Prototypes */
@@ -1223,7 +1224,7 @@ sim_command_completer (struct completer_data *cdata,
{
struct sim_inferior_data *sim_data;
char **tmp;
- int i;
+ int i, stop;
VEC (char_ptr) *result = NULL;
sim_data = inferior_data (current_inferior (), sim_inferior_data_key);
@@ -1235,8 +1236,29 @@ sim_command_completer (struct completer_data *cdata,
return NULL;
/* Transform the array into a VEC, and then free the array. */
- for (i = 0; tmp[i] != NULL; i++)
- VEC_safe_push (char_ptr, result, tmp[i]);
+ for (i = 0, stop = 0; !stop && tmp[i] != NULL; i++)
+ {
+ enum maybe_add_completion_enum add_status;
+
+ add_status = maybe_add_completion (cdata, tmp[i]);
+ switch (add_status)
+ {
+ case MAYBE_ADD_COMPLETION_OK:
+ VEC_safe_push (char_ptr, result, tmp[i]);
+ break;
+ case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
+ VEC_safe_push (char_ptr, result, tmp[i]);
+ stop = 1;
+ break;
+ case MAYBE_ADD_COMPLETION_MAX_REACHED:
+ xfree (tmp[i]);
+ stop = 1;
+ break;
+ case MAYBE_ADD_COMPLETION_DUPLICATE:
+ xfree (tmp[i]);
+ break;
+ }
+ }
xfree (tmp);
return result;