diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-01-02 17:08:30 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-01-12 11:03:33 +0000 |
commit | 3b9ff5d9009d587aa76ec7bbaab4439e26a52c50 (patch) | |
tree | 5316996e930bbcf61835924a7202e8c1e9992aa8 /gdb/completer.h | |
parent | 76118e1675f5eaf3fc44524ec435981705572629 (diff) | |
download | binutils-3b9ff5d9009d587aa76ec7bbaab4439e26a52c50.zip binutils-3b9ff5d9009d587aa76ec7bbaab4439e26a52c50.tar.gz binutils-3b9ff5d9009d587aa76ec7bbaab4439e26a52c50.tar.bz2 |
gdb: add trailing '/' when using 'complete' with directory names
This patch contains work pulled from this previously proposed patch:
https://inbox.sourceware.org/gdb-patches/20210213220752.32581-2-lsix@lancelotsix.com/
But has been modified by me. Credit for the original idea and
implementation goes to Lancelot, any bugs in this new iteration belong
to me.
Consider the executable `/tmp/foo/my_exec', and if we assume `/tmp' is
empty other than the `foo' sub-directory, then currently within GDB,
if I type:
(gdb) file /tmp/f
and then hit TAB, GDB completes this to:
(gdb) file /tmp/foo/
notice that not only did GDB fill in the whole of `foo', but GDB also
added a trailing '/' character. This is done within readline when the
path that was just completed is a directory. However, if I instead
do:
(gdb) complete file /tmp/f
file /tmp/foo
I now see the completed directory name, but the trailing '/' is
missing. The reason is that, in this case, the completions are not
offered via readline, but are handled entirely within GDB, and so
readline never gets the chance to add the trailing '/' character.
The above patch added filename option support to GDB, which included
completion of the filename options. This initially suffered from the
same problem that I've outlined above, but the above patch proposed a
solution to this problem, but this solution only applied to filename
options (which have still not been added to GDB), and was mixed in
with the complete filename options support.
This patch pulls out just the fix for the trailing "/" problem, and
applies it to GDB's general filename completion. This patch does not
add filename options to GDB, that can always be done later, but I
think this small part is itself a useful fix.
One of the biggest changes I made in this version is that I got rid of
the set_from_readline member function, instead, I now pass the value
of m_from_readline into the completion_tracker constructor.
I then moved the addition of the trailing '/' into filename_completer
so that it is applied in the general filename completion case. I also
added a call to gdb_tilde_expand which was missing from the original
patch, I haven't tested, but I suspect that this meant that the
original patch would not add the trailing '/' if the user entered a
path starting with a tilde character.
When writing the test for this patch I ran into two problems.
The first was that the procedures in lib/completion-support.exp relied
on the command being completed for the test name. This is fine for
many commands, but not when completing a filename, if we use the
command in this case the test name will (potentially) include the name
of the directory in which the test is being run, which means we can't
compare results between two runs of GDB from different directories.
So in this commit I've gone through completion-support.exp and added a
new (optional) testname argument to many of the procedures, this
allows me to give a unique test name, that doesn't include the path
for my new tests.
The second issue was in the procedure make_tab_completion_list_re,
this builds the completion list which is displayed after a double tab
when there are multiple possible completions.
The procedure added the regexp ' +' after each completion, and then
added another ' +' at the very end of the expected output. So, if we
expected to match the name of two functions 'f1' and 'f2' the
generated regexp would be: 'f1 +f2 + +'. This would match just fine,
the actual output would be: 'f1 f2 ', notice that we get two spaces
after each function name.
However, if we complete two directory names 'd1' and 'd2' then the
output will be 'd1/ d2/ '. Notice that now we only have a single
space between each match, however, we do get the '/' added instead.
What happens is that when presenting the matches, readline always adds
the appropriate trailing character; if we performed tab completion of
'break f1' then, as 'f1' is a unique match, we'd get 'break f1 ' with
a trailing space added. However, if we complete 'file d1' then we get
'file d1/'. Then readline is adding a single space after each
possible match, including the last one, which accounts for the
trailing space character.
To resolve this I've simply remove the addition o the second ' +'
within make_tab_completion_list_re, for the function completion
example I gave above the expected pattern is now 'f1 +f2 +', which for
the directory case we expect 'd1/ +d2/ +', both of which work just
fine.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16265
Co-Authored-By: Lancelot SIX <lsix@lancelotsix.com>
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'gdb/completer.h')
-rw-r--r-- | gdb/completer.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gdb/completer.h b/gdb/completer.h index d96c4b5..4faef4e 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -328,7 +328,7 @@ public: class completion_tracker { public: - completion_tracker (); + explicit completion_tracker (bool from_readline); ~completion_tracker (); DISABLE_COPY_AND_ASSIGN (completion_tracker); @@ -423,6 +423,11 @@ public: completion_result build_completion_result (const char *text, int start, int end); + /* Tells if the completion task is triggered by readline. See + m_from_readline. */ + bool from_readline () const + { return m_from_readline; } + private: /* The type that we place into the m_entries_hash hash table. */ @@ -512,6 +517,11 @@ private: track the maximum possible size of the lowest common denominator, which we know as each completion is added. */ size_t m_lowest_common_denominator_max_length = 0; + + /* Indicates that the completions are to be displayed by readline + interactively. The 'complete' command is a way to generate completions + not to be displayed by readline. */ + bool m_from_readline; }; /* Return a string to hand off to readline as a completion match |