This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix remote 'g' command error handling (PR remote/9665)


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

commit b75abf5bb636869fd893ecf98414b8b2fe0d4a12
Author: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Date:   Thu Apr 26 23:47:25 2018 +0100

    Fix remote 'g' command error handling (PR remote/9665)
    
    'g' command returns hex-string as response so simply checking for 'E'
    to determine if it failed is not enough and can trigger spurious error
    messages.  For example, invalid behaviour can be easily triggered on
    Cortex-M as follows:
    
      (gdb) set $r0 = 0xe0
      Sending packet: $P0=e0000000#72...Packet received: OK
      Packet P (set-register) is supported
      Sending packet: $g#67...Packet received: E0000000849A0020...
      Remote failure reply: E0000000849A0020...
    
    This patch fixes the problem by calling putpkt()/getpkt() directly and
    checking result with packet_check_result().  This works fine since Enn
    response has odd number of bytes while proper response has even number
    of bytes.
    
    Also, remote_send() is now not used anywhere so it can be removed.
    
    gdb/Changelog:
    2018-04-26  Andrzej Kaczmarek  <andrzej.kaczmarek@codecoup.pl>
    
    	PR remote/9665
    	* remote.c (send_g_packet): Use putpkt/getpkt/packet_check_result
    	instead of remote_send.
    	(remote_send): Remove.

Diff:
---
 gdb/ChangeLog |  7 +++++++
 gdb/remote.c  | 24 +++++-------------------
 2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6164fc3..cd86be7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2018-04-26  Andrzej Kaczmarek  <andrzej.kaczmarek@codecoup.pl>
+
+	PR remote/9665
+	* remote.c (send_g_packet): Use putpkt/getpkt/packet_check_result
+	instead of remote_send.
+	(remote_send): Remove.
+
 2018-04-26  Pedro Alves  <palves@redhat.com>
 
 	* elfread.c (elf_gnu_ifunc_resolver_return_stop): Use
diff --git a/gdb/remote.c b/gdb/remote.c
index 193037b..5920b82 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -122,8 +122,6 @@ static void remote_mourn (struct target_ops *ops);
 
 static void extended_remote_restart (void);
 
-static void remote_send (char **buf, long *sizeof_buf_p);
-
 static int readchar (int timeout);
 
 static void remote_serial_write (const char *str, int len);
@@ -7524,7 +7522,11 @@ send_g_packet (void)
   int buf_len;
 
   xsnprintf (rs->buf, get_remote_packet_size (), "g");
-  remote_send (&rs->buf, &rs->buf_size);
+  putpkt (rs->buf);
+  getpkt (&rs->buf, &rs->buf_size, 0);
+  if (packet_check_result (rs->buf) == PACKET_ERROR)
+    error (_("Could not read registers; remote failure reply '%s'"),
+           rs->buf);
 
   /* We can get out of synch in various cases.  If the first character
      in the buffer is not a hex character, assume that has happened
@@ -8600,22 +8602,6 @@ remote_serial_write (const char *str, int len)
     set_quit_flag ();
 }
 
-/* Send the command in *BUF to the remote machine, and read the reply
-   into *BUF.  Report an error if we get an error reply.  Resize
-   *BUF using xrealloc if necessary to hold the result, and update
-   *SIZEOF_BUF.  */
-
-static void
-remote_send (char **buf,
-	     long *sizeof_buf)
-{
-  putpkt (*buf);
-  getpkt (buf, sizeof_buf, 0);
-
-  if ((*buf)[0] == 'E')
-    error (_("Remote failure reply: %s"), *buf);
-}
-
 /* Return a string representing an escaped version of BUF, of len N.
    E.g. \n is converted to \\n, \t to \\t, etc.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]