]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: Fix incorrect assertion
authorPedro Alves <pedro@palves.net>
Thu, 25 Nov 2021 19:07:36 +0000 (19:07 +0000)
committerPedro Alves <pedro@palves.net>
Mon, 21 Mar 2022 16:45:49 +0000 (16:45 +0000)
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

index 3004130fb25b9435707956419375370f424fccc1..0599cc9c4f1a11cf4ea646b679b140e5dd943bc7 100644 (file)
@@ -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;
          }