public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/remote: fix qRcmd error handling
@ 2024-04-29  9:01 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2024-04-29  9:01 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c541d53765bdea821b06b929ed5d13d00dc42f22

commit c541d53765bdea821b06b929ed5d13d00dc42f22
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Apr 22 09:33:06 2024 +0100

    gdb/remote: fix qRcmd error handling
    
    This commit:
    
      commit 3623271997a5c0d79609aa6a1f35ef61b4469054
      Date:   Tue Jan 30 15:55:47 2024 +0100
    
          remote.c: Use packet_check_result
    
    Introduced a bug in the error handling of the qRcmd packet.  Prior to
    this commit if a packet had status PACKET_OK then, if the packet
    contained the text "OK" we considered the packet handled.  But, if the
    packet contained any other content (that was not an error message)
    then the content was printed to the user.
    
    After the above commit this was no longer the case, any non-error
    packet that didn't contain "OK" would be treated as an error.
    
    Currently, gdbserver doesn't exercise this path so it's not possible
    to write a simple test for this case.  When gdbserver wishes to print
    output it sends back an 'O' string output packet, these packets are
    handled earlier in the process.  Then once gdbserver has finished
    sending output an 'OK' packet is sent.
    
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/remote.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index d425e558422..55069559a60 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -11997,18 +11997,23 @@ remote_target::rcmd (const char *command, struct ui_file *outbuf)
 	  continue;
 	}
       packet_result result = packet_check_result (buf, false);
-      if (strcmp (buf, "OK") == 0)
-	break;
-      else if (result.status () == PACKET_UNKNOWN)
-	error (_("Target does not support this command."));
-      else
-	error (_("Protocol error with Rcmd: %s."), result.err_msg ());
-
-      for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
+      switch (result.status ())
 	{
-	  char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
+	case PACKET_UNKNOWN:
+	  error (_("Target does not support this command."));
+	case PACKET_ERROR:
+	  error (_("Protocol error with Rcmd: %s."), result.err_msg ());
+	case PACKET_OK:
+	  break;
+	}
 
-	  gdb_putc (c, outbuf);
+      if (strcmp (buf, "OK") != 0)
+	{
+	  for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
+	    {
+	      char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
+	      gdb_putc (c, outbuf);
+	    }
 	}
       break;
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-29  9:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29  9:01 [binutils-gdb] gdb/remote: fix qRcmd error handling Andrew Burgess

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).