public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] Fix scoped_value_mark not working with empty value chain
@ 2023-05-25 11:14 Ciaran Woodward
  2023-05-25 18:59 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Ciaran Woodward @ 2023-05-25 11:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Ciaran Woodward, tom


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.

However, value_mark() also returns NULL if the value chain is
empty at the time of call.

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.

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.
---
 gdb/value.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gdb/value.h b/gdb/value.h
index a9c77a033ab..fe05ed1d4dd 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 != NULL)
+    if (!m_freed)
       {
-       value_free_to_mark (m_value);
-       m_value = NULL;
+        value_free_to_mark (m_value);
+        m_freed = true;
       }
   }

  private:

   const struct value *m_value;
+  bool m_freed = false;
 };

 extern struct value *value_cstring (const char *ptr, ssize_t len,
--
2.25.1

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

* Re: [PATCH v2] Fix scoped_value_mark not working with empty value chain
  2023-05-25 11:14 [PATCH v2] Fix scoped_value_mark not working with empty value chain Ciaran Woodward
@ 2023-05-25 18:59 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-05-25 18:59 UTC (permalink / raw)
  To: Ciaran Woodward; +Cc: gdb-patches, tom

>>>>> "Ciaran" == Ciaran Woodward <ciaranwoodward@xmos.com> writes:

Ciaran> The scoped_value_mark helper class was setting its internal
Ciaran> mark value to NULL to indicate that the value chain had already
Ciaran> been freed to mark.

...

Thanks.  I'm checking this in.

Tom

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

end of thread, other threads:[~2023-05-25 18:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25 11:14 [PATCH v2] Fix scoped_value_mark not working with empty value chain Ciaran Woodward
2023-05-25 18:59 ` Tom Tromey

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