From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17619 invoked by alias); 28 Nov 2014 18:14:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17604 invoked by uid 89); 28 Nov 2014 18:14:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp17.uk.ibm.com Received: from e06smtp17.uk.ibm.com (HELO e06smtp17.uk.ibm.com) (195.75.94.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 28 Nov 2014 18:14:39 +0000 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 28 Nov 2014 18:14:35 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 28 Nov 2014 18:14:33 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id B0CF62190045 for ; Fri, 28 Nov 2014 18:14:05 +0000 (GMT) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sASIEXAP18677924 for ; Fri, 28 Nov 2014 18:14:33 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sASIEXE6000393 for ; Fri, 28 Nov 2014 11:14:33 -0700 Received: from br87z6lw.de.ibm.com (dyn-9-152-212-196.boeblingen.de.ibm.com [9.152.212.196]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sASIEWFP000356; Fri, 28 Nov 2014 11:14:32 -0700 From: Andreas Arnez To: Sergio Durigan Junior Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Provide useful completer for "info registers" References: <87h9xnqje8.fsf@br87z6lw.de.ibm.com> <87ioi1bs3x.fsf@redhat.com> Date: Fri, 28 Nov 2014 18:14:00 -0000 In-Reply-To: <87ioi1bs3x.fsf@redhat.com> (Sergio Durigan Junior's message of "Wed, 26 Nov 2014 15:54:10 -0500") Message-ID: <87vblzp4zb.fsf@br87z6lw.de.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14112818-0029-0000-0000-000001ECC495 X-IsSubscribed: yes X-SW-Source: 2014-11/txt/msg00719.txt.bz2 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.