This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Fix GDB builds that include the simulator
- From: Pedro Alves <palves at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 18 Jul 2017 10:41:23 -0000
- Subject: [binutils-gdb] Fix GDB builds that include the simulator
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=386535dd91432b784f6a46f8a92c6a599ba30174
commit 386535dd91432b784f6a46f8a92c6a599ba30174
Author: Pedro Alves <palves@redhat.com>
Date: Tue Jul 18 11:38:17 2017 +0100
Fix GDB builds that include the simulator
The completer rewrite series missed adjusting target sim to the new
completion_tracker interface.
src/gdb/remote-sim.c: In function â??void _initialize_remote_sim()â??:
src/gdb/remote-sim.c:1350:46: error: invalid conversion from â??VEC_char_ptr* (*)(cmd_list_element*, const char*, const char*)â?? to â??void (*)(cmd_list_element*, completion_tracker&, const char*, const char*)â?? [-fpermissive]
set_cmd_completer (c, sim_command_completer);
^
This commit fixes it, and also takes care to be exception safe (the
previous code would leak if growing the VEC throws).
Tested manually with a --target=arm-none-eabi build.
gdb/ChangeLog:
2017-07-18 Pedro Alves <palves@redhat.com>
* remote-sim.c (sim_command_completer): Adjust to work with a
completion_tracker instead of a VEC.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/remote-sim.c | 48 +++++++++++++++++++++++++++++++++---------------
2 files changed, 38 insertions(+), 15 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 20344f7..66ae527 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-18 Pedro Alves <palves@redhat.com>
+
+ * remote-sim.c (sim_command_completer): Adjust to work with a
+ completion_tracker instead of a VEC.
+
2017-07-17 Pedro Alves <palves@redhat.com>
* completer.c (complete_source_filenames): New function.
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 13137ab..508e2c2 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -1220,30 +1220,48 @@ simulator_command (char *args, int from_tty)
registers_changed ();
}
-static VEC (char_ptr) *
-sim_command_completer (struct cmd_list_element *ignore, const char *text,
- const char *word)
+static void
+sim_command_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char *word)
{
struct sim_inferior_data *sim_data;
- char **tmp;
- int i;
- VEC (char_ptr) *result = NULL;
sim_data = ((struct sim_inferior_data *)
inferior_data (current_inferior (), sim_inferior_data_key));
if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
- return NULL;
+ return;
- tmp = sim_complete_command (sim_data->gdbsim_desc, text, word);
- if (tmp == NULL)
- return NULL;
+ /* sim_complete_command returns a NULL-terminated malloc'ed array of
+ malloc'ed strings. */
+ struct sim_completions_deleter
+ {
+ void operator() (char **ptr) const
+ {
+ for (size_t i = 0; ptr[i] != NULL; i++)
+ xfree (ptr[i]);
+ xfree (ptr);
+ }
+ };
+
+ std::unique_ptr<char *[], sim_completions_deleter> sim_completions
+ (sim_complete_command (sim_data->gdbsim_desc, text, word));
+ if (sim_completions == NULL)
+ return;
- /* 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]);
- xfree (tmp);
+ /* Count the elements and add completions from tail to head because
+ below we'll swap elements out of the array in case add_completion
+ throws and the deleter deletes until it finds a NULL element. */
+ size_t count = 0;
+ while (sim_completions[count] != NULL)
+ count++;
- return result;
+ for (size_t i = count; i > 0; i--)
+ {
+ gdb::unique_xmalloc_ptr<char> match (sim_completions[i - 1]);
+ sim_completions[i - 1] = NULL;
+ tracker.add_completion (std::move (match));
+ }
}
/* Check to see if a thread is still alive. */