From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 1E36E3857404; Mon, 21 Mar 2022 16:48:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E36E3857404 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbserver: Fix incorrect assertion X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: f55649cc9bcb92405d49af6bdcde6e69ac4d1c49 X-Git-Newrev: 04f0c03a22135c7eefa47ed99c03e5b3dc9a34e2 Message-Id: <20220321164833.1E36E3857404@sourceware.org> Date: Mon, 21 Mar 2022 16:48:33 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Mar 2022 16:48:33 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D04f0c03a2213= 5c7eefa47ed99c03e5b3dc9a34e2 commit 04f0c03a22135c7eefa47ed99c03e5b3dc9a34e2 Author: Pedro Alves Date: Thu Nov 25 19:07:36 2021 +0000 gdbserver: Fix incorrect assertion =20 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 =3D=3D 'T' assertion. =20 Fix it by tweaking the assertion to always look at the beginning of the buffer. =20 Change-Id: I8c38e32353db115edcde418b3b1e8ba12343c22b Diff: --- 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 t= arget_waitstatus &status) { const char **regp; struct regcache *regcache; + char *buf_start =3D buf; =20 if ((status.kind () =3D=3D TARGET_WAITKIND_FORKED && cs.report_fork_event= s) || (status.kind () =3D=3D 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 =3D=3D 'T'); - gdb_assert (isxdigit (*(buf + 1))); - gdb_assert (isxdigit (*(buf + 2))); + gdb_assert (buf_start[0] =3D=3D 'T'); + gdb_assert (isxdigit (buf_start[1])); + gdb_assert (isxdigit (buf_start[2])); *buf =3D 'S'; - *(buf + 3) =3D '\0'; + buf_start[3] =3D '\0'; break; }