* [PATCH] [PR cli/16269] Add completer for the inferior commands
@ 2020-12-22 21:54 Lancelot SIX via Gdb-patches
2021-01-17 18:50 ` Lancelot SIX via Gdb-patches
0 siblings, 1 reply; 2+ messages in thread
From: Lancelot SIX via Gdb-patches @ 2020-12-22 21:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Lancelot SIX
This patch adds or improves completers for the following commands:
* inferior
* add-inferior
* clone-inferior
* remove-inferiors
* kill inferiors
* detach inferiors
Before the patch, the 'inferior', 'clone-inferior', 'remove-inferiors',
'kill inferiors' and 'detach inferiors' commands complete on symbols
which is unexpected. The 'add-inferior' only completes on filename and
fails to complete on option flags.
Tested with 'make check TESTS="gdb.base/completion.exp"'
My copyright assignment is still pending.
gdb/ChangeLog:
2020-12-22 Lancelot SIX <lsix@lancelotsix.com>
PR cli/16269
* inferior.c (inferior_id_completer): add completer
(add_inferior_completer): add completer
(clone_inferior_completer): add completer
(initialize_inferiors): declare use of completers
gdb/testsuite/ChangeLog:
2020-12-22 Lancelot SIX <lsix@lancelotsix.com>
PR cli/16269
* gdb.base/completion.exp: test completion of inferior related
commands
---
gdb/inferior.c | 61 ++++++++++++++++++++++++---
gdb/testsuite/gdb.base/completion.exp | 18 ++++++++
2 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/gdb/inferior.c b/gdb/inferior.c
index a6652b6920..406e5030d7 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -539,6 +539,22 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
}
}
+/* Complete available inferior IDs */
+
+static void
+inferior_id_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char *word)
+{
+ for (inferior *inf : all_inferiors ())
+ {
+ std::string const st = std::to_string (inf->num);
+ if (st.rfind(text, 0) == 0)
+ tracker.add_completion
+ (make_completion_match_str (st.c_str (), text, word));
+ }
+}
+
static void
detach_inferior_command (const char *args, int from_tty)
{
@@ -833,6 +849,20 @@ add_inferior_command (const char *args, int from_tty)
}
}
+/* Completer for the add-inferior command */
+
+static void
+add_inferior_completer (struct cmd_list_element *cmd,
+ completion_tracker &tracker,
+ const char *text, const char *word)
+{
+ static const char * const options[] = {
+ "-copies", "-exec", "-no-connection", nullptr
+ };
+ complete_on_enum (tracker, options, text, word);
+ filename_completer (cmd, tracker, text, word);
+}
+
/* clone-inferior [-copies N] [ID] [-no-connection] */
static void
@@ -919,6 +949,20 @@ clone_inferior_command (const char *args, int from_tty)
}
}
+/* Completer for the clone-inferior command */
+
+static void
+clone_inferior_completer (struct cmd_list_element *cmd,
+ completion_tracker &tracker,
+ const char *text, const char *word)
+{
+ static const char * const options[] = {
+ "-copies", "-no-connection", nullptr
+ };
+ complete_on_enum (tracker, options, text, word);
+ inferior_id_completer (cmd, tracker, text, word);
+}
+
/* Print notices when new inferiors are created and die. */
static void
show_print_inferior_events (struct ui_file *file, int from_tty,
@@ -981,13 +1025,14 @@ as main program.\n\
By default, the new inferior inherits the current inferior's connection.\n\
If -no-connection is specified, the new inferior begins with\n\
no target connection yet."));
- set_cmd_completer (c, filename_completer);
+ set_cmd_completer (c, add_inferior_completer);
- add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
+ c = add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
Remove inferior ID (or list of IDs).\n\
Usage: remove-inferiors ID..."));
+ set_cmd_completer(c, inferior_id_completer);
- add_com ("clone-inferior", no_class, clone_inferior_command, _("\
+ c = add_com ("clone-inferior", no_class, clone_inferior_command, _("\
Clone inferior ID.\n\
Usage: clone-inferior [-copies N] [-no-connection] [ID]\n\
Add N copies of inferior ID. The new inferiors have the same\n\
@@ -997,22 +1042,26 @@ that is cloned.\n\
By default, the new inferiors inherit the copied inferior's connection.\n\
If -no-connection is specified, the new inferiors begin with\n\
no target connection yet."));
+ set_cmd_completer (c, clone_inferior_completer);
- add_cmd ("inferiors", class_run, detach_inferior_command, _("\
+ c = add_cmd ("inferiors", class_run, detach_inferior_command, _("\
Detach from inferior ID (or list of IDS).\n\
Usage; detach inferiors ID..."),
&detachlist);
+ set_cmd_completer(c, inferior_id_completer);
- add_cmd ("inferiors", class_run, kill_inferior_command, _("\
+ c = add_cmd ("inferiors", class_run, kill_inferior_command, _("\
Kill inferior ID (or list of IDs).\n\
Usage: kill inferiors ID..."),
&killlist);
+ set_cmd_completer(c, inferior_id_completer);
- add_cmd ("inferior", class_run, inferior_command, _("\
+ c = add_cmd ("inferior", class_run, inferior_command, _("\
Use this command to switch between inferiors.\n\
Usage: inferior ID\n\
The new inferior ID must be currently known."),
&cmdlist);
+ set_cmd_completer(c, inferior_id_completer);
add_setshow_boolean_cmd ("inferior-events", no_class,
&print_inferior_events, _("\
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 8000d52049..cc3b7b7182 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -975,3 +975,21 @@ test_gdb_complete_unique "xxx_yyy_" "xxx_yyy_zzz"
gdb_test_no_output "alias set aaa_bbb_ccc=set debug"
gdb_test_no_output "maint deprecate set aaa_bbb_ccc"
test_gdb_complete_unique "set aaa_bbb_" "set aaa_bbb_ccc"
+
+# Test completion of inferior related commands
+
+gdb_test "complete add-inferior -cop" "-copies"
+gdb_test "complete add-inferior -no-con" "-no-connection"
+gdb_test "complete add-inferior -e" "-exec"
+
+gdb_test "complete clone-inferior -c" "-copies"
+gdb_test "complete clone-inferior -n" "-no-connection"
+
+# The following test will ensure that the completer yields the list of
+# available inferiors. We expect to only have 1 present, with ID '1'
+gdb_test "complete clone-inferior " ".*clone-inferior 1.*"
+
+gdb_test "complete remove-inferiors " "remove-inferiors 1"
+gdb_test "complete kill inferiors " "kill inferiors 1"
+gdb_test "complete detach inferiors " "detach inferiors 1"
+gdb_test "complete inferior " "inferior 1"
--
2.29.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [PR cli/16269] Add completer for the inferior commands
2020-12-22 21:54 [PATCH] [PR cli/16269] Add completer for the inferior commands Lancelot SIX via Gdb-patches
@ 2021-01-17 18:50 ` Lancelot SIX via Gdb-patches
0 siblings, 0 replies; 2+ messages in thread
From: Lancelot SIX via Gdb-patches @ 2021-01-17 18:50 UTC (permalink / raw)
To: gdb-patches
Hi,
Even if those completers are an improvement to the actual state of
things, I realise they still have limitations.
I’ll work on a new version of this patch, and will probably migrate the
inferior related commands to gdb::option style.
This patch can be ignored as it is.
Lancelot.
Le Tue, Dec 22, 2020 at 09:54:39PM +0000, Lancelot SIX a écrit :
> This patch adds or improves completers for the following commands:
>
> * inferior
> * add-inferior
> * clone-inferior
> * remove-inferiors
> * kill inferiors
> * detach inferiors
>
> Before the patch, the 'inferior', 'clone-inferior', 'remove-inferiors',
> 'kill inferiors' and 'detach inferiors' commands complete on symbols
> which is unexpected. The 'add-inferior' only completes on filename and
> fails to complete on option flags.
>
> Tested with 'make check TESTS="gdb.base/completion.exp"'
>
> My copyright assignment is still pending.
>
> gdb/ChangeLog:
>
> 2020-12-22 Lancelot SIX <lsix@lancelotsix.com>
>
> PR cli/16269
> * inferior.c (inferior_id_completer): add completer
> (add_inferior_completer): add completer
> (clone_inferior_completer): add completer
> (initialize_inferiors): declare use of completers
>
> gdb/testsuite/ChangeLog:
>
> 2020-12-22 Lancelot SIX <lsix@lancelotsix.com>
>
> PR cli/16269
> * gdb.base/completion.exp: test completion of inferior related
> commands
> ---
> gdb/inferior.c | 61 ++++++++++++++++++++++++---
> gdb/testsuite/gdb.base/completion.exp | 18 ++++++++
> 2 files changed, 73 insertions(+), 6 deletions(-)
>
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index a6652b6920..406e5030d7 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -539,6 +539,22 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
> }
> }
>
> +/* Complete available inferior IDs */
> +
> +static void
> +inferior_id_completer (struct cmd_list_element *ignore,
> + completion_tracker &tracker,
> + const char *text, const char *word)
> +{
> + for (inferior *inf : all_inferiors ())
> + {
> + std::string const st = std::to_string (inf->num);
> + if (st.rfind(text, 0) == 0)
> + tracker.add_completion
> + (make_completion_match_str (st.c_str (), text, word));
> + }
> +}
> +
> static void
> detach_inferior_command (const char *args, int from_tty)
> {
> @@ -833,6 +849,20 @@ add_inferior_command (const char *args, int from_tty)
> }
> }
>
> +/* Completer for the add-inferior command */
> +
> +static void
> +add_inferior_completer (struct cmd_list_element *cmd,
> + completion_tracker &tracker,
> + const char *text, const char *word)
> +{
> + static const char * const options[] = {
> + "-copies", "-exec", "-no-connection", nullptr
> + };
> + complete_on_enum (tracker, options, text, word);
> + filename_completer (cmd, tracker, text, word);
> +}
> +
> /* clone-inferior [-copies N] [ID] [-no-connection] */
>
> static void
> @@ -919,6 +949,20 @@ clone_inferior_command (const char *args, int from_tty)
> }
> }
>
> +/* Completer for the clone-inferior command */
> +
> +static void
> +clone_inferior_completer (struct cmd_list_element *cmd,
> + completion_tracker &tracker,
> + const char *text, const char *word)
> +{
> + static const char * const options[] = {
> + "-copies", "-no-connection", nullptr
> + };
> + complete_on_enum (tracker, options, text, word);
> + inferior_id_completer (cmd, tracker, text, word);
> +}
> +
> /* Print notices when new inferiors are created and die. */
> static void
> show_print_inferior_events (struct ui_file *file, int from_tty,
> @@ -981,13 +1025,14 @@ as main program.\n\
> By default, the new inferior inherits the current inferior's connection.\n\
> If -no-connection is specified, the new inferior begins with\n\
> no target connection yet."));
> - set_cmd_completer (c, filename_completer);
> + set_cmd_completer (c, add_inferior_completer);
>
> - add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
> + c = add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
> Remove inferior ID (or list of IDs).\n\
> Usage: remove-inferiors ID..."));
> + set_cmd_completer(c, inferior_id_completer);
>
> - add_com ("clone-inferior", no_class, clone_inferior_command, _("\
> + c = add_com ("clone-inferior", no_class, clone_inferior_command, _("\
> Clone inferior ID.\n\
> Usage: clone-inferior [-copies N] [-no-connection] [ID]\n\
> Add N copies of inferior ID. The new inferiors have the same\n\
> @@ -997,22 +1042,26 @@ that is cloned.\n\
> By default, the new inferiors inherit the copied inferior's connection.\n\
> If -no-connection is specified, the new inferiors begin with\n\
> no target connection yet."));
> + set_cmd_completer (c, clone_inferior_completer);
>
> - add_cmd ("inferiors", class_run, detach_inferior_command, _("\
> + c = add_cmd ("inferiors", class_run, detach_inferior_command, _("\
> Detach from inferior ID (or list of IDS).\n\
> Usage; detach inferiors ID..."),
> &detachlist);
> + set_cmd_completer(c, inferior_id_completer);
>
> - add_cmd ("inferiors", class_run, kill_inferior_command, _("\
> + c = add_cmd ("inferiors", class_run, kill_inferior_command, _("\
> Kill inferior ID (or list of IDs).\n\
> Usage: kill inferiors ID..."),
> &killlist);
> + set_cmd_completer(c, inferior_id_completer);
>
> - add_cmd ("inferior", class_run, inferior_command, _("\
> + c = add_cmd ("inferior", class_run, inferior_command, _("\
> Use this command to switch between inferiors.\n\
> Usage: inferior ID\n\
> The new inferior ID must be currently known."),
> &cmdlist);
> + set_cmd_completer(c, inferior_id_completer);
>
> add_setshow_boolean_cmd ("inferior-events", no_class,
> &print_inferior_events, _("\
> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 8000d52049..cc3b7b7182 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -975,3 +975,21 @@ test_gdb_complete_unique "xxx_yyy_" "xxx_yyy_zzz"
> gdb_test_no_output "alias set aaa_bbb_ccc=set debug"
> gdb_test_no_output "maint deprecate set aaa_bbb_ccc"
> test_gdb_complete_unique "set aaa_bbb_" "set aaa_bbb_ccc"
> +
> +# Test completion of inferior related commands
> +
> +gdb_test "complete add-inferior -cop" "-copies"
> +gdb_test "complete add-inferior -no-con" "-no-connection"
> +gdb_test "complete add-inferior -e" "-exec"
> +
> +gdb_test "complete clone-inferior -c" "-copies"
> +gdb_test "complete clone-inferior -n" "-no-connection"
> +
> +# The following test will ensure that the completer yields the list of
> +# available inferiors. We expect to only have 1 present, with ID '1'
> +gdb_test "complete clone-inferior " ".*clone-inferior 1.*"
> +
> +gdb_test "complete remove-inferiors " "remove-inferiors 1"
> +gdb_test "complete kill inferiors " "kill inferiors 1"
> +gdb_test "complete detach inferiors " "detach inferiors 1"
> +gdb_test "complete inferior " "inferior 1"
> --
> 2.29.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-17 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22 21:54 [PATCH] [PR cli/16269] Add completer for the inferior commands Lancelot SIX via Gdb-patches
2021-01-17 18:50 ` Lancelot SIX via Gdb-patches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox