From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28143 invoked by alias); 26 Aug 2013 08:58: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 28134 invoked by uid 89); 26 Aug 2013 08:58:52 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (143.182.124.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Aug 2013 08:58:52 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE autolearn=no version=3.3.2 X-HELO: mga14.intel.com Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga102.ch.intel.com with ESMTP; 26 Aug 2013 01:58:48 -0700 X-ExtLoop1: 1 Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by AZSMGA002.ch.intel.com with ESMTP; 26 Aug 2013 01:58:47 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.64]) by IRSMSX104.ger.corp.intel.com ([169.254.5.157]) with mapi id 14.03.0123.003; Mon, 26 Aug 2013 09:58:47 +0100 From: "Agovic, Sanimir" To: 'Yao Qi' CC: "gdb-patches@sourceware.org" Subject: RE: [PATCH 1/2] Use mi_getopt_silent Date: Mon, 26 Aug 2013 08:58:00 -0000 Message-ID: <0377C58828D86C4588AEEC42FC3B85A71764DC1D@IRSMSX105.ger.corp.intel.com> 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="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2013-08/txt/msg00731.txt.bz2 Hello Yao, I`d rather catch the exception in mi_cmd_stack_list_args to prevent the=20 error to bubble up to upper layers. This requires the use of=20 throw_error (NOT_FOUND_ERROR, ...) instead of error (...) in mi_getopt to catch the right exception (*) and re-throw otherwise. Due to the poor exception handling in gdb this may lead to some boilerplate code. On the other side it keeps the interface simple & consistent=20 e.g. (*) in the patch below mi_getopt_silent may still be verbose/throw. -Sanimir > -----Original Message----- > From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourcewa= re.org] On Behalf > Of Yao Qi > Sent: Sunday, August 25, 2013 05:42 AM > To: gdb-patches@sourceware.org > Subject: [PATCH 1/2] Use mi_getopt_silent >=20 > 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'. >=20 > It makes easier to add a new option in patch 2/2. > gdb: >=20 > 2013-08-24 Yao Qi >=20 > * mi/mi-cmd-stack.c (parse_no_frames_option): Remove. > (mi_cmd_stack_list_args): Use mi_getopt_silent to handle > options.=09 > * mi/mi-getopt.c (mi_getopt): Remove. > (mi_getopt_1): Renamed from mi_getopt. Add one parameter > 'error_on_unknown'. > (mi_getopt): Call mi_getopt_1. > (mi_getopt_silent): New. > * mi/mi-getopt.h (mi_getopt_silent): Declare. > --- > gdb/mi/mi-cmd-stack.c | 50 ++++++++++++++++++++++++++++++-------------= ----- > gdb/mi/mi-getopt.c | 35 ++++++++++++++++++++++++++++----- > gdb/mi/mi-getopt.h | 8 +++++- > 3 files changed, 66 insertions(+), 27 deletions(-) >=20 > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c > index e542fc1..b280e7d 100644 > --- a/gdb/mi/mi-cmd-stack.c > +++ b/gdb/mi/mi-cmd-stack.c > @@ -54,17 +54,6 @@ mi_cmd_enable_frame_filters (char *command, char **arg= v, int argc) > frame_filters =3D 1; > } >=20 > -/* Parse the --no-frame-filters option in commands where we cannot use > - mi_getopt. */ > -static int > -parse_no_frames_option (const char *arg) > -{ > - if (arg && (strcmp (arg, "--no-frame-filters") =3D=3D 0)) > - return 1; > - > - return 0; > -} > - > /* Print a list of the stack frames. Args can be none, in which case > we want to print the whole backtrace, or a pair of numbers > specifying the frame numbers at which to start and stop the > @@ -284,19 +273,42 @@ mi_cmd_stack_list_args (char *command, char **argv,= int argc) > enum print_values print_values; > struct ui_out *uiout =3D current_uiout; > int raw_arg =3D 0; > + int oind =3D 0; > enum py_bt_status result =3D PY_BT_ERROR; > + enum opt > + { > + NO_FRAME_FILTERS, > + }; > + static const struct mi_opt opts[] =3D > + { > + {"-no-frame-filters", NO_FRAME_FILTERS, 0}, > + { 0, 0, 0 } > + }; >=20 > - if (argc > 0) > - raw_arg =3D parse_no_frames_option (argv[0]); > + while (1) > + { > + char *oarg; > + int opt =3D mi_getopt_silent ("-stack-list-args", argc, argv, opts, > + &oind, &oarg); > + > + if (opt < 0) > + break; > + switch ((enum opt) opt) > + { > + case NO_FRAME_FILTERS: > + raw_arg =3D oind; > + break; > + } > + } >=20 > - if (argc < 1 || (argc > 3 && ! raw_arg) || (argc =3D=3D 2 && ! raw_arg= )) > - error (_("-stack-list-arguments: Usage: " \ > + if (argc - oind !=3D 1 && argc - oind !=3D 3) > + error (_("-stack-list-arguments: Usage: " \ > "[--no-frame-filters] PRINT_VALUES [FRAME_LOW FRAME_HIGH]")); >=20 > - if (argc >=3D 3) > + if (argc - oind =3D=3D 3) > { > - frame_low =3D atoi (argv[1 + raw_arg]); > - frame_high =3D atoi (argv[2 + raw_arg]); > + frame_low =3D atoi (argv[1 + oind]); > + frame_high =3D atoi (argv[2 + oind]); > } > else > { > @@ -306,7 +318,7 @@ mi_cmd_stack_list_args (char *command, char **argv, i= nt argc) > frame_high =3D -1; > } >=20 > - print_values =3D mi_parse_print_values (argv[raw_arg]); > + print_values =3D mi_parse_print_values (argv[oind]); >=20 > /* Let's position fi on the frame at which to start the > display. Could be the innermost frame if the whole stack needs > diff --git a/gdb/mi/mi-getopt.c b/gdb/mi/mi-getopt.c > index a1e2ccc..0255d22 100644 > --- a/gdb/mi/mi-getopt.c > +++ b/gdb/mi/mi-getopt.c > @@ -21,11 +21,14 @@ > #include "mi-getopt.h" > #include "gdb_string.h" >=20 > -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. */ > + > +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) > { > char *arg; > const struct mi_opt *opt; > @@ -71,7 +74,27 @@ mi_getopt (const char *prefix, > return opt->index; > } > } > - error (_("%s: Unknown option ``%s''"), prefix, arg + 1); > + > + if (error_on_unknown) > + error (_("%s: Unknown option ``%s''"), prefix, arg + 1); > + else > + return -1; > +} > + > +int > +mi_getopt (const char *prefix, > + int argc, char **argv, > + const struct mi_opt *opts, > + int *oind, char **oarg) > +{ > + return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 1); > +} > + > +int > +mi_getopt_silent (const char *prefix, int argc, char **argv, > + const struct mi_opt *opts, int *oind, char **oarg) > +{ > + return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 0); > } >=20 > 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. >=20 > - 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_sile= nt > + returns -1. */ >=20 > 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); >=20 > /* mi_valid_noargs determines if ARGC/ARGV are a valid set of > parameters to satisfy an MI function that is not supposed to > -- > 1.7.7.6 Intel GmbH Dornacher Strasse 1 85622 Feldkirchen/Muenchen, Deutschland Sitz der Gesellschaft: Feldkirchen bei Muenchen Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk Registergericht: Muenchen HRB 47456 Ust.-IdNr./VAT Registration No.: DE129385895 Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052