From: Andrew Burgess Date: Wed, 27 Sep 2023 16:54:15 +0000 (+0100) Subject: gdbserver: handle newlines in inferior arguments X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=67e6945b7e3a5c1577d19b9d83ee9be86c0a8424;p=binutils-gdb.git gdbserver: handle newlines in inferior arguments Similarly to how single quotes were mishandled, which was fixed two commits ago, this commit fixes handling of newlines in arguments passed to gdbserver. We already had a test that covered this, gdb.base/args.exp, which, when run with the native-extended-gdbserver board contained several KFAIL covering this situation. In this commit I remove the unnecessary, attempt to quote incoming newlines within arguments, and do some minimal cleanup of the related code. There is additional cleanup that can be done, but I'm leaving that for the next commit. Then I've removed the KFAIL from the test case, and performed some minimal cleanup there too. After this commit the gdb.base/args.exp is 100% passing with the native-extended-gdbserver board file. During review I was pointed to this older series: https://inbox.sourceware.org/gdb-patches/20211022071933.3478427-1-m.weghorn@posteo.de/ which also includes this fix as part of a larger set of changes. I'm giving a Co-Authored-By credit to the author of that original series. I believe this smaller fix brings some benefits on its own, though the original series does offer additional improvements. Once this is merged I'll take a look at rebasing and resubmitting the original series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 Co-Authored-By: Michael Weghorn Approved-By: Tom Tromey --- diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 092b44bd61d..0e2dc8b1399 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -30,10 +30,10 @@ if {[build_executable $testfile.exp $testfile \ return -1 } -# If SINGLE_QUOTES_NEWLINE_KFAIL true, arguments made of exactly '' or a -# newline character will fail, so kfail those tests. +# NAME is the name to use for the tests and ARGLIST is the list of +# expected arguments. -proc args_test { name arglist {single_quotes_newline_kfail false}} { +proc args_test { name arglist } { global srcdir global subdir global testfile @@ -51,10 +51,6 @@ proc args_test { name arglist {single_quotes_newline_kfail false}} { set i 1 foreach arg $arglist { - if { $single_quotes_newline_kfail - && ($arg == {''} || $arg == {\\n}) } { - setup_kfail "gdb/27989" "*-*-*" - } gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ "argv\[$i\] for $name" set i [expr $i + 1] @@ -68,12 +64,6 @@ proc args_test { name arglist {single_quotes_newline_kfail false}} { save_vars { GDBFLAGS } { set old_gdbflags $GDBFLAGS - # Single quotes and newlines are not well handled by the extended-remote - # target: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 - set single_quotes_newline_kfail \ - [expr { [target_info exists gdb_protocol] \ - && [target_info gdb_protocol] == "extended-remote" }] - set GDBFLAGS "$old_gdbflags --args $binfile 1 3" args_test basic {{1} {3}} @@ -102,8 +92,8 @@ save_vars { GDBFLAGS } { # try with arguments containing literal newlines. set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} 3" - args_test "one newline" {{1} {\\n} {3}} $single_quotes_newline_kfail + args_test "one newline" {{1} {\\n} {3}} set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} {\n} 3" - args_test "two newlines" {{1} {\\n} {\\n} {3}} $single_quotes_newline_kfail + args_test "two newlines" {{1} {\\n} {\\n} {3}} } diff --git a/gdbserver/server.cc b/gdbserver/server.cc index d78eb5a7d94..84b8712e668 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2997,34 +2997,17 @@ handle_v_run (char *own_buf) /* These are pointers used to navigate the strings above. */ char *tmp_arg = arg; char *tmp_full_arg = full_arg; - int need_quote = 0; hex2bin (p, (gdb_byte *) arg, len); arg[len] = '\0'; while (*tmp_arg != '\0') { - switch (*tmp_arg) - { - case '\n': - /* Quote \n. */ - *tmp_full_arg = '\''; - ++tmp_full_arg; - need_quote = 1; - break; - - default: - break; - } - *tmp_full_arg = *tmp_arg; ++tmp_full_arg; ++tmp_arg; } - if (need_quote) - *tmp_full_arg++ = '\''; - /* Finish FULL_ARG and push it into the vector containing the argv. */ *tmp_full_arg = '\0';