diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-01-15 13:25:01 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-03-25 17:47:43 +0000 |
commit | 5792be924413fcd2195242d87252857b888086dd (patch) | |
tree | c679ce30c61775ebb9c7feb1d98104dca8c82111 /gdb/completer.c | |
parent | 17640f65fc6d42bfcaac9bcd0c72121c461c555b (diff) | |
download | fsf-binutils-gdb-5792be924413fcd2195242d87252857b888086dd.zip fsf-binutils-gdb-5792be924413fcd2195242d87252857b888086dd.tar.gz fsf-binutils-gdb-5792be924413fcd2195242d87252857b888086dd.tar.bz2 |
gdb: fix bug where quote characters would become nullptr
In gdb_completion_word_break_characters_throw, after calling
complete_line_internal, if the completion function chose to use a
custom word point then we set rl_completer_quote_characters to NULL.
However, nowhere do we set rl_completer_quote_characters back to its
default value, which is setup in init_main (top.c).
An example of something that uses a custom word point for its
completion is 'thread apply all ...'.
An example of something that relies on rl_completer_quote_characters
would be completion of a quoted filename that contains white space.
Consider this shell and GDB session. The <TAB> markers indicate where
I've used tab to trigger completion:
$ mkdir /tmp/aaa\ bbb
$ touch /tmp/aaa\ bbb/xx\ 11
$ touch /tmp/aaa\ bbb/xx\ 22
$ gdb -q
(gdb) file '/tmp/aaa bbb/xx<TAB><TAB>
xx 11 xx 22
(gdb) thread apply all hel<TAB>
(gdb) thread apply all help
(gdb) file '/tmp/aaa bbb/xx<TAB><TAB>
First I create a directory structure which uses white space within
file and directory names. Then within GDB I use the 'file' command
and use a single quote to quote the filename. When I tab complete GDB
correctly offers the two files within the directory '/tmp/aaa bbb/'.
This works because rl_completer_quote_characters contains the single
quote, and so readline knows that it is trying to complete the string
that starts after the single quote: /tmp/aaa bbb/xx
Next I invoke the completer for the 'thread apply all' command, to do
this I type 'thread apply all hel' and hit tab, this expands to the
one completion 'thread apply all help'. We can run this command or
not, it doesn't matter (there are no threads, so we'll get no output).
Now I repeat the original 'file' completion. This time though I don't
get offered any completions.
The reason is that the 'thread apply all' completer set
rl_completer_quote_characters to nullptr. Now, when readline tries to
figure out the word to complete it doesn't see the single quote as the
start of a quoted word, so instead readline falls back to the word
break characters, and in this case spots the white space. As a result
readline tries to complete the string 'bbb/xx' which obviously doesn't
have any completions.
By setting rl_completer_quote_characters each time completion is
invoked this problem is resolved and the second 'file' command
completes as expected.
I've extended gdb.base/filename-completion.exp to also test with
quoted filenames, and added a 'thread apply all' completion at the
start to expose this bug.
As setting of rl_completer_quote_characters is now all done in the
completer.c file the function get_gdb_completer_quote_characters()
could be made static. However, as this function is only used one time
to initialise rl_completer_quote_characters, I've instead just deleted
get_gdb_completer_quote_characters() and used
gdb_completer_quote_characters directly.
Diffstat (limited to 'gdb/completer.c')
-rw-r--r-- | gdb/completer.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/gdb/completer.c b/gdb/completer.c index 8168f79..44da654 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -181,13 +181,6 @@ static const char gdb_completer_file_name_break_characters[] = sequences as strings. */ static const char gdb_completer_quote_characters[] = "'"; -/* Accessor for some completer data that may interest other files. */ - -const char * -get_gdb_completer_quote_characters (void) -{ - return gdb_completer_quote_characters; -} /* This can be used for functions which don't want to complete on symbols but don't want to complete on anything else either. */ @@ -1269,6 +1262,9 @@ complete_line_internal_1 (completion_tracker &tracker, set_rl_completer_word_break_characters (current_language->word_break_characters ()); + /* Likewise for the quote characters. */ + rl_completer_quote_characters = gdb_completer_quote_characters; + /* Decide whether to complete on a list of gdb commands or on symbols. */ tmp_command = (char *) alloca (point + 1); |