From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 723 invoked by alias); 7 May 2013 08:23:52 -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 697 invoked by uid 89); 7 May 2013 08:23:51 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,TW_RG autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 07 May 2013 08:23:50 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r478Nmn0016351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 May 2013 04:23:49 -0400 Received: from localhost.localdomain (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r478NlwX016169; Tue, 7 May 2013 04:23:47 -0400 Message-ID: <5188BA12.4050508@redhat.com> Date: Tue, 07 May 2013 08:23:00 -0000 From: Phil Muldoon MIME-Version: 1.0 To: Tom Tromey CC: "gdb-patches@sourceware.org" Subject: Re: [patch][python] 2 of 5 - Frame filter MI code changes. References: <51876882.3010301@redhat.com> <87ppx3x2k3.fsf@fleche.redhat.com> In-Reply-To: <87ppx3x2k3.fsf@fleche.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-05/txt/msg00180.txt.bz2 On 06/05/13 21:42, Tom Tromey wrote: >>>>>> "Phil" == Phil Muldoon writes: > > Phil> @@ -52,14 +78,43 @@ mi_cmd_stack_list_frames (char *command, char **argv, int argc) > > Phil> + if ((argc > 3) || (argc == 2 && oind) || (argc == 1 && ! oind)) > Phil> + error (_("-stack-list-frames: Usage: [--no-frame-filters] [FRAME_LOW FRAME_HIGH]")); > > Phil> - if (argc == 2) > Phil> + if (argc == 3 || argc == 2) > > It seems to me that these checks should use oind rather than argc. > Then they would be simpler. > > As it is I think they are wrong for the weird but accepted input: > > -stack-list-frames --no-frame-filters --no-frame-filters 0 15 I'm not sure how I would write them just using oind. oind will be an integer index to the last option in the argv list parsed. -stack-list-frames --no-frame-filters 0 15 mi_getopt stops parsing when it reaches the first non-option argument. So in this case it would be 1. argc is the total number of arguments, which is in that case is 3. Your example: -stack-list-frames --no-frame-filters --no-frame-filters 0 15 Would fail on the first "if" condition check: if ((argc > 3) || (argc == 2 && oind) || (argc == 1 && ! oind)) As argc is > 3. Typically from what I have found all MI commands do an argc check for the accepted number of arguments. Because MI relies on integer arguments for ranges (i.e. FRAME LOW - FRAME HIGH), and also some MI commands allow integer substitutions for some options (i.e., 1 or --all-values), and mi_getopt stops parsing on the first non-option it encounters, MI arguments are inherently limited to strict positional adherence. Anyway, that "if" statement just checks for permutations of -stack-list-frames --no-frame-filters 1 2 3 4 -stack-list-frames --no-frame-filters 1 -stack-list-frames 1 It looks like I am missing a check for: if (argc == 3 && ! oind). I will add that. If there is a way to write the test solely using oind I will happily do it, but I must admit to being puzzled how to do it. Cheers Phil