[PATCH v2 2/5] gdb: Tab complete internalvars in expressions

nt8r@protonmail.com nt8r@protonmail.com
Sun Sep 1 21:35:22 GMT 2024


The `advance_custom_word_point` usage was a holdover from when I was confused about the contract for the completer code; it isn't necessary and I'll remove it in v3 along with doing all formatting fixes.

The completion code could have suggested completions include the $, but that isn't what's done by `complete_internalvar` or `complete_register` internally. Effectively we just treat the $ as context. Is it straightforward to also include the $ in the completions? If not, I'd say it probably isn't worth the trouble.

Antonio

On Friday, August 30th, 2024 at 7:32 PM, Keith Seitz <keiths@redhat.com> wrote:

> On 8/27/24 6:50 PM, Antonio Rische wrote:
> 
> > For example, 'print $f<tab>' or 'print $fo<tab>+$foo' after running
> > 'set $foo=0' now tab completes.
> > 
> > 'print $_siginf<tab>' also now tab completes.
> > ---
> > gdb/completer.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> > 
> > diff --git a/gdb/completer.c b/gdb/completer.c
> > index 1008ec23b..3c9f01c84 100644
> > --- a/gdb/completer.c
> > +++ b/gdb/completer.c
> > @@ -1099,6 +1099,17 @@ complete_expression (completion_tracker &tracker,
> > && expr_completer->complete (exp.get (), tracker))
> > return;
> > 
> > + /* If the text is non-empty, see if the word is preceded by '$'. */
> > + if (text[0] != '\0' && text[strlen(text)-strlen(word)-1] == '$')
> 
> 
> This should be formatted: text[strlen (text) - strlen (word) - 1]
> 
> > + {
> > + tracker.advance_custom_word_point_by (1);
> > + /* We don't support completion of history indices. */
> > + if (!isdigit (word[0]))
> > + complete_internalvar (tracker, word);
> > + tracker.advance_custom_word_point_by (-1);
> > + return;
> > + }
> > +
> > complete_files_symbols (tracker, text, word);
> > }
> 
> 
> I don't follow the use of advance_custom_word_point here, advancing
> by 1 and then reversing it. I don't seen that used anywhere else,
> either. Can you explain?
> 
> The behavior here is also a little strange with double TAB:
> 
> (gdb) p $_gdbTABTAB
> _gdb_maint_setting _gdb_major _gdb_setting
> _gdb_maint_setting_str _gdb_minor _gdb_setting_str
> 
> I would expect this to include the leading '$'.
> 
> Keith


More information about the Gdb-patches mailing list