From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16518 invoked by alias); 31 Jul 2013 07:01:36 -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 16493 invoked by uid 89); 31 Jul 2013 07:01:35 -0000 X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_20,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RDNS_NONE autolearn=no version=3.3.1 Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 31 Jul 2013 07:01:34 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1V4QPV-0003bf-Sq from Yao_Qi@mentor.com ; Wed, 31 Jul 2013 00:01:25 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 31 Jul 2013 00:01:26 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Wed, 31 Jul 2013 00:01:25 -0700 Message-ID: <51F8B61B.4000204@codesourcery.com> Date: Wed, 31 Jul 2013 07:01:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Pedro Alves CC: Subject: Re: [PATCH 1/2] Use mi_getopt in mi_cmd_stack_list_locals and mi_cmd_stack_list_variables References: <1372816106-15942-1-git-send-email-yao@codesourcery.com> <1372816106-15942-2-git-send-email-yao@codesourcery.com> <51F6B1A1.6030704@redhat.com> In-Reply-To: <51F6B1A1.6030704@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-SW-Source: 2013-07/txt/msg00807.txt.bz2 On 07/30/2013 02:17 AM, Pedro Alves wrote: > Please help me understand the patch. Why do we need to copy > the arg vector? Isn't it the same to do: > > /* Don't parse 'print-values' as an option. */ > int opt = mi_getopt ("-stack-list-locals", argc - 1, argv, > opts, &oind, &oarg); > > ? There was something wrong in mi_getopt (an internal error, IIRC) when I call mi_getopt with 'argc - 1', however, I can't reproduce it now. Probably because my tree was dirty then. I update the patch to avoid copying the arg vector. Patch 2/2 still apply. -- Yao (齐尧) gdb: 2013-07-31 Yao Qi * mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Parse argv by mi_getopt. (mi_cmd_stack_list_variables): Likewise. --- gdb/mi/mi-cmd-stack.c | 79 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 69 insertions(+), 10 deletions(-) diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index 1f1068c..70ff0b6 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -212,16 +212,46 @@ 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) + { + int i; + enum opt + { + NO_FRAME_FILTERS + }; + static const struct mi_opt opts[] = + { + {"-no-frame-filters", NO_FRAME_FILTERS, 0}, + { 0, 0, 0 } + }; + + while (1) + { + char *oarg; + /* Don't parse 'print-values' as an option. */ + int opt = mi_getopt ("-stack-list-locals", argc - 1, argv, + opts, &oind, &oarg); + + if (opt < 0) + break; + switch ((enum opt) opt) + { + case NO_FRAME_FILTERS: + raw_arg = oind; + break; + } + } + } - 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 +371,46 @@ 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) + { + int i; + enum opt + { + NO_FRAME_FILTERS + }; + static const struct mi_opt opts[] = + { + {"-no-frame-filters", NO_FRAME_FILTERS, 0}, + { 0, 0, 0 } + }; + + while (1) + { + char *oarg; + /* Don't parse 'print-values' as an option. */ + int opt = mi_getopt ("-stack-list-variables", argc - 1, + argv, opts, &oind, &oarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case NO_FRAME_FILTERS: + raw_arg = oind; + break; + } + } + } - 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