This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 1/2] Add completion for COMMAND in 'thread apply all|ID... COMMAND'
- From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- To: gdb-patches at sourceware dot org
- Cc: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
- Date: Sun, 21 Apr 2019 15:44:39 +0200
- Subject: [RFA 1/2] Add completion for COMMAND in 'thread apply all|ID... COMMAND'
- References: <20190421134440.21100-1-philippe.waroquiers@skynet.be>
This patch adds logic to complete the COMMAND part of the
'thread apply all|ID...' command.
gdb/ChangeLog
2019-04-21 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* thread.c (thread_apply_all_command_completer,
thread_apply_id_command_completer): New functions.
(thread_apply_all_command, thread_apply_command): Add comment
referring to the corresponding completer function.
(_initialize_thread): Setup completers for thread apply all,
thread apply ID, taas, tfaas.
gdb/testsuite/ChangeLog
2019-04-21 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.threads/pthreads.exp: Test COMMAND completion.
---
gdb/testsuite/gdb.threads/pthreads.exp | 25 ++++++++
gdb/thread.c | 84 +++++++++++++++++++++++---
2 files changed, 102 insertions(+), 7 deletions(-)
diff --git a/gdb/testsuite/gdb.threads/pthreads.exp b/gdb/testsuite/gdb.threads/pthreads.exp
index 0bb9083f67..2cde3e64d5 100644
--- a/gdb/testsuite/gdb.threads/pthreads.exp
+++ b/gdb/testsuite/gdb.threads/pthreads.exp
@@ -15,6 +15,8 @@
# This file was written by Fred Fish. (fnf@cygnus.com)
+load_lib completion-support.exp
+
# This test requires sending ^C to interrupt the running target.
if [target_info exists gdb,nointerrupts] {
verbose "Skipping pthreads.exp because of nointerrupts."
@@ -341,6 +343,29 @@ proc check_qcs {} {
}
+proc check_completion {} {
+ test_gdb_complete_cmd_unique "thread apply al" "thread apply all"
+ test_gdb_complete_cmd_unique "thread apply all info al" \
+ "thread apply all info all-registers"
+ test_gdb_complete_cmd_unique "thread apply all -ascending info al" \
+ "thread apply all -ascending info all-registers"
+ test_gdb_complete_cmd_unique "thread apply all -ascending -q info al" \
+ "thread apply all -ascending -q info all-registers"
+
+ test_gdb_complete_cmd_unique "thread apply" "thread apply"
+ test_gdb_complete_none "thread apply 1"
+ test_gdb_complete_none "thread apply 1 2"
+ test_gdb_complete_cmd_unique "thread apply 1 2 info al" \
+ "thread apply 1 2 info all-registers"
+ test_gdb_complete_cmd_unique "thread apply 1 2 -q -c info al" \
+ "thread apply 1 2 -q -c info all-registers"
+
+ test_gdb_complete_cmd_unique "taas info al" "taas info all-registers"
+ test_gdb_complete_cmd_unique "tfaas info al" "tfaas info all-registers"
+}
+
+check_completion
+
if [runto_main] then {
if [test_startup] then {
if [check_control_c] then {
diff --git a/gdb/thread.c b/gdb/thread.c
index dbcf8be0e1..c8ca49d54c 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1502,6 +1502,8 @@ thread_apply_all_command (const char *cmd, int from_tty)
tp_array_compar_ascending = false;
+ /* Changing this parsing logic probably implies to similarly update
+ thread_apply_all_completer below. */
while (cmd != NULL)
{
if (check_for_argument (&cmd, "-ascending", strlen ("-ascending")))
@@ -1551,6 +1553,33 @@ thread_apply_all_command (const char *cmd, int from_tty)
}
}
+/* Skips the known arguments of thread apply all
+ and then invokes the usual command_completer. */
+
+static void
+thread_apply_all_command_completer (struct cmd_list_element *cmd,
+ completion_tracker &tracker,
+ const char *text, const char *word)
+{
+ while (text != NULL)
+ {
+ qcs_flags dummy;
+
+ if (check_for_argument (&text, "-ascending", strlen ("-ascending")))
+ {
+ text = skip_spaces (text);
+ continue;
+ }
+
+ if (parse_flags_qcs ("thread apply all COMMAND completer", &text, &dummy))
+ continue;
+
+ break;
+ }
+
+ command_completer (cmd, tracker, text, word);
+}
+
/* Implementation of the "thread apply" command. */
static void
@@ -1588,6 +1617,8 @@ thread_apply_command (const char *tidlist, int from_tty)
scoped_restore_current_thread restore_thread;
+ /* Changing this parsing logic probably implies to similarly update
+ thread_apply_id_completer below. */
parser.init (tidlist, current_inferior ()->num);
while (!parser.finished () && parser.cur_tok () < cmd_or_flags)
{
@@ -1638,6 +1669,40 @@ thread_apply_command (const char *tidlist, int from_tty)
}
}
+/* Skips the known arguments of thread apply ID...
+ and then invokes the usual command_completer. */
+
+static void
+thread_apply_id_command_completer (struct cmd_list_element *cmd,
+ completion_tracker &tracker,
+ const char *text, const char *word)
+{
+ tid_range_parser parser;
+ qcs_flags dummy;
+
+ if (text == NULL)
+ return; /* No ID yet. */
+
+ parser.init (text, current_inferior ()->num);
+ while (!parser.finished ())
+ {
+ int inf_num, thr_start, thr_end;
+
+ if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
+ {
+ text = parser.cur_tok ();
+ break;
+ }
+ }
+
+ while (text != NULL
+ && parse_flags_qcs ("thread apply ID... COMMAND completer",
+ &text, &dummy))
+ ;
+
+ command_completer (cmd, tracker, text, word);
+}
+
/* Implementation of the "taas" command. */
@@ -1939,6 +2004,7 @@ void
_initialize_thread (void)
{
static struct cmd_list_element *thread_apply_list = NULL;
+ struct cmd_list_element *c;
add_info ("threads", info_threads_command,
_("Display currently known threads.\n\
@@ -1962,32 +2028,36 @@ Flag -c indicates to print the error and continue.\n\
Flag -s indicates to silently ignore a COMMAND that raises an error\n\
or produces no output."
- add_prefix_cmd ("apply", class_run, thread_apply_command,
+ c = add_prefix_cmd ("apply", class_run, thread_apply_command,
_("Apply a command to a list of threads.\n\
Usage: thread apply ID... [FLAG]... COMMAND\n\
ID is a space-separated list of IDs of threads to apply COMMAND on.\n"
THREAD_APPLY_FLAGS_HELP),
- &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
+ &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
+ set_cmd_completer (c, thread_apply_id_command_completer);
- add_cmd ("all", class_run, thread_apply_all_command,
- _("\
+ c = add_cmd ("all", class_run, thread_apply_all_command,
+ _("\
Apply a command to all threads.\n\
\n\
Usage: thread apply all [-ascending] [FLAG]... COMMAND\n\
-ascending: Call COMMAND for all threads in ascending order.\n\
The default is descending order.\n"
THREAD_APPLY_FLAGS_HELP),
- &thread_apply_list);
+ &thread_apply_list);
+ set_cmd_completer (c, thread_apply_all_command_completer);
- add_com ("taas", class_run, taas_command, _("\
+ c = add_com ("taas", class_run, taas_command, _("\
Apply a command to all threads (ignoring errors and empty output).\n\
Usage: taas COMMAND\n\
shortcut for 'thread apply all -s COMMAND'"));
+ set_cmd_completer (c, command_completer);
- add_com ("tfaas", class_run, tfaas_command, _("\
+ c = add_com ("tfaas", class_run, tfaas_command, _("\
Apply a command to all frames of all threads (ignoring errors and empty output).\n\
Usage: tfaas COMMAND\n\
shortcut for 'thread apply all -s frame apply all -s COMMAND'"));
+ set_cmd_completer (c, command_completer);
add_cmd ("name", class_run, thread_name_command,
_("Set the current thread's name.\n\
--
2.20.1