public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>, Andreas Schwab <schwab@suse.de>
Subject: [PATCHv2 3/5] gdbserver: handle newlines in inferior arguments
Date: Wed, 27 Sep 2023 18:27:56 +0100	[thread overview]
Message-ID: <8c64b64c6ff1e2567d25ffcc39217a61e856e873.1695835626.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1695835626.git.aburgess@redhat.com>

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.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27989
---
 gdb/testsuite/gdb.base/args.exp | 20 +++++---------------
 gdbserver/server.cc             | 17 -----------------
 2 files changed, 5 insertions(+), 32 deletions(-)

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';
-- 
2.25.4


  parent reply	other threads:[~2023-09-27 17:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27 12:21 [PATCH] gdbserver: fix handling of single quote arguments Andrew Burgess
2023-09-27 13:01 ` Andreas Schwab
2023-09-27 17:27 ` [PATCHv2 0/5] Fixes for passing arguments to gdbserver Andrew Burgess
2023-09-27 17:27   ` [PATCHv2 1/5] gdbserver: fix handling of single quote arguments Andrew Burgess
2023-09-27 17:27   ` [PATCHv2 2/5] gdbserver: fix handling of trailing empty argument Andrew Burgess
2023-09-27 17:27   ` Andrew Burgess [this message]
2023-09-27 17:27   ` [PATCHv2 4/5] gdbserver: cleanup in handle_v_run Andrew Burgess
2023-10-03 19:13     ` Tom Tromey
2023-10-04 14:40       ` Andrew Burgess
2023-10-04 19:35         ` Tom Tromey
2023-09-27 17:27   ` [PATCHv2 5/5] gdb/testsuite: cleanup in gdb.base/args.exp Andrew Burgess
2023-10-05 16:17     ` Tom Tromey
2023-10-05 16:18   ` [PATCHv2 0/5] Fixes for passing arguments to gdbserver Tom Tromey
2023-10-06 12:15     ` Andrew Burgess
2023-10-06 12:56       ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c64b64c6ff1e2567d25ffcc39217a61e856e873.1695835626.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).