aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-07-11 11:08:42 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-07-11 20:18:11 +0100
commit021d8588f6ca843a2aada955d00851fbb62f8a62 (patch)
tree2fe3e417f14317271aa14f6916669f0aef7942a3 /gdb/testsuite/gdb.base
parentb777eb6de24ae1a1dc2f1e48d593b0a5c79937a9 (diff)
downloadgdb-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/testsuite/gdb.base')
-rw-r--r--gdb/testsuite/gdb.base/options.exp56
1 files changed, 39 insertions, 17 deletions
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp
index e8f571d..561ca1d 100644
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -128,6 +128,13 @@ proc expect_integer {option val operand} {
# test-options xxx", with -string set to $STR. OPERAND is the
# expected operand.
proc expect_string {str operand} {
+ # Dequote the string in the expected output.
+ if { ( [string range $str 0 0] == "\""
+ && [string range $str end end] == "\"")
+ || ([string range $str 0 0] == "'"
+ && [string range $str end end] == "'")} {
+ set str [string range $str 1 end-1]
+ }
return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '$str' -- $operand"
}
@@ -967,26 +974,41 @@ proc_with_prefix test-string {variant} {
"-string requires an argument"
}
- res_test_gdb_complete_none \
- "1 [expect_none ""]" \
- "$cmd -string STR"
- gdb_test "$cmd -string STR --" [expect_string "STR" ""]
+ foreach_with_prefix str {
+ "STR"
+ "\"STR\""
+ "\\\"STR"
+ "'STR'"
+ "\\'STR"
+ "\"STR AAA\""
+ "'STR BBB'"
+ "\"STR 'CCC' DDD\""
+ "'STR \"EEE\" FFF'"
+ "\"STR \\\"GGG\\\" HHH\""
+ "'STR \\\'III\\\' JJJ'"
+ } {
+ res_test_gdb_complete_none \
+ "1 [expect_none ""]" \
+ "$cmd -string ${str}"
+ gdb_test "$cmd -string ${str} --" [expect_string "${str}" ""]
- # Completing at "-" after parsing STR should list all options.
- res_test_gdb_complete_multiple \
- "1 [expect_string "STR" "-"]" \
- "$cmd -string STR " "-" "" $all_options
+ # Completing at "-" after parsing STR should list all options.
+ res_test_gdb_complete_multiple \
+ "1 [expect_string "${str}" "-"]" \
+ "$cmd -string ${str} " "-" "" $all_options
- # Check that only FOO is considered part of the string's value.
- # I.e., that we stop parsing the string at the first whitespace.
- if {$variant == "require-delimiter"} {
- res_test_gdb_complete_none \
- "1 [expect_string "FOO" "BAR"]" \
- "$cmd -string FOO BAR"
- } else {
- res_test_gdb_complete_none "0 BAR" "$cmd -string FOO BAR"
+ # Check that only $STR is considered part of the string's value.
+ # I.e., that we stop parsing the string at the first
+ # whitespace or after the closing quote of $STR.
+ if {$variant == "require-delimiter"} {
+ res_test_gdb_complete_none \
+ "1 [expect_string "${str}" "BAR"]" \
+ "$cmd -string ${str} BAR"
+ } else {
+ res_test_gdb_complete_none "0 BAR" "$cmd -string ${str} BAR"
+ }
+ gdb_test "$cmd -string ${str} BAR --" "Unrecognized option at: BAR --"
}
- gdb_test "$cmd -string FOO BAR --" "Unrecognized option at: BAR --"
}
# Run the options framework tests first.