From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
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 [thread overview]
Message-ID: <1372816106-15942-2-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1372816106-15942-1-git-send-email-yao@codesourcery.com>
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 <yao@codesourcery.com>
* 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
next prev parent reply other threads:[~2013-07-03 1:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-03 1:48 [PATCH 0/2] New option --skip-unavailable to -stack-list-XXX commands Yao Qi
2013-07-03 1:48 ` Yao Qi [this message]
2013-07-29 18:17 ` [PATCH 1/2] Use mi_getopt in mi_cmd_stack_list_locals and mi_cmd_stack_list_variables Pedro Alves
2013-07-31 7:01 ` Yao Qi
2013-07-31 12:23 ` Pedro Alves
2013-08-01 6:45 ` Yao Qi
2013-07-03 1:48 ` [PATCH 2/2] Add options to skip unavailable locals Yao Qi
2013-07-03 4:14 ` asmwarrior
2013-07-03 5:21 ` Yao Qi
2013-07-03 19:22 ` Eli Zaretskii
2013-07-22 1:38 ` Yao Qi
2013-08-01 12:33 ` Pedro Alves
2013-08-01 13:59 ` Yao Qi
2013-08-01 14:47 ` Pedro Alves
2013-08-25 3:43 ` [PATCH 0/2 v2] " Yao Qi
2013-08-25 3:43 ` [PATCH 1/2] Use mi_getopt_silent Yao Qi
2013-08-26 8:58 ` Agovic, Sanimir
2013-08-26 10:18 ` Yao Qi
2013-08-26 16:01 ` Pedro Alves
2013-08-26 16:22 ` Pedro Alves
2013-08-27 3:30 ` Yao Qi
2013-08-27 11:43 ` Pedro Alves
2013-08-25 3:43 ` [PATCH 2/2] Add options to skip unavailable locals Yao Qi
2013-08-26 16:40 ` Pedro Alves
2013-08-27 5:22 ` Yao Qi
2013-07-29 9:33 ` [ping]: [PATCH 0/2] New option --skip-unavailable to -stack-list-XXX commands Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1372816106-15942-2-git-send-email-yao@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox