diff options
-rw-r--r-- | gdb/testsuite/gdb.base/args.exp | 11 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/inferior-args.exp | 48 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/startup-with-shell.exp | 37 | ||||
-rw-r--r-- | gdbsupport/common-inferior.cc | 108 |
4 files changed, 91 insertions, 113 deletions
diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 34d722a..363d74a 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -29,15 +29,6 @@ if {[build_executable $testfile.exp $testfile $srcfile] == -1} { return -1 } -set startup_with_shell_modes { "on" } -if {![gdb_protocol_is_remote]} { - lappend startup_with_shell_modes "off" -} else { - # Some of these tests will not work when using the remote protocol - # due to bug PR gdb/28392. - unsupported "gdbserver 'startup-with-shell off' broken PR gdb/28392" -} - # NAME is the name to use for the tests and ARGLIST is the list of # arguments that are passed to GDB when it is started. # @@ -55,7 +46,7 @@ proc args_test { name arglist {re_list {}} } { set re_list $arglist } - foreach_with_prefix startup_with_shell $::startup_with_shell_modes { + foreach_with_prefix startup_with_shell { on off } { save_vars { ::GDBFLAGS } { set ::GDBFLAGS "$::GDBFLAGS --args $::binfile $arglist" diff --git a/gdb/testsuite/gdb.base/inferior-args.exp b/gdb/testsuite/gdb.base/inferior-args.exp index 79b73e6..a1977db 100644 --- a/gdb/testsuite/gdb.base/inferior-args.exp +++ b/gdb/testsuite/gdb.base/inferior-args.exp @@ -174,22 +174,48 @@ set bs "\\\\" lappend item [list "$hex \"$bs\"\"" "$hex \"$bs$bs$bs\"\""] lappend test_desc_list $item -set startup_with_shell_modes { "on" } -if {![gdb_protocol_is_remote]} { - lappend startup_with_shell_modes "off" -} else { - # Due to PR gdb/28392 gdbserver doesn't currently support having - # startup-with-shell off, and then attempting to pass arguments - # containing whitespace. - unsupported "bug gdb/28392: gdbserver doesn't support this" -} - +# test three +# ---------- +# +# This test focuses on sending special shell characters within a +# double quote argument, and each special character is prefixed with a +# backslash. +# +# In a POSIX shell, within a double quoted argument, only $ (dollar), +# ` (backtick), " (double quote), \ (backslash), and newline can be +# escaped. All other backslash characters are literal backslashes. +# +# As with the previous test, the double quotes are lost when the +# arguments are sent through gdbserver_start, as such, this test isn't +# going to work when using the native-gdbserver board, hence we set +# the second arguemnt to 'false'. +lappend test_desc_list [list "test three" \ + false \ + { "\&" "\<" "\#" "\^" "\>" "\$" "\`" } \ + [list "$hex \"\\\\\\\\&\"" \ + "$hex \"\\\\\\\\<\"" \ + "$hex \"\\\\\\\\#\"" \ + "$hex \"\\\\\\\\\\^\"" \ + "$hex \"\\\\\\\\>\"" \ + "$hex \"\\\$\"" \ + "$hex \"`\""]] + +# test four +# --------- +# +# This test passes two arguments, a single and double quote, each +# escaped with a backslash. +lappend test_desc_list [list "test four" \ + true \ + { \' \" } \ + [list "$hex \"'\"" \ + "$hex \"\\\\\"\""]] foreach desc $test_desc_list { lassign $desc name stub_suitable args re_list with_test_prefix $name { foreach_with_prefix set_method { "start" "starti" "run" "set args" } { - foreach_with_prefix startup_with_shell $startup_with_shell_modes { + foreach_with_prefix startup_with_shell { on off } { do_test $set_method $startup_with_shell $args $re_list \ $stub_suitable } diff --git a/gdb/testsuite/gdb.base/startup-with-shell.exp b/gdb/testsuite/gdb.base/startup-with-shell.exp index 495c43e..e27f17a 100644 --- a/gdb/testsuite/gdb.base/startup-with-shell.exp +++ b/gdb/testsuite/gdb.base/startup-with-shell.exp @@ -59,12 +59,8 @@ proc initial_setup_simple { startup_with_shell run_args } { # If PROBLEMATIC_ON is true then when startup-with-shell is on we # expect the comparison to fail, so setup an xfail. # -# If PROBLEMATIC_OFF is true then when startup-with-shell is off we -# expect the comparison to fail, so setup an xfail. -# # TESTNAME is a string used in the test names. -proc run_test { args on_re off_re testname { problematic_on false } \ - { problematic_off false } } { +proc run_test { args on_re off_re testname { problematic_on false } } { foreach startup_with_shell { "on" "off" } { with_test_prefix "$testname, startup_with_shell: ${startup_with_shell}" { if {![initial_setup_simple $startup_with_shell $args]} { @@ -76,7 +72,7 @@ proc run_test { args on_re off_re testname { problematic_on false } \ set problematic $problematic_on } else { set re $off_re - set problematic $problematic_off + set problematic false } if { $problematic } { @@ -91,9 +87,8 @@ proc run_test { args on_re off_re testname { problematic_on false } \ # This is like the run_test proc except that RE is used as the # expected argument regexp when startup-with-shell is both on and off. # For the other arguments, see run_test. -proc run_test_same { args re testname { problematic_on false } \ - { problematic_off false } } { - run_test $args $re $re $testname $problematic_on $problematic_off +proc run_test_same { args re testname } { + run_test $args $re $re $testname } # The regexp to match a single '\' character. @@ -129,13 +124,11 @@ save_vars { env(TEST) } { run_test_same "\"\\a\"" \ "\"${bs}${bs}a\"" \ - "retain backslash in double quote arg" \ - false $is_remote_p + "retain backslash in double quote arg" run_test_same "'\\a'" \ "\"${bs}${bs}a\"" \ - "retain backslash in single quote arg" \ - false $is_remote_p + "retain backslash in single quote arg" run_test_same "\"\\\$\"" \ "\"\\\$\"" \ @@ -143,8 +136,7 @@ run_test_same "\"\\\$\"" \ run_test_same "'\\\$'" \ "\"${bs}${bs}\\\$\"" \ - "'\$' is not escaped in single quote arg" \ - false $is_remote_p + "'\$' is not escaped in single quote arg" run_test_same "\"\\`\"" \ "\"\\`\"" \ @@ -152,25 +144,20 @@ run_test_same "\"\\`\"" \ run_test_same "'\\`'" \ "\"${bs}${bs}`\"" \ - "'`' is not escaped in single quote arg" \ - false $is_remote_p + "'`' is not escaped in single quote arg" run_test_same "\"\\\"\"" \ "\"${bs}\"\"" \ - "'\"' can be escaped in double quote arg" \ - false $is_remote_p + "'\"' can be escaped in double quote arg" run_test_same "'\\\"'" \ "\"${bs}${bs}${bs}\"\"" \ - "'\"' is not escaped in single quote arg" \ - false $is_remote_p + "'\"' is not escaped in single quote arg" run_test_same "\"\\\\\"" \ "\"${bs}${bs}\"" \ - "'\\' can be escaped in double quote arg" \ - false $is_remote_p + "'\\' can be escaped in double quote arg" run_test_same "'\\\\'" \ "\"${bs}${bs}${bs}${bs}\"" \ - "'\\' is not escaped in single quote arg" \ - false $is_remote_p + "'\\' is not escaped in single quote arg" diff --git a/gdbsupport/common-inferior.cc b/gdbsupport/common-inferior.cc index 4211e04..8e35f41 100644 --- a/gdbsupport/common-inferior.cc +++ b/gdbsupport/common-inferior.cc @@ -31,92 +31,66 @@ construct_inferior_arguments (gdb::array_view<char * const> argv) { std::string result; - if (startup_with_shell) - { #ifdef __MINGW32__ - /* This holds all the characters considered special to the - Windows shells. */ - static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n"; - static const char quote = '"'; + /* This holds all the characters considered special to the + Windows shells. */ + static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n"; + static const char quote = '"'; #else - /* This holds all the characters considered special to the - typical Unix shells. We include `^' because the SunOS - /bin/sh treats it as a synonym for `|'. */ - static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n"; - static const char quote = '\''; + /* This holds all the characters considered special to the + typical Unix shells. We include `^' because the SunOS + /bin/sh treats it as a synonym for `|'. */ + static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n"; + static const char quote = '\''; #endif - for (int i = 0; i < argv.size (); ++i) + for (int i = 0; i < argv.size (); ++i) + { + if (i > 0) + result += ' '; + + /* Need to handle empty arguments specially. */ + if (argv[i][0] == '\0') { - if (i > 0) - result += ' '; + result += quote; + result += quote; + } + else + { +#ifdef __MINGW32__ + bool quoted = false; - /* Need to handle empty arguments specially. */ - if (argv[i][0] == '\0') + if (strpbrk (argv[i], special)) { - result += quote; + quoted = true; result += quote; } - else +#endif + for (char *cp = argv[i]; *cp != '\0'; ++cp) { -#ifdef __MINGW32__ - bool quoted = false; - - if (strpbrk (argv[i], special)) + if (*cp == '\n') { - quoted = true; + /* A newline cannot be quoted with a backslash (it + just disappears), only by putting it inside + quotes. */ + result += quote; + result += '\n'; result += quote; } -#endif - for (char *cp = argv[i]; *cp; ++cp) + else { - if (*cp == '\n') - { - /* A newline cannot be quoted with a backslash (it - just disappears), only by putting it inside - quotes. */ - result += quote; - result += '\n'; - result += quote; - } - else - { #ifdef __MINGW32__ - if (*cp == quote) + if (*cp == quote) #else - if (strchr (special, *cp) != NULL) + if (strchr (special, *cp) != NULL) #endif - result += '\\'; - result += *cp; - } + result += '\\'; + result += *cp; } + } #ifdef __MINGW32__ - if (quoted) - result += quote; + if (quoted) + result += quote; #endif - } - } - } - else - { - /* In this case we can't handle arguments that contain spaces, - tabs, or newlines -- see breakup_args(). */ - for (char *arg : argv) - { - char *cp = strchr (arg, ' '); - if (cp == NULL) - cp = strchr (arg, '\t'); - if (cp == NULL) - cp = strchr (arg, '\n'); - if (cp != NULL) - error (_("can't handle command-line " - "argument containing whitespace")); - } - - for (int i = 0; i < argv.size (); ++i) - { - if (i > 0) - result += " "; - result += argv[i]; } } |