Re: [PATCH 4/6] gdb: add match formatter mechanism for 'complete' command output

Andrew Burgess
2024-04-12T17:42:39Z

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Sat, 30 Mar 2024 23:49:18 +0000
>> From: Lancelot SIX <lsix@lancelotsix.com>
>> Cc: gdb-patches@sourceware.org
>>
>> > (gdb) complete file '/tmp/xx
>> > file '/tmp/xxx/'
>> >
>> > The completion offered here is really only a partial completion, we've
>> > completed up to the end of the next directory name, but, until we have
>> > a filename then the completion is not finished and the trailing quote
>> > should not be added.
>> >
>> > This would match the readline behaviour, e.g.:
>> >
>> > (gdb) file '/tmp/xx<TAB>
>> > (gdb) file '/tmp/xxx/
>> >
>> > In this case readline completes the directory name, but doesn't add
>> > the trailing quote character.
>
> Btw, what readline does is not the only useful behavior. An
> alternative would be this:
>
> (gdb) file '/tmp/xx<TAB>
> => (gdb) file '/tmp/xx/'
> (gdb) file '/tmp/xx/'a<TAB>
> => (gdb) file '/tmp/xx/abcd'
>
> That is, allow to type after the closing quote, and remove the closing
> quote before trying to complete. This way, the user can use
> '/tmp/xx/' if that is what she needs, or continue typing and
> completing if not.

That does sound better. I think there are still things that would need
figuring out. For example, what if the user didn't do the second tab
completion, but just kept typing.

(gdb) file '/tmp/xx<TAB>
=> (gdb) file '/tmp/xx/'
(gdb) file '/tmp/xx/'abcd<ENTER>
=> ?? What would this do?

What if there really was a file /tmp/xx/'abcd ? What happens then? But
I do think this sounds like an interesting idea. But...

... I don't think I want to start making such sweeping changes to
readline, or how GDB uses readline. Or maybe that would require moving
off readline completely?

My goal with this work is to support '-filename PATH' command options
using GDB's option framework. Adding such options really calls for good
filename completion. [ NOTE: I'm not adding those options in this
series, that would be the next project. ]

Ideally I want to work with GDB as it is right now, i.e. how does GDB
work right now, and how does GDB parse filenames right now, and have
filename completion work with those constraints.

Thanks,
Andrew