aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-06-02 20:33:36 +0100
committerAndrew Burgess <aburgess@redhat.com>2025-06-23 15:16:19 +0100
commita66ed82cf04ed4527882af57e2bffec065ed47e0 (patch)
treed2344d3f5a8217f40216582abc75cd0a34f0139c
parentb23903836007d1acaf7f8c059ab000ee83fcebfa (diff)
downloadbinutils-a66ed82cf04ed4527882af57e2bffec065ed47e0.zip
binutils-a66ed82cf04ed4527882af57e2bffec065ed47e0.tar.gz
binutils-a66ed82cf04ed4527882af57e2bffec065ed47e0.tar.bz2
gdb: filename completion for pipe command -- the shell command bit
This commit adds filename completion for the shell command part of the pipe command. This is a follow on from this commit: commit 036e5c0c9121d0ac691dbf408a3bdf2bf3501d0f Date: Mon May 19 20:54:54 2025 +0100 gdb: use quoted filename completion for the shell command which fixed the completion for the 'shell' command itself. Like with the 'shell' command, we don't offer completions of command names pulled from $PATH, we just offer filename completion, which is often useful for arguments being passed to commands. Maybe in the future we could add completion for command names too (for both 'pipe' and the 'shell' command), but that is left for a future commit. There's some additional testing.
-rw-r--r--gdb/cli/cli-cmds.c28
-rw-r--r--gdb/testsuite/gdb.base/filename-completion.exp2
2 files changed, 27 insertions, 3 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index d812c49..054fff4 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1193,8 +1193,32 @@ pipe_command_completer (struct cmd_list_element *ignore,
return;
}
- /* We're past the delimiter. What follows is a shell command, which
- we don't know how to complete. */
+ /* We're past the delimiter now, or at least, DELIM points to the
+ delimiter string. Update TEXT to point to the start of whatever
+ appears after the delimiter. */
+ text = skip_spaces (delim + strlen (delimiter));
+
+ /* We really are past the delimiter now, so offer completions. This is
+ like GDB's "shell" command, currently we only offer filename
+ completion, but in the future this could be improved by offering
+ completion of command names from $PATH.
+
+ What we don't do here is offer completions for the empty string. It
+ is assumed that the first word after the delimiter is going to be a
+ command name from $PATH, not a filename, so if the user has typed
+ nothing (yet) and tries to complete, there's no point offering a list
+ of files from the current directory.
+
+ Once the user has started to type something though, then we do start
+ offering filename completions. */
+ if (*text == '\0')
+ return;
+
+ tracker.set_use_custom_word_point (true);
+ tracker.advance_custom_word_point_by (text - org_text);
+ const char *word
+ = advance_to_filename_maybe_quoted_complete_word_point (tracker, text);
+ filename_maybe_quoted_completer (ignore, tracker, text, word);
}
/* Helper for the list_command function. Prints the lines around (and
diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp
index 742a182..c10941c 100644
--- a/gdb/testsuite/gdb.base/filename-completion.exp
+++ b/gdb/testsuite/gdb.base/filename-completion.exp
@@ -414,7 +414,7 @@ proc run_quoting_and_escaping_tests { root } {
# focuses on completion of the final filename. There is also some
# testing of the shell command above, this tests completion within
# the line.
- foreach_with_prefix shell_cmd { "shell " "!" } {
+ foreach_with_prefix shell_cmd { "shell " "!" "pipe print 1 | " } {
foreach suffix { "aaa/aa bb" "bb2/dir 1/unique file" } {
set dir $root/$suffix