public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdbserver: Add mechanism to prevent sending T stop packets
@ 2020-03-02 15:07 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2020-03-02 15:07 UTC (permalink / raw)
  To: gdb-cvs

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

commit 442131c1bec1a2ff0b3a5e5d1d91a116ce869dee
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Fri Feb 28 21:33:26 2020 +0000

    gdbserver: Add mechanism to prevent sending T stop packets
    
    There is a developer only feature in gdbserver that provides a
    command line option --disable-packet that prevents some packets from
    being sent, which is used to increase test coverage within GDB.
    
    This commit extends this mechanism to prevent GDBserver from sending
    the T stop reply packets, instead limiting GDBserver to only send the
    S stop reply packets.
    
    The S stop reply packet is part of the older target control mechanism,
    which has design flaws that were worked around with the introduction
    of the newer target control mechanism, which uses the T stop reply
    packet.
    
    Limiting GDBserver to use S stop packets instead of T stop packets
    will, inevitably, mean that GDBserver doesn't function correctly in
    many cases involving multiple threads, however, I don't think this is
    too important, this is a developer only feature, intended to allow us
    to test GDB.
    
    A new test that makes use of this feature will be added in the next
    commit.
    
    gdbserver/ChangeLog:
    
    	* remote-utils.cc (prepare_resume_reply): Add ability to convert T
    	reply into an S reply.
    	* server.cc (disable_packet_T): New global.
    	(captured_main): Set new global when appropriate.
    	* server.h (disable_packet_T): Declare.

Diff:
---
 gdbserver/ChangeLog       |  8 ++++++++
 gdbserver/remote-utils.cc | 20 ++++++++++++++++++++
 gdbserver/server.cc       |  3 +++
 gdbserver/server.h        |  1 +
 4 files changed, 32 insertions(+)

diff --git a/gdbserver/ChangeLog b/gdbserver/ChangeLog
index dc8964b..7a5a3b7 100644
--- a/gdbserver/ChangeLog
+++ b/gdbserver/ChangeLog
@@ -1,3 +1,11 @@
+2020-03-02  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* remote-utils.cc (prepare_resume_reply): Add ability to convert T
+	reply into an S reply.
+	* server.cc (disable_packet_T): New global.
+	(captured_main): Set new global when appropriate.
+	* server.h (disable_packet_T): Declare.
+
 2020-02-21  Tom Tromey  <tom@tromey.com>
 
 	* Makefile.in (mostlyclean): New target.
diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 6b54749..1c211e2 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1204,6 +1204,26 @@ prepare_resume_reply (char *buf, ptid_t ptid,
 	else
 	  sprintf (buf, "T%02x", status->value.sig);
 
+	if (disable_packet_T)
+	  {
+	    /* This is a bit (OK, a lot) of a kludge, however, this isn't
+	       really a user feature, but exists only so GDB can use the
+	       gdbserver to test handling of the 'S' stop reply packet, so
+	       we would rather this code be as simple as possible.
+
+	       By this point we've started to build the 'T' stop packet,
+	       and it should look like 'Txx....' where 'x' is a hex digit.
+	       An 'S' stop packet always looks like 'Sxx', so all we do
+	       here is convert the buffer from a T packet to an S packet
+	       and the avoid adding any extra content by breaking out.  */
+	    gdb_assert (*buf == 'T');
+	    gdb_assert (isxdigit (*(buf + 1)));
+	    gdb_assert (isxdigit (*(buf + 2)));
+	    *buf = 'S';
+	    *(buf + 3) = '\0';
+	    break;
+	  }
+
 	buf += strlen (buf);
 
 	saved_thread = current_thread;
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index a4cb1eb..43962ad 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -130,6 +130,7 @@ bool disable_packet_vCont;
 bool disable_packet_Tthread;
 bool disable_packet_qC;
 bool disable_packet_qfThreadInfo;
+bool disable_packet_T;
 
 static unsigned char *mem_buf;
 
@@ -3649,6 +3650,8 @@ captured_main (int argc, char *argv[])
 		disable_packet_qC = true;
 	      else if (strcmp ("qfThreadInfo", tok) == 0)
 		disable_packet_qfThreadInfo = true;
+	      else if (strcmp ("T", tok) == 0)
+		disable_packet_T = true;
 	      else if (strcmp ("threads", tok) == 0)
 		{
 		  disable_packet_vCont = true;
diff --git a/gdbserver/server.h b/gdbserver/server.h
index 3c28686..5ef48b6 100644
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -76,6 +76,7 @@ extern bool disable_packet_vCont;
 extern bool disable_packet_Tthread;
 extern bool disable_packet_qC;
 extern bool disable_packet_qfThreadInfo;
+extern bool disable_packet_T;
 
 extern bool run_once;
 extern bool non_stop;


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

only message in thread, other threads:[~2020-03-02 15:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-02 15:07 [binutils-gdb] gdbserver: Add mechanism to prevent sending T stop packets 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).