public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [ob/pushed] gdbserver: Fix incorrect assertion
@ 2022-03-21 16:48 Pedro Alves
  2022-03-21 17:04 ` [pushed] gdbserver: Fixup previous patch Pedro Alves
  0 siblings, 1 reply; 2+ messages in thread
From: Pedro Alves @ 2022-03-21 16:48 UTC (permalink / raw)
  To: gdb-patches

While playing with adding a new event kind, I noticed that
prepare_resume_reply TARGET_WAITKIND_FORKED, etc. advance 'buf', so if
we force-disable the T packet, we'd fail the *buf == 'T' assertion.

Fix it by tweaking the assertion to always look at the beginning of
the buffer.

Change-Id: I8c38e32353db115edcde418b3b1e8ba12343c22b
---
 gdbserver/remote-utils.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 3004130fb25..0599cc9c4f1 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1070,6 +1070,7 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
       {
 	const char **regp;
 	struct regcache *regcache;
+	char *buf_start = buf;
 
 	if ((status.kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events)
 	    || (status.kind () == TARGET_WAITKIND_VFORKED
@@ -1140,11 +1141,11 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
 	       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)));
+	    gdb_assert (buf_start[0] == 'T');
+	    gdb_assert (isxdigit (buf_start[1]));
+	    gdb_assert (isxdigit (buf_start[2]));
 	    *buf = 'S';
-	    *(buf + 3) = '\0';
+	    buf_start[3] = '\0';
 	    break;
 	  }
 

base-commit: f55649cc9bcb92405d49af6bdcde6e69ac4d1c49
-- 
2.26.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pushed] gdbserver: Fixup previous patch
  2022-03-21 16:48 [ob/pushed] gdbserver: Fix incorrect assertion Pedro Alves
@ 2022-03-21 17:04 ` Pedro Alves
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2022-03-21 17:04 UTC (permalink / raw)
  To: gdb-patches

On 2022-03-21 16:48, Pedro Alves wrote:

> @@ -1140,11 +1141,11 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
>  	       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)));
> +	    gdb_assert (buf_start[0] == 'T');
> +	    gdb_assert (isxdigit (buf_start[1]));
> +	    gdb_assert (isxdigit (buf_start[2]));
>  	    *buf = 'S';
> -	    *(buf + 3) = '\0';
> +	    buf_start[3] = '\0';
>  	    break;
>  	  }
>  

Whoops, the '*buf = 'S';' line is also incorrect, of course.  Fixed by this follow up patch.
Pushed to master.

From 4414150d33212f5f395c3bf8a940bccf80ffc508 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Mon, 21 Mar 2022 16:58:23 +0000
Subject: [PATCH] gdbserver: Fixup previous patch

The previous prepare_resume_reply change missed updating the 'buf'
reference that overwrites the 'T', so if 'buf' was advanced, we'd
still overwrite the wrong character.  This fixes it.

Change-Id: Ia8ce433366b85af4e268c1c49e7b447da3130a4d
---
 gdbserver/remote-utils.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 0599cc9c4f1..db9b2a66f3c 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1144,7 +1144,7 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
 	    gdb_assert (buf_start[0] == 'T');
 	    gdb_assert (isxdigit (buf_start[1]));
 	    gdb_assert (isxdigit (buf_start[2]));
-	    *buf = 'S';
+	    buf_start[0] = 'S';
 	    buf_start[3] = '\0';
 	    break;
 	  }

base-commit: 04f0c03a22135c7eefa47ed99c03e5b3dc9a34e2
-- 
2.26.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-21 17:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 16:48 [ob/pushed] gdbserver: Fix incorrect assertion Pedro Alves
2022-03-21 17:04 ` [pushed] gdbserver: Fixup previous patch Pedro Alves

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