diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-06-24 15:53:34 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-09-07 20:28:58 +0100 |
commit | 67b8e30af907d8c19f50343268d7c6db85347ee2 (patch) | |
tree | 5aa12e4efaa74cec6156ff4b6f9ebfe8b2483521 | |
parent | 8f87fcb1daf1af1dd2d332f7303b02e391fa6b6c (diff) | |
download | gdb-67b8e30af907d8c19f50343268d7c6db85347ee2.zip gdb-67b8e30af907d8c19f50343268d7c6db85347ee2.tar.gz gdb-67b8e30af907d8c19f50343268d7c6db85347ee2.tar.bz2 |
gdb: implement readline rl_directory_rewrite_hook callback
Implement the readline rl_directory_rewrite_hook callback function,
this is used when readline needs to offer completions from within a
directory. The important thing is that this function should remove
any escaping, this allows GDB to correctly offer completions in
situations like this:
(gdb) file /tmp/directory\ with\ spaces/<TAB><TAB>
Note the escaping in 'directory\ with\ spaces'. Without the
rl_directory_rewrite_hook callback readline will try to open a
directory literally called '/tmp/directory\ with\ spaces' which
obviously doesn't exist.
There are tests added to cover this new functionality.
-rw-r--r-- | gdb/completer.c | 21 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/filename-completion.exp | 12 |
2 files changed, 33 insertions, 0 deletions
diff --git a/gdb/completer.c b/gdb/completer.c index b0e999e..b80649c 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -321,6 +321,26 @@ gdb_completer_file_name_dequote (char *filename, int quote_char) return strdup (tmp.c_str ()); } +/* Implement readline's rl_directory_rewrite_hook. Remove any quoting from + the string *DIRNAME,update *DIRNAME, and return non-zero. If *DIRNAME + doesn't need updating then return zero. See readline docs for more + information. */ + +static int +gdb_completer_directory_rewrite (char **dirname) +{ + if (!rl_completion_found_quote) + return 0; + + int quote_char = rl_completion_quote_character; + char *new_dirname + = gdb_completer_file_name_dequote (*dirname, quote_char); + free (*dirname); + *dirname = new_dirname; + + return 1; +} + /* Apply character escaping to the filename in TEXT and return a newly allocated buffer containing the possibly updated filename. @@ -3416,6 +3436,7 @@ _initialize_completer () rl_filename_quote_characters = " \t\n\\\"'"; rl_filename_dequoting_function = gdb_completer_file_name_dequote; rl_filename_quoting_function = gdb_completer_file_name_quote; + rl_directory_rewrite_hook = gdb_completer_directory_rewrite; add_setshow_zuinteger_unlimited_cmd ("max-completions", no_class, &max_completions, _("\ diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index a4b411c..cf00d00 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -170,6 +170,11 @@ proc run_quoting_and_escaping_tests { root } { set dq "\\\"" } + test_gdb_complete_unique "${cmd} ${qc}${root}/bb2/dir${sp}1/" \ + "${cmd} ${qc}${root}/bb2/dir${sp}1/unique${sp}file${qc}" " " \ + false \ + "expand a unique file name in a directory containing a space" + test_gdb_complete_filename_multiple "$cmd ${qc}${root}/bb2/" \ "d" "ir${sp}" { "dir 1/" @@ -177,6 +182,13 @@ proc run_quoting_and_escaping_tests { root } { } "" "${qc}" false \ "expand multiple directory names containing spaces" + test_gdb_complete_filename_multiple "${cmd} ${qc}${root}/bb2/dir${sp}2/" \ + "f" "ile${sp}" { + "file 1" + "file 2" + } "" "${qc}" false \ + "expand contents of a directory containing a space" + test_gdb_complete_filename_multiple "$cmd ${qc}${root}/aaa/" \ "a" "a${sp}" { "aa bb" |