* [PATCH] gdb: sim: add command line completion
@ 2011-04-07 23:32 Mike Frysinger
2011-04-14 20:02 ` Tom Tromey
2011-04-15 3:20 ` [PATCH v2] " Mike Frysinger
0 siblings, 2 replies; 7+ messages in thread
From: Mike Frysinger @ 2011-04-07 23:32 UTC (permalink / raw)
To: gdb-patches; +Cc: toolchain-devel
For now, only the sub-command name is completed. No support yet for
completing options to that command. But even this is a huge step as
currently, nothing is completed, and the basic "help sim" is fairly
obtuse as to what exactly the "sim" command accepts.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
gdb/:
2011-04-07 Mike Frysinger <vapier@gentoo.org>
* remote-sim.c (sim_command_completer): New function.
(_initialize_remote_sim): Set completer to sim_command_completer.
include/gdb/:
2011-04-07 Mike Frysinger <vapier@gentoo.org>
* remote-sim.h (sim_complete_command): New prototype.
sim/:
2011-04-07 Mike Frysinger <vapier@gentoo.org>
* sim-options.c (complete_option_list, sim_complete_command):
New functions.
---
gdb/remote-sim.c | 19 +++++++++++++++-
include/gdb/remote-sim.h | 4 +++
sim/common/sim-options.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index baaf439..f9232b5 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -1193,6 +1193,18 @@ simulator_command (char *args, int from_tty)
registers_changed ();
}
+char **sim_command_completer (struct cmd_list_element *ignore,
+ char *text, char *word)
+{
+ struct sim_inferior_data *sim_data;
+
+ sim_data = inferior_data (current_inferior (), sim_inferior_data_key);
+ if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
+ return NULL;
+
+ return sim_complete_command (sim_data->gdbsim_desc, text, word);
+}
+
/* Check to see if a thread is still alive. */
static int
@@ -1287,11 +1299,14 @@ init_gdbsim_ops (void)
void
_initialize_remote_sim (void)
{
+ struct cmd_list_element *c;
+
init_gdbsim_ops ();
add_target (&gdbsim_ops);
- add_com ("sim", class_obscure, simulator_command,
- _("Send a command to the simulator."));
+ c = add_com ("sim", class_obscure, simulator_command,
+ _("Send a command to the simulator."));
+ set_cmd_completer (c, sim_command_completer);
sim_inferior_data_key
= register_inferior_data_with_cleanup (sim_inferior_data_cleanup);
diff --git a/include/gdb/remote-sim.h b/include/gdb/remote-sim.h
index a171cfd..5f6000d 100644
--- a/include/gdb/remote-sim.h
+++ b/include/gdb/remote-sim.h
@@ -276,6 +276,10 @@ void sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
void sim_do_command (SIM_DESC sd, char *cmd);
+/* Complete a command based on the available sim commands. Returns an
+ array of possible matches. */
+char **sim_complete_command (SIM_DESC sd, char *text, char *word);
+
#ifdef __cplusplus
}
#endif
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index 0b4d4ee..ee8a8ec 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -915,6 +915,57 @@ find_match (SIM_DESC sd, sim_cpu *cpu, char *argv[], int *pargi)
return matching_opt;
}
+static char **
+complete_option_list (char **ret, size_t *cnt, const struct option_list *ol,
+ char *text, char *word)
+{
+ const OPTION *opt = NULL;
+ int argi;
+ size_t len = strlen (word);
+
+ for ( ; ol != NULL; ol = ol->next)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
+ {
+ const char *name = opt->opt.name;
+
+ /* A long option to match against? */
+ if (!name)
+ continue;
+
+ /* Does this option actually match? */
+ if (strncmp (name, word, len))
+ continue;
+
+ ret = xrealloc (ret, ++*cnt * sizeof (ret[0]));
+ ret[*cnt - 2] = xstrdup (name);
+ }
+
+ return ret;
+}
+
+/* All leading text is stored in @text, while the current word being
+ completed is stored in @word. Trailing text of @word is not. */
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ char **ret = NULL;
+ size_t cnt = 1;
+ sim_cpu *cpu;
+
+ /* Only complete first word for now. */
+ if (text != word)
+ return ret;
+
+ cpu = STATE_CPU (sd, 0);
+ if (cpu)
+ ret = complete_option_list (ret, &cnt, CPU_OPTIONS (cpu), text, word);
+ ret = complete_option_list (ret, &cnt, STATE_OPTIONS (sd), text, word);
+
+ if (ret)
+ ret[cnt - 1] = NULL;
+ return ret;
+}
+
SIM_RC
sim_args_command (SIM_DESC sd, char *cmd)
{
--
1.7.4.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] gdb: sim: add command line completion
2011-04-07 23:32 [PATCH] gdb: sim: add command line completion Mike Frysinger
@ 2011-04-14 20:02 ` Tom Tromey
2011-04-15 3:44 ` [toolchain-devel] " Mike Frysinger
2011-04-15 3:20 ` [PATCH v2] " Mike Frysinger
1 sibling, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2011-04-14 20:02 UTC (permalink / raw)
To: Mike Frysinger; +Cc: gdb-patches, toolchain-devel
>>>>> "Mike" == Mike Frysinger <vapier@gentoo.org> writes:
Mike> For now, only the sub-command name is completed. No support yet for
Mike> completing options to that command. But even this is a huge step as
Mike> currently, nothing is completed, and the basic "help sim" is fairly
Mike> obtuse as to what exactly the "sim" command accepts.
Thanks for doing this.
Mike> +char **sim_command_completer (struct cmd_list_element *ignore,
Mike> + char *text, char *word)
I think this could be static.
And, newline after the initial "char **".
I don't really know anything about sim, but I didn't see anything
obviously bad in there. So, ok with the above change.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [toolchain-devel] [PATCH] gdb: sim: add command line completion
2011-04-14 20:02 ` Tom Tromey
@ 2011-04-15 3:44 ` Mike Frysinger
2011-04-19 17:13 ` Tom Tromey
0 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2011-04-15 3:44 UTC (permalink / raw)
To: Tom Tromey; +Cc: toolchain-devel, gdb-patches
On Thu, Apr 14, 2011 at 16:01, Tom Tromey wrote:
> Mike Frysinger writes:
>> +char **sim_command_completer (struct cmd_list_element *ignore,
>> + char *text, char *word)
>
> I think this could be static.
> And, newline after the initial "char **".
np, updated patch should fix that and one or two other style things.
ive committed that.
> I don't really know anything about sim, but I didn't see anything
> obviously bad in there. So, ok with the above change.
well, it works for me :)
side note that i meant to ask about earlier, i noticed that i cant
complete things that have a dash in its name. seems because of
readline having this marked as a word break char (which is
understandable as it is usually used in math expressions). any way
around this ?
e.g. if i do:
(gdb) sim h<tab>
i get back:
help hw-board-file hw-device hw-file hw-info hw-list hw-trace
and so if i do:
(gdb) sim hw<tab>
it goes to "hw-", but now if i hit <tab>, i get nothing back. in the
completer, the word is set to "" and the text is "hw-" ...
-mike
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [toolchain-devel] [PATCH] gdb: sim: add command line completion
2011-04-15 3:44 ` [toolchain-devel] " Mike Frysinger
@ 2011-04-19 17:13 ` Tom Tromey
0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2011-04-19 17:13 UTC (permalink / raw)
To: Mike Frysinger; +Cc: toolchain-devel, gdb-patches
>>>>> "Mike" == Mike Frysinger <vapier@gentoo.org> writes:
Mike> side note that i meant to ask about earlier, i noticed that i cant
Mike> complete things that have a dash in its name. seems because of
Mike> readline having this marked as a word break char (which is
Mike> understandable as it is usually used in math expressions). any way
Mike> around this ?
I never remember exactly what happens here, I always have to look it up
or debug by hand.
Look for rl_completer_word_break_characters, maybe.
Also I think you can handle the completion differently by examining the
full `text' argument, though, again, I always have to look this up to
figure out what it all means.
Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] gdb: sim: add command line completion
2011-04-07 23:32 [PATCH] gdb: sim: add command line completion Mike Frysinger
2011-04-14 20:02 ` Tom Tromey
@ 2011-04-15 3:20 ` Mike Frysinger
2011-04-16 11:40 ` Richard Earnshaw
1 sibling, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2011-04-15 3:20 UTC (permalink / raw)
To: gdb-patches; +Cc: toolchain-devel
For now, only the sub-command name is completed. No support yet for
completing options to that command. But even this is a huge step as
currently, nothing is completed, and the basic "help sim" is fairly
obtuse as to what exactly the "sim" command accepts.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
gdb/:
2011-04-07 Mike Frysinger <vapier@gentoo.org>
* remote-sim.c (sim_command_completer): New function.
(_initialize_remote_sim): Set completer to sim_command_completer.
include/gdb/:
2011-04-07 Mike Frysinger <vapier@gentoo.org>
* remote-sim.h (sim_complete_command): New prototype.
sim/:
2011-04-07 Mike Frysinger <vapier@gentoo.org>
* sim-options.c (complete_option_list, sim_complete_command):
New functions.
---
v2
- mark sim_command_completer static
- tweak style in a few places
gdb/remote-sim.c | 19 +++++++++++++++-
include/gdb/remote-sim.h | 5 ++++
sim/common/sim-options.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index baaf439..bf4e0ee 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -1193,6 +1193,18 @@ simulator_command (char *args, int from_tty)
registers_changed ();
}
+static char **
+sim_command_completer (struct cmd_list_element *ignore, char *text, char *word)
+{
+ struct sim_inferior_data *sim_data;
+
+ sim_data = inferior_data (current_inferior (), sim_inferior_data_key);
+ if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
+ return NULL;
+
+ return sim_complete_command (sim_data->gdbsim_desc, text, word);
+}
+
/* Check to see if a thread is still alive. */
static int
@@ -1287,11 +1299,14 @@ init_gdbsim_ops (void)
void
_initialize_remote_sim (void)
{
+ struct cmd_list_element *c;
+
init_gdbsim_ops ();
add_target (&gdbsim_ops);
- add_com ("sim", class_obscure, simulator_command,
- _("Send a command to the simulator."));
+ c = add_com ("sim", class_obscure, simulator_command,
+ _("Send a command to the simulator."));
+ set_cmd_completer (c, sim_command_completer);
sim_inferior_data_key
= register_inferior_data_with_cleanup (sim_inferior_data_cleanup);
diff --git a/include/gdb/remote-sim.h b/include/gdb/remote-sim.h
index a171cfd..14a86a8 100644
--- a/include/gdb/remote-sim.h
+++ b/include/gdb/remote-sim.h
@@ -276,6 +276,11 @@ void sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
void sim_do_command (SIM_DESC sd, char *cmd);
+/* Complete a command based on the available sim commands. Returns an
+ array of possible matches. */
+
+char **sim_complete_command (SIM_DESC sd, char *text, char *word);
+
#ifdef __cplusplus
}
#endif
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index 0b4d4ee..cfc572c 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -915,6 +915,58 @@ find_match (SIM_DESC sd, sim_cpu *cpu, char *argv[], int *pargi)
return matching_opt;
}
+static char **
+complete_option_list (char **ret, size_t *cnt, const struct option_list *ol,
+ char *text, char *word)
+{
+ const OPTION *opt = NULL;
+ int argi;
+ size_t len = strlen (word);
+
+ for ( ; ol != NULL; ol = ol->next)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
+ {
+ const char *name = opt->opt.name;
+
+ /* A long option to match against? */
+ if (!name)
+ continue;
+
+ /* Does this option actually match? */
+ if (strncmp (name, word, len))
+ continue;
+
+ ret = xrealloc (ret, ++*cnt * sizeof (ret[0]));
+ ret[*cnt - 2] = xstrdup (name);
+ }
+
+ return ret;
+}
+
+/* All leading text is stored in @text, while the current word being
+ completed is stored in @word. Trailing text of @word is not. */
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ char **ret = NULL;
+ size_t cnt = 1;
+ sim_cpu *cpu;
+
+ /* Only complete first word for now. */
+ if (text != word)
+ return ret;
+
+ cpu = STATE_CPU (sd, 0);
+ if (cpu)
+ ret = complete_option_list (ret, &cnt, CPU_OPTIONS (cpu), text, word);
+ ret = complete_option_list (ret, &cnt, STATE_OPTIONS (sd), text, word);
+
+ if (ret)
+ ret[cnt - 1] = NULL;
+ return ret;
+}
+
SIM_RC
sim_args_command (SIM_DESC sd, char *cmd)
{
--
1.7.5.rc1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2] gdb: sim: add command line completion
2011-04-15 3:20 ` [PATCH v2] " Mike Frysinger
@ 2011-04-16 11:40 ` Richard Earnshaw
2011-04-16 18:33 ` Mike Frysinger
0 siblings, 1 reply; 7+ messages in thread
From: Richard Earnshaw @ 2011-04-16 11:40 UTC (permalink / raw)
To: Mike Frysinger; +Cc: gdb-patches, toolchain-devel
On 15/04/11 04:20, Mike Frysinger wrote:
> For now, only the sub-command name is completed. No support yet for
> completing options to that command. But even this is a huge step as
> currently, nothing is completed, and the basic "help sim" is fairly
> obtuse as to what exactly the "sim" command accepts.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>
> gdb/:
> 2011-04-07 Mike Frysinger <vapier@gentoo.org>
>
> * remote-sim.c (sim_command_completer): New function.
> (_initialize_remote_sim): Set completer to sim_command_completer.
>
> include/gdb/:
> 2011-04-07 Mike Frysinger <vapier@gentoo.org>
>
> * remote-sim.h (sim_complete_command): New prototype.
>
> sim/:
> 2011-04-07 Mike Frysinger <vapier@gentoo.org>
>
> * sim-options.c (complete_option_list, sim_complete_command):
> New functions.
This breaks building gdb for arm-eabi.
/home/rearnsha/gnusrc/gcc-cross/git/gdb/remote-sim.c:1205: undefined
reference to `sim_complete_command'
Note the ARM simulator doesn't use most of the sim/common infrastructure.
R.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] gdb: sim: add command line completion
2011-04-16 11:40 ` Richard Earnshaw
@ 2011-04-16 18:33 ` Mike Frysinger
0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2011-04-16 18:33 UTC (permalink / raw)
To: Richard Earnshaw; +Cc: gdb-patches, toolchain-devel
[-- Attachment #1: Type: Text/Plain, Size: 3289 bytes --]
On Saturday, April 16, 2011 07:35:17 Richard Earnshaw wrote:
> On 15/04/11 04:20, Mike Frysinger wrote:
> > sim/:
> > 2011-04-07 Mike Frysinger <vapier@gentoo.org>
> >
> > * sim-options.c (complete_option_list, sim_complete_command):
> > New functions.
>
> This breaks building gdb for arm-eabi.
>
> /home/rearnsha/gnusrc/gcc-cross/git/gdb/remote-sim.c:1205: undefined
> reference to `sim_complete_command'
>
> Note the ARM simulator doesn't use most of the sim/common infrastructure.
blah, i sometimes forget many sims live in the past. ive added stubs to a
bunch of arches in the following patch.
these targets pass for me now:
arm avr bfin cr16 cris frv h8300 iq2000 lm32 m32c m32r m68hc11 microblaze mips
mn10300 moxie ppc rx sh sh64 v850
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* wrapper.c (sim_complete_command): New stub function.
--- arm/wrapper.c
+++ arm/wrapper.c
@@ -940,3 +940,9 @@ sim_set_callbacks (ptr)
{
sim_callback = ptr;
}
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_complete_command): New stub function.
--- avr/interp.c
+++ avr/interp.c
@@ -1853,3 +1853,9 @@ sim_set_callbacks (host_callback *ptr)
{
callback = ptr;
}
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* gdb-if.c (sim_complete_command): New stub function.
--- m32c/gdb-if.c
+++ m32c/gdb-if.c
@@ -703,3 +703,9 @@ sim_do_command (SIM_DESC sd, char *cmd)
printf ("The 'sim' command expects either 'trace' or 'verbose'"
" as a subcommand.\n");
}
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_complete_command): New stub function.
--- microblaze/interp.c
+++ microblaze/interp.c
@@ -1089,3 +1089,9 @@ sim_set_callbacks (host_callback *ptr)
{
callback = ptr;
}
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* sim_calls.c (sim_complete_command): New stub function.
--- ppc/sim_calls.c
+++ ppc/sim_calls.c
@@ -259,6 +259,11 @@ sim_do_command (SIM_DESC sd, char *cmd)
}
}
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
/* Polling, if required */
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* gdb-if.c (sim_complete_command): New stub function.
--- rx/gdb-if.c
+++ rx/gdb-if.c
@@ -862,3 +862,9 @@ sim_do_command (SIM_DESC sd, char *cmd)
printf ("The 'sim' command expects either 'trace' or 'verbose'"
" as a subcommand.\n");
}
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
2011-04-16 Mike Frysinger <vapier@gentoo.org>
* interp.c (sim_complete_command): New stub function.
--- sh/interp.c
+++ sh/interp.c
@@ -2787,3 +2787,9 @@ sim_set_callbacks (p)
{
callback = p;
}
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ return NULL;
+}
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-04-19 17:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07 23:32 [PATCH] gdb: sim: add command line completion Mike Frysinger
2011-04-14 20:02 ` Tom Tromey
2011-04-15 3:44 ` [toolchain-devel] " Mike Frysinger
2011-04-19 17:13 ` Tom Tromey
2011-04-15 3:20 ` [PATCH v2] " Mike Frysinger
2011-04-16 11:40 ` Richard Earnshaw
2011-04-16 18:33 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox