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 Friday, November 28 2014, Andreas Arnez wrote:

>> 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.

Yeah.  This is a problem with our completer scheme; you can see this
behavior happening also for other commands:

  (gdb) complete break hello,ma
  break hello,mabort
  break hello,madvise
  ...

And I agree that this may not be a real problem for users (since this
problem exists for a long time apparently).

>> [...]
>>
>> 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.

Agreed :-).  Although complete_on_enum exists, its interface is in dire
need of a revamp; besides, using it on your function does not make the
code simpler or clearer as you pointed.

> 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.

Thanks.

>> 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.

No, thank you!  :-)

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/


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