From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28572 invoked by alias); 26 Aug 2013 16:22:18 -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 28563 invoked by uid 89); 26 Aug 2013 16:22:18 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Aug 2013 16:22:18 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.8 required=5.0 tests=ALL_TRUSTED,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7QGMFnk028049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Aug 2013 12:22:15 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7QGMEub023383; Mon, 26 Aug 2013 12:22:14 -0400 Message-ID: <521B80B5.1020108@redhat.com> Date: Mon, 26 Aug 2013 16:22:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Yao Qi CC: gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] Use mi_getopt_silent References: <51FA557F.5@redhat.com> <1377402123-3740-1-git-send-email-yao@codesourcery.com> <1377402123-3740-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1377402123-3740-2-git-send-email-yao@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-08/txt/msg00750.txt.bz2 On 08/25/2013 04:42 AM, Yao Qi wrote: > This patch is to add a new function mi_getopt_silent, which returns -1 > silently (without throwing error) when unknown option is met, and use > this function to parse options for command '-stack-list-arguments'. > > It makes easier to add a new option in patch 2/2. Thanks! This is OK. A few minor suggestions below. > 2013-08-24 Yao Qi > > * mi/mi-cmd-stack.c (parse_no_frames_option): Remove. > (mi_cmd_stack_list_args): Use mi_getopt_silent to handle > options. > * mi/mi-getopt.c (mi_getopt): Remove. This "remove" got me confused, and made think it was a ChangeLog mistake. > (mi_getopt_1): Renamed from mi_getopt. Add one parameter > 'error_on_unknown'. > (mi_getopt): Call mi_getopt_1. > (mi_getopt_silent): New. Here's what I suggest: * mi/mi-getopt.c (mi_getopt): Rename to ... (mi_getopt_1): ... this. Add parameter 'error_on_unknown'. (mi_getopt): Reimplement as wrapper around mi_getopt_1. (mi_getopt_silent): New function. > * mi/mi-getopt.h (mi_getopt_silent): Declare. > --- a/gdb/mi/mi-getopt.c > +++ b/gdb/mi/mi-getopt.c > @@ -21,11 +21,14 @@ > #include "mi-getopt.h" > #include "gdb_string.h" > > -int > -mi_getopt (const char *prefix, > - int argc, char **argv, > - const struct mi_opt *opts, > - int *oind, char **oarg) > +/* See comments about mi_getopt and mi_getopt_silent in mi-getopt.h. > + When there is an unknown option, if ERROR_ON_UNKNOWN is true, it > + throws an error, otherwise return -1. */ ("throws" -> "returns"). I'd suggest: If an unknown option is encountered, if ERROR_ON_UNKNOWN is true, throw an error, otherwise return -1. */ > + > +static int > +mi_getopt_1 (const char *prefix, int argc, char **argv, > + const struct mi_opt *opts, int *oind, char **oarg, > + int error_on_unknown) > { > > int > diff --git a/gdb/mi/mi-getopt.h b/gdb/mi/mi-getopt.h > index 9600353..cabe488 100644 > --- a/gdb/mi/mi-getopt.h > +++ b/gdb/mi/mi-getopt.h > @@ -46,11 +46,15 @@ struct mi_opt > If ARGV[OPTIND] is not an option, -1 is returned and OPTIND updated > to specify the non-option argument. OPTARG is set to NULL. > > - mi_getopt() calls ``error("%s: Unknown option %c", prefix, > - option)'' if an unknown option is encountered. */ > + If an unknown option is encountered, mi_getopt() calls > + ``error("%s: Unknown option %c", prefix, option)'' and mi_getopt_silent > + returns -1. */ I'd suggest s/and/while/. > > extern int mi_getopt (const char *prefix, int argc, char **argv, > const struct mi_opt *opt, int *optind, char **optarg); > +extern int mi_getopt_silent (const char *prefix, int argc, char **argv, > + const struct mi_opt *opts, int *oind, > + char **oarg); -- Pedro Alves