This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Provide useful completer for "info registers"
- From: Andreas Arnez <arnez at linux dot vnet dot ibm dot com>
- To: Sergio Durigan Junior <sergiodj at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 28 Nov 2014 19:14:32 +0100
- Subject: Re: [PATCH] Provide useful completer for "info registers"
- Authentication-results: sourceware.org; auth=none
- References: <87h9xnqje8 dot fsf at br87z6lw dot de dot ibm dot com> <87ioi1bs3x dot fsf at redhat dot com>
On Wed, Nov 26 2014, Sergio Durigan Junior wrote:
> On Tuesday, November 25 2014, Andreas Arnez wrote:
>
>> [...]
>> @@ -836,6 +838,55 @@ signal_completer (struct cmd_list_element *ignore,
>> return return_val;
>> }
>>
>> +/* Complete on a register or reggroup. */
>> +
>> +VEC (char_ptr) *
>> +reg_or_group_completer (struct cmd_list_element *ignore,
>> + const char *text, const char *word)
>> +{
>> + VEC (char_ptr) *result = NULL;
>> + size_t len = strlen (text);
>
> Hm, this should be "strlen (word)".
>
> The "text" will hold the entire line that is being completed, and "word"
> will hold just the last word, according to the breaking characters being
> used for this specific completer. For example, consider:
>
> (gdb) info registers rsp es
>
> In this case, "text" will be "rsp es", and "word" will be "es". Most of
> the time, you will only be interested in using "word" for the
> completion.
>
> Therefore, the "len" variable should hold "strlen (word)". Also, later
> in the code you are comparing each register name against "text", but you
> should be comparing against "word", for the reason explained above.
>
> Yeah, it can be confusing :-/.
First I actually had used 'word' here, but then I noticed that the
completer's notion of words doesn't match how the command parses its
arguments. If using 'word', the completer behaves like this:
(gdb) complete info registers hello,g
info registers hello,general
Which I consider a bit strange. However, I realize this may not be a
real problem for users, and being able to expand multiple arguments
probably beats this flaw, so I'll use 'word', as suggested.
> [...]
>
> While I understand and like this approach, we have a function that does
> the "strncmp" dance for you. All you need to do is provide a list of
> possible candidates (char **), and the word being completed. I gave it
> a try and hacked your patch to do that. The resulting patch is
> attached, feel free to use it if you like the approach.
Thanks for the patch! Indeed I didn't know about complete_on_enum()
before. But after weighing pros and cons, I still prefer the "strncmp
dance": It's not longer and needs somewhat less logic, e.g. only two
instead of three loops and no temporary xmalloc'd buffer. Also, I think
the code is easier to maintain if signal_completer and
reg_or_group_completer use the same approach.
But since it's a short function, I will dissolve the sub-blocks and move
the variable declarations to the top instead, like your patch does.
> I'd say this patch also needs a testcase :-). I know that this is
> architecture specific, so I'd personally be happy with something very
> simple, maybe testing only one or two architectures would be enough.
Yes, a test case would probably be adequate. I'll try it in an
architecture-independent way and include it in the next version.
> Other than that, it is fine by me (not an approval). Thanks for doing
> that.
Thanks for looking at this, and for your feedback. Much appreciated.