public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: gdb-patches@sourceware.org
Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Subject: [RFA 1/2] Add completion for COMMAND in 'thread apply all|ID... COMMAND'
Date: Sun, 21 Apr 2019 13:44:00 -0000	[thread overview]
Message-ID: <20190421134440.21100-2-philippe.waroquiers@skynet.be> (raw)
In-Reply-To: <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

  parent reply	other threads:[~2019-04-21 13:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-21 13:44 [RFA 0/2] Add completion for COMMAND for frame|thread apply Philippe Waroquiers
2019-04-21 13:44 ` [RFA 2/2] Add completion for COMMAND in 'frame apply all|level|COUNT... COMMAND' Philippe Waroquiers
2019-04-25 13:33   ` Tom Tromey
2019-04-21 13:44 ` Philippe Waroquiers [this message]
2019-04-25 13:30   ` [RFA 1/2] Add completion for COMMAND in 'thread apply all|ID... COMMAND' Tom Tromey
2019-04-25 22:44     ` Philippe Waroquiers
2019-04-30 15:13       ` Tom Tromey
2019-05-01  4:53         ` Philippe Waroquiers
2019-05-01 10:18           ` Pedro Alves
2019-05-01 19:54             ` Philippe Waroquiers
2019-05-24 18:31               ` "with" command (alternative to the "/" command) Pedro Alves
2019-05-25 21:07                 ` Philippe Waroquiers
2019-05-10  0:54             ` [RFA 1/2] Add completion for COMMAND in 'thread apply all|ID... COMMAND' Pedro Alves
2019-05-11 15:01               ` Philippe Waroquiers
2019-05-13 10:19                 ` Pedro Alves

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=20190421134440.21100-2-philippe.waroquiers@skynet.be \
    --to=philippe.waroquiers@skynet.be \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).