[2/2] gdb: Tab complete internalvars in expressions

Message ID 20240822154730.1595141-3-nt8r@protonmail.com
State New
Headers
Series Tab complete convenience variables |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Test failed

Commit Message

Antonio Rische Aug. 22, 2024, 3:47 p.m. UTC
  For example, 'print $f<tab>' after running 'set $foo=0' now tab
completes.

'print $_siginf<tab>' also now tab completes.
---
 gdb/completer.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Antonio Rische Aug. 22, 2024, 7:41 p.m. UTC | #1
It seems I misunderstood the semantics of the 'word' and 'text' parameters here. I'll correct in v2; as written this doesn't work for completions not at the start of the text to complete (e.g. 'print 4+$fo<tab>' or 'print $fo<tab>+4').

On Thursday, August 22nd, 2024 at 3:47 PM, Antonio Rische <nt8r@protonmail.com> wrote:

> For example, 'print $f<tab>' after running 'set $foo=0' now tab
> 
> completes.
> 
> 'print $_siginf<tab>' also now tab completes.
> 
> ---
> gdb/completer.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
> 
> diff --git a/gdb/completer.c b/gdb/completer.c
> index 1008ec23b..6476ddf79 100644
> --- a/gdb/completer.c
> +++ b/gdb/completer.c
> @@ -1099,6 +1099,16 @@ complete_expression (completion_tracker &tracker,
> && expr_completer->complete (exp.get (), tracker))
> 
> return;
> 
> + if (text[0] == '$')
> + {
> + tracker.advance_custom_word_point_by (1);
> + /* We don't support completion of history indices. */
> + if (!isdigit (text[1]))
> + complete_internalvar (tracker, &text[1]);
> + tracker.advance_custom_word_point_by (-1);
> + return;
> + }
> +
> complete_files_symbols (tracker, text, word);
> }
> 
> --
> 2.46.0
  
Keith Seitz Aug. 26, 2024, 4:54 p.m. UTC | #2
Hi,

On 8/22/24 12:41 PM, nt8r@protonmail.com wrote:
> It seems I misunderstood the semantics of the 'word' and 'text' parameters here. I'll correct in v2; as written this doesn't work for completions not at the start of the text to complete (e.g. 'print 4+$fo<tab>' or 'print $fo<tab>+4').

Wow, thank you for taking a look at this! This is a most welcome
submission.

Is it possible to include any tests exercising this new feature? That
would make review much easier for us.

There are several examples in gdb/testsuite/ to follow. Grep
for "test_gdb_complete" or take a look at the support routines
in gdb/testsuite/lib/completion-support.exp. [Also see
https://sourceware.org/gdb/wiki/GDBTestcaseCookbook and
gdb/testsuite/README for add'l pointers/examples on writing
and running tests.]

Do you have an assignment on file? If not, in order for us to
accept your patch, please see/follow

https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment

Thank you again for submitting a patch to fix this.

Keith
  
Antonio Rische Aug. 28, 2024, 1:36 a.m. UTC | #3
Thanks for the enthusiasm! I'm adding some tests in v2.

How do I go about copyright assignment? The documents I'm seeing seem to suggest getting in touch with a maintainer over e-mail.

Thanks,
Antonio

On Monday, August 26th, 2024 at 4:54 PM, Keith Seitz <keiths@redhat.com> wrote:

> Hi,
> 
> On 8/22/24 12:41 PM, nt8r@protonmail.com wrote:
> 
> > It seems I misunderstood the semantics of the 'word' and 'text' parameters here. I'll correct in v2; as written this doesn't work for completions not at the start of the text to complete (e.g. 'print 4+$fo<tab>' or 'print $fo<tab>+4').
> 
> 
> Wow, thank you for taking a look at this! This is a most welcome
> submission.
> 
> Is it possible to include any tests exercising this new feature? That
> would make review much easier for us.
> 
> There are several examples in gdb/testsuite/ to follow. Grep
> for "test_gdb_complete" or take a look at the support routines
> in gdb/testsuite/lib/completion-support.exp. [Also see
> https://sourceware.org/gdb/wiki/GDBTestcaseCookbook and
> gdb/testsuite/README for add'l pointers/examples on writing
> and running tests.]
> 
> Do you have an assignment on file? If not, in order for us to
> accept your patch, please see/follow
> 
> https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment
> 
> Thank you again for submitting a patch to fix this.
> 
> Keith
  
Eli Zaretskii Aug. 28, 2024, 2:30 a.m. UTC | #4
> Date: Wed, 28 Aug 2024 01:36:28 +0000
> From: nt8r@protonmail.com
> Cc: gdb-patches@sourceware.org
> 
> Thanks for the enthusiasm! I'm adding some tests in v2.
> 
> How do I go about copyright assignment? The documents I'm seeing seem to suggest getting in touch with a maintainer over e-mail.

I've sent the assignment form off-list.
  

Patch

diff --git a/gdb/completer.c b/gdb/completer.c
index 1008ec23b..6476ddf79 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1099,6 +1099,16 @@  complete_expression (completion_tracker &tracker,
       && expr_completer->complete (exp.get (), tracker))
     return;
 
+  if (text[0] == '$')
+	{
+	  tracker.advance_custom_word_point_by (1);
+	  /* We don't support completion of history indices.  */
+	  if (!isdigit (text[1]))
+	    complete_internalvar (tracker, &text[1]);
+	  tracker.advance_custom_word_point_by (-1);
+	  return;
+	}
+
   complete_files_symbols (tracker, text, word);
 }