This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Provide useful completer for "info registers"


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]