From: Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Lancelot SIX <lsix@lancelotsix.com>
Subject: [PATCH] [PR cli/16269] Add completer for the inferior commands
Date: Tue, 22 Dec 2020 21:54:39 +0000 [thread overview]
Message-ID: <20201222215439.4563-1-lsix@lancelotsix.com> (raw)
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
next reply other threads:[~2020-12-22 21:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-22 21:54 Lancelot SIX via Gdb-patches [this message]
2021-01-17 18:50 ` Lancelot SIX via Gdb-patches
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=20201222215439.4563-1-lsix@lancelotsix.com \
--to=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.com \
/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