diff options
author | Yao Qi <yao@codesourcery.com> | 2013-08-27 03:04:45 +0000 |
---|---|---|
committer | Yao Qi <yao@codesourcery.com> | 2013-08-27 03:04:45 +0000 |
commit | 242f1fd7ee29538968e32155c99a36c3d7604eb5 (patch) | |
tree | 63842883ad96777ca1f546e358c1456d6fea4618 /gdb/mi/mi-getopt.c | |
parent | e5034e59e04c90d3a0b6c78af0cbfd3f73eb7809 (diff) | |
download | gdb-242f1fd7ee29538968e32155c99a36c3d7604eb5.zip gdb-242f1fd7ee29538968e32155c99a36c3d7604eb5.tar.gz gdb-242f1fd7ee29538968e32155c99a36c3d7604eb5.tar.bz2 |
Add mi_getopt_allow_unknown
This patch is to add a new function mi_getopt_allow_unknown, which
returns -1 silently (without throwing error) when unknown option is
met, and use this function to parse options for command
'-stack-list-arguments'.
gdb/
* 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.
Diffstat (limited to 'gdb/mi/mi-getopt.c')
-rw-r--r-- | gdb/mi/mi-getopt.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/gdb/mi/mi-getopt.c b/gdb/mi/mi-getopt.c index a1e2ccc..f207249 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, + throw 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_allow_unknown (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 |