diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-07-11 11:08:42 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-07-11 20:18:11 +0100 |
commit | 021d8588f6ca843a2aada955d00851fbb62f8a62 (patch) | |
tree | 2fe3e417f14317271aa14f6916669f0aef7942a3 /gdb/cli | |
parent | b777eb6de24ae1a1dc2f1e48d593b0a5c79937a9 (diff) | |
download | gdb-021d8588f6ca843a2aada955d00851fbb62f8a62.zip gdb-021d8588f6ca843a2aada955d00851fbb62f8a62.tar.gz gdb-021d8588f6ca843a2aada955d00851fbb62f8a62.tar.bz2 |
gdb: Allow quoting around string options in the gdb::option framework
Currently string options must be a single string with no whitespace,
this limitation prevents the gdb::option framework being used in some
places.
After this commit, string options can be quoted in single or double
quotes, and quote characters can be escaped with a backslash if needed
to either place them within quotes, or to avoid starting a quoted
argument.
This test adds a new function extract_string_maybe_quoted which is
basically a copy of extract_arg_maybe_quoted from cli/cli-utils.c,
however, the cli-utils.c function will be deleted in the next commit.
There are tests to exercise the new quoting mechanism.
gdb/ChangeLog:
* cli/cli-option.c (parse_option): Use extract_string_maybe_quoted
to extract string arguments.
* common/common-utils.c (extract_string_maybe_quoted): New function.
* common/common-utils.h (extract_string_maybe_quoted): Declare.
gdb/testsuite/ChangeLog:
* gdb.base/options.exp (expect_string): Dequote strings in
results.
(test-string): Test strings with different quoting and reindent.
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-option.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c index 07d552b..eb8ef79 100644 --- a/gdb/cli/cli-option.c +++ b/gdb/cli/cli-option.c @@ -434,13 +434,12 @@ parse_option (gdb::array_view<const option_def_group> options_group, } const char *arg_start = *args; - *args = skip_to_space (*args); - + std::string str = extract_string_maybe_quoted (args); if (*args == arg_start) error (_("-%s requires an argument"), match->name); option_value val; - val.string = savestring (arg_start, *args - arg_start); + val.string = xstrdup (str.c_str ()); return option_def_and_value {*match, match_ctx, val}; } |