From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22784 invoked by alias); 25 Aug 2013 03:43:22 -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 22735 invoked by uid 89); 25 Aug 2013 03:43:22 -0000 X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL autolearn=ham version=3.3.2 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 25 Aug 2013 03:43:21 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VDRET-0004GP-Tv from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Sat, 24 Aug 2013 20:43:17 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Sat, 24 Aug 2013 20:43:18 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.2.247.3; Sat, 24 Aug 2013 20:43:16 -0700 From: Yao Qi To: Subject: [PATCH 1/2] Use mi_getopt_silent Date: Sun, 25 Aug 2013 03:43:00 -0000 Message-ID: <1377402123-3740-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1377402123-3740-1-git-send-email-yao@codesourcery.com> References: <51FA557F.5@redhat.com> <1377402123-3740-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-08/txt/msg00724.txt.bz2 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. gdb: 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. (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(-) 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 **argv, int argc) frame_filters = 1; } -/* 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") == 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 = current_uiout; int raw_arg = 0; + int oind = 0; enum py_bt_status result = PY_BT_ERROR; + enum opt + { + NO_FRAME_FILTERS, + }; + static const struct mi_opt opts[] = + { + {"-no-frame-filters", NO_FRAME_FILTERS, 0}, + { 0, 0, 0 } + }; - if (argc > 0) - raw_arg = parse_no_frames_option (argv[0]); + while (1) + { + char *oarg; + int opt = 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 = oind; + break; + } + } - if (argc < 1 || (argc > 3 && ! raw_arg) || (argc == 2 && ! raw_arg)) - error (_("-stack-list-arguments: Usage: " \ + if (argc - oind != 1 && argc - oind != 3) + error (_("-stack-list-arguments: Usage: " \ "[--no-frame-filters] PRINT_VALUES [FRAME_LOW FRAME_HIGH]")); - if (argc >= 3) + if (argc - oind == 3) { - frame_low = atoi (argv[1 + raw_arg]); - frame_high = atoi (argv[2 + raw_arg]); + frame_low = atoi (argv[1 + oind]); + frame_high = atoi (argv[2 + oind]); } else { @@ -306,7 +318,7 @@ mi_cmd_stack_list_args (char *command, char **argv, int argc) frame_high = -1; } - print_values = mi_parse_print_values (argv[raw_arg]); + print_values = mi_parse_print_values (argv[oind]); /* 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" -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); } 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. */ 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); /* 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