From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21165 invoked by alias); 3 Jul 2013 01:48:54 -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 21118 invoked by uid 89); 3 Jul 2013 01:48:53 -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,TW_RG autolearn=ham version=3.3.1 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; Wed, 03 Jul 2013 01:48:52 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1UuCBe-0000r4-Pk from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Tue, 02 Jul 2013 18:48:50 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 2 Jul 2013 18:48:50 -0700 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.2.247.3; Tue, 2 Jul 2013 18:48:49 -0700 From: Yao Qi To: Subject: [PATCH 1/2] Use mi_getopt in mi_cmd_stack_list_locals and mi_cmd_stack_list_variables Date: Wed, 03 Jul 2013 01:48:00 -0000 Message-ID: <1372816106-15942-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1372816106-15942-1-git-send-email-yao@codesourcery.com> References: <1372816106-15942-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-07/txt/msg00103.txt.bz2 Hi, During the review of frame filter MI patch, Tom pointed that it is better to use mi_getopt to simplify option parsing. Unfortunately, the code doesn't do it. Since I am trying to add another option to commands '-stack-list-XXXX', I'd like to have a try to use mi_getopt. For command '-stack-list-locals' and '-stack-list-variables', the PRINT_VALUES may confuse option parsing by mi_getopt, so in this patch, we copy the argv except PRINT_VALUES to a new vector, and parse the new vector by mi_getopt. gdb: 2013-07-03 Yao Qi * mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Don't call parse_no_frames_option. Copy ARGV to new_argv except PRINT_VALUES. Parse new_argv by mi_getopt. (mi_cmd_stack_list_variables): Likewise. --- gdb/mi/mi-cmd-stack.c | 99 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 89 insertions(+), 10 deletions(-) diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index 4b21015..3212c03 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -212,16 +212,56 @@ mi_cmd_stack_list_locals (char *command, char **argv, int argc) int raw_arg = 0; enum py_bt_status result = PY_BT_ERROR; int print_value; + int oind = 0; - if (argc > 0) - raw_arg = parse_no_frames_option (argv[0]); + if (argc > 1) + { + struct cleanup *cleanup; + int i; + char **new_argv = xmalloc ((argc - 1) * sizeof (char *)); + enum opt + { + NO_FRAME_FILTERS + }; + static const struct mi_opt opts[] = + { + {"-no-frame-filters", NO_FRAME_FILTERS, 0}, + { 0, 0, 0 } + }; + + cleanup = make_cleanup (xfree, new_argv); + + for (i = 0; i < argc - 1; i++) + { + new_argv[i] = xstrdup (argv[i]); + make_cleanup (xfree, new_argv[i]); + } + + while (1) + { + char *oarg; + /* Don't parse 'print-values' as an option. */ + int opt = mi_getopt ("-stack-list-locals", argc - 1, new_argv, + opts, &oind, &oarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case NO_FRAME_FILTERS: + raw_arg = oind; + break; + } + } + do_cleanups (cleanup); + } - if (argc < 1 || argc > 2 || (argc == 2 && ! raw_arg) - || (argc == 1 && raw_arg)) + /* After the last option is parsed, there should be only + 'print-values'. */ + if (argc - oind != 1) error (_("-stack-list-locals: Usage: [--no-frame-filters] PRINT_VALUES")); frame = get_selected_frame (NULL); - print_value = mi_parse_print_values (argv[raw_arg]); + print_value = mi_parse_print_values (argv[oind]); if (! raw_arg && frame_filters) { @@ -341,17 +381,56 @@ mi_cmd_stack_list_variables (char *command, char **argv, int argc) int raw_arg = 0; enum py_bt_status result = PY_BT_ERROR; int print_value; + int oind = 0; - if (argc > 0) - raw_arg = parse_no_frames_option (argv[0]); + if (argc > 1) + { + struct cleanup *cleanup; + int i; + char **new_argv = xmalloc ((argc - 1) * sizeof (char *)); + enum opt + { + NO_FRAME_FILTERS + }; + static const struct mi_opt opts[] = + { + {"-no-frame-filters", NO_FRAME_FILTERS, 0}, + { 0, 0, 0 } + }; + cleanup = make_cleanup (xfree, new_argv); + + for (i = 0; i < argc - 1; i++) + { + new_argv[i] = xstrdup (argv[i]); + make_cleanup (xfree, new_argv[i]); + } + + while (1) + { + char *oarg; + /* Don't parse 'print-values' as an option. */ + int opt = mi_getopt ("-stack-list-variables", argc - 1, + new_argv, opts, &oind, &oarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case NO_FRAME_FILTERS: + raw_arg = oind; + break; + } + } + do_cleanups (cleanup); + } - if (argc < 1 || argc > 2 || (argc == 2 && ! raw_arg) - || (argc == 1 && raw_arg)) + /* After the last option is parsed, there should be only + 'print-values'. */ + if (argc - oind != 1) error (_("-stack-list-variables: Usage: " \ "[--no-frame-filters] PRINT_VALUES")); frame = get_selected_frame (NULL); - print_value = mi_parse_print_values (argv[raw_arg]); + print_value = mi_parse_print_values (argv[oind]); if (! raw_arg && frame_filters) { -- 1.7.7.6