From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 19/24] Introduce complete_command
Date: Wed, 22 May 2019 20:53:00 -0000 [thread overview]
Message-ID: <20190522205327.2568-20-palves@redhat.com> (raw)
In-Reply-To: <20190522205327.2568-1-palves@redhat.com>
This adds a completion helper routine that makes it possible for a
command that takes another command as argument, such as "frame apply
all COMMAND" as "thread apply all COMMAND", to complete on COMMAND,
and have the completion machinery recurse and complete COMMAND as if
you tried to complete "(gdb) COMMAND". I.e., we'll be able to
complete like this, for example:
(gdb) thread apply all -[TAB]
-c -ascending -q -s
(gdb) thread apply all -ascending frame apply all -[TAB]
-c -limit -past-entry -past-main -q -s
(gdb) thread apply all -ascending frame apply all -past-main print -[TAB]
-address -elements -pretty -symbol
-array -null-stop -repeats -union
-array-indexes -object -static-members -vtbl
(gdb) thread apply all -ascending frame apply all -past-main print glo[TAB]
global1 global2
Above, the completer function understands that "thread apply all" is a
command, and then parses "-ascending" successfully and understand that
the rest of the string is "thread apply all"'s operand. And then, the
process repeats for the "frame apply" command, and on and on.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* completer.c (complete_command): New.
(gdb_completion_word_break_characters_throw): Add assertion.
* completer.h (complete_command): Declare.
---
gdb/completer.c | 36 ++++++++++++++++++++++++++++++++++++
gdb/completer.h | 11 +++++++++++
2 files changed, 47 insertions(+)
diff --git a/gdb/completer.c b/gdb/completer.c
index 25714c33c28..27ea20e928e 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -423,6 +423,39 @@ completion_tracker::completes_to_completion_word (const char *word)
return false;
}
+/* See completer.h. */
+
+void
+complete_command (completion_tracker &tracker, const char *text)
+{
+ /* Must be called from a custom-word-point completer. */
+ gdb_assert (tracker.use_custom_word_point ());
+
+ /* Disable the custom word point temporarily, because we want to
+ probe whether the command we're completing itself uses a custom
+ word point. */
+ tracker.set_use_custom_word_point (false);
+ size_t save_custom_word_point = tracker.custom_word_point ();
+
+ int quote_char = '\0';
+ const char *word = completion_find_completion_word (tracker, text,
+ "e_char);
+
+ if (tracker.use_custom_word_point ())
+ {
+ /* The command we're completing uses a custom word point, so the
+ tracker already contains the matches. We're done. */
+ return;
+ }
+
+ /* Restore the custom word point settings. */
+ tracker.set_custom_word_point (save_custom_word_point);
+ tracker.set_use_custom_word_point (true);
+
+ /* Run the handle_completions completer phase. */
+ complete_line (tracker, word, text, strlen (text));
+}
+
/* Complete on linespecs, which might be of two possible forms:
file:line
@@ -1898,6 +1931,9 @@ gdb_completion_word_break_characters_throw ()
{
gdb_assert (tracker.custom_word_point () > 0);
rl_point = tracker.custom_word_point () - 1;
+
+ gdb_assert (rl_point >= 0 && rl_point < strlen (rl_line_buffer));
+
gdb_custom_word_point_brkchars[0] = rl_line_buffer[rl_point];
rl_completer_word_break_characters = gdb_custom_word_point_brkchars;
rl_completer_quote_characters = NULL;
diff --git a/gdb/completer.h b/gdb/completer.h
index 58fe84f4fee..1b7176f031a 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -611,6 +611,17 @@ extern completion_list complete_source_filenames (const char *text);
extern void complete_expression (completion_tracker &tracker,
const char *text, const char *word);
+/* Called by custom word point completers that want to recurse into
+ the completion machinery to complete a command. Used to complete
+ COMMAND in "thread apply all COMMAND", for example. Note that
+ unlike command_completer, this fully recurses into the proper
+ completer for COMMAND, so that e.g.,
+
+ (gdb) thread apply all print -[TAB]
+
+ does the right thing and show the print options. */
+extern void complete_command (completion_tracker &tracker, const char *text);
+
extern const char *skip_quoted_chars (const char *, const char *,
const char *);
--
2.14.5
next prev parent reply other threads:[~2019-05-22 20:53 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-22 20:53 [PATCH 00/24] gdb::option framework, "print -OPT", other cmd options Pedro Alves
2019-05-22 20:53 ` [PATCH 11/24] number_or_range_parser::get_number, don't treat "1 -" as a range Pedro Alves
2019-05-22 20:53 ` [PATCH 04/24] Make check_for_argument skip whitespace after arg itself Pedro Alves
2019-05-22 20:53 ` [PATCH 18/24] lib/completion-support.exp: Add test_gdb_completion_offers_commands Pedro Alves
2019-05-22 20:53 ` [PATCH 08/24] gdb.base/settings.exp: Fix comment typo Pedro Alves
2019-05-24 11:40 ` Pedro Alves
2019-05-22 20:53 ` [PATCH 07/24] Remove "show" command completers Pedro Alves
2019-05-23 19:28 ` Sergio Durigan Junior
2019-05-24 11:25 ` Pedro Alves
2019-05-24 14:21 ` Sergio Durigan Junior
2019-05-22 20:53 ` [PATCH 03/24] Fix TID parser bug Pedro Alves
2019-05-22 20:53 ` [PATCH 15/24] Introduce rename_cmd Pedro Alves
2019-05-25 19:58 ` Philippe Waroquiers
2019-05-29 16:03 ` Pedro Alves
2019-05-29 18:30 ` Pedro Alves
2019-05-30 10:22 ` Philippe Waroquiers
2019-05-30 20:01 ` Pedro Alves
2019-05-22 20:53 ` Pedro Alves [this message]
2019-05-22 20:54 ` [PATCH 02/24] Fix latent bug with custom word point completers Pedro Alves
2019-05-22 20:54 ` [PATCH 01/24] Fix latent bug in custom word point completion handling Pedro Alves
2019-05-22 20:54 ` [PATCH 14/24] Migrate rest of compile commands to new options framework Pedro Alves
2019-05-22 20:54 ` [PATCH 20/24] Make "frame apply" support -OPT options Pedro Alves
2019-05-25 20:12 ` Philippe Waroquiers
2019-05-29 15:13 ` Pedro Alves
2019-05-29 15:25 ` Pedro Alves
2019-05-22 20:54 ` [PATCH 10/24] boolean/auto-boolean commands, make "o" ambiguous Pedro Alves
2019-05-22 20:54 ` [PATCH 22/24] Make "thread apply" use the gdb::option framework Pedro Alves
2019-05-25 20:24 ` Philippe Waroquiers
2019-05-29 15:38 ` Pedro Alves
2019-05-22 20:54 ` [PATCH 06/24] Fix "set enum-command value garbage" Pedro Alves
2019-05-23 19:13 ` Sergio Durigan Junior
2019-05-24 11:39 ` Pedro Alves
2019-05-22 20:54 ` [PATCH 05/24] Allow "unlimited" abbreviations Pedro Alves
2019-05-22 20:54 ` [PATCH 09/24] New set/show testing framework (gdb.base/settings.exp) Pedro Alves
2019-05-23 4:15 ` Eli Zaretskii
2019-05-22 20:54 ` [PATCH 21/24] "thread apply 1 -- -" vs "frame apply level 0 -- -" Pedro Alves
2019-05-22 20:54 ` [PATCH 12/24] Introduce generic command options framework Pedro Alves
2019-05-25 7:43 ` Philippe Waroquiers
2019-05-25 10:31 ` Pedro Alves
2019-05-22 20:58 ` [PATCH 13/24] Make "print" and "compile print" support -OPT options Pedro Alves
2019-05-24 19:49 ` Sergio Durigan Junior
2019-05-25 10:10 ` Pedro Alves
2019-05-25 10:37 ` Andreas Schwab
2019-05-22 20:58 ` [PATCH 16/24] Make "backtrace" " Pedro Alves
2019-05-22 21:00 ` [PATCH 17/24] "backtrace full/no-filters/hide" completer Pedro Alves
2019-05-22 21:00 ` [PATCH 24/24] NEWS and manual changes for command options changes Pedro Alves
2019-05-23 4:31 ` Eli Zaretskii
2019-05-23 15:01 ` Pedro Alves
2019-05-23 15:07 ` Eli Zaretskii
2019-05-23 15:31 ` Pedro Alves
2019-05-25 20:40 ` Philippe Waroquiers
2019-05-29 16:03 ` Pedro Alves
2019-05-22 21:03 ` [PATCH 23/24] Delete parse_flags/parse_flags_qcs Pedro Alves
2019-05-22 21:46 ` [PATCH 00/24] gdb::option framework, "print -OPT", other cmd options Pedro Alves
2019-05-24 19:58 ` Sergio Durigan Junior
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=20190522205327.2568-20-palves@redhat.com \
--to=palves@redhat.com \
--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