From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 06B983857703; Thu, 25 May 2023 18:59:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06B983857703 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685041190; bh=M10h54t5hewnSfUHXaMkecR+tOKkKHYaLkrlBSYYcx4=; h=From:To:Subject:Date:From; b=yEzCYdhgcGV9A7u3d6qaf9njrSgQXYsEeMTzEUoYNx9FKYXxCHCRbjBRTWBk/zKvd PL/inB0s5XQ8XRSsl3X/riTL6pRIsB6rM57opN35jOhZXk0e7g1Mnd+6DqxSAP/tqP 9IIUuU2mvzIKknMkICI1TudMVgFrkMrNmmMedS4s= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix scoped_value_mark not working with empty value chain X-Act-Checkin: binutils-gdb X-Git-Author: Ciaran Woodward X-Git-Refname: refs/heads/master X-Git-Oldrev: a1decfc1df541de75e7506cb6ac7fbdd8648fbf6 X-Git-Newrev: 3422b26537123bb63240996feea4aeb1a317e507 Message-Id: <20230525185950.06B983857703@sourceware.org> Date: Thu, 25 May 2023 18:59:50 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3422b2653712= 3bb63240996feea4aeb1a317e507 commit 3422b26537123bb63240996feea4aeb1a317e507 Author: Ciaran Woodward Date: Thu May 25 11:14:15 2023 +0000 Fix scoped_value_mark not working with empty value chain =20 The scoped_value_mark helper class was setting its internal mark value to NULL to indicate that the value chain had already been freed to mark. =20 However, value_mark() also returns NULL if the value chain is empty at the time of call. =20 This lead to the situation that if the value chain was empty at the time the scoped_value_mark was created, the class would not correctly clean up the state when it was destroyed, because it believed it had already been freed. =20 I noticed this because I was setting a watchpoint very early in my debug session, and it was becoming a software watchpoint rather than hardware. Running any command that called evaluate() beforehand (such as 'x 0') would mean that a hardware watchpoint was correctly used. After some careful examination of the differences in execution, I noticed that values were being freed later in the 'bad case', which lead me to notice the issue with scoped_value_mark. Diff: --- gdb/value.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/value.h b/gdb/value.h index a9c77a033ab..508367a4159 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1170,16 +1170,17 @@ class scoped_value_mark /* Free the values currently on the value stack. */ void free_to_mark () { - if (m_value !=3D NULL) + if (!m_freed) { value_free_to_mark (m_value); - m_value =3D NULL; + m_freed =3D true; } } =20 private: =20 const struct value *m_value; + bool m_freed =3D false; }; =20 extern struct value *value_cstring (const char *ptr, ssize_t len,