From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Provide useful completer for "info registers"
Date: Fri, 28 Nov 2014 18:14:00 -0000 [thread overview]
Message-ID: <87vblzp4zb.fsf@br87z6lw.de.ibm.com> (raw)
In-Reply-To: <87ioi1bs3x.fsf@redhat.com> (Sergio Durigan Junior's message of "Wed, 26 Nov 2014 15:54:10 -0500")
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.
next prev parent reply other threads:[~2014-11-28 18:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 17:28 Andreas Arnez
2014-11-26 20:54 ` Sergio Durigan Junior
2014-11-26 21:52 ` Sergio Durigan Junior
2014-11-28 18:14 ` Andreas Arnez [this message]
2014-11-28 20:39 ` Sergio Durigan Junior
2014-12-04 17:34 ` Pedro Alves
2014-12-10 17:36 ` Andreas Arnez
2014-12-10 18:21 ` Pedro Alves
2014-12-04 17:38 ` Pedro Alves
2014-12-10 17:48 ` Andreas Arnez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vblzp4zb.fsf@br87z6lw.de.ibm.com \
--to=arnez@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=sergiodj@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).