aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCiaran Woodward <ciaranwoodward@xmos.com>2023-05-25 11:14:15 +0000
committerTom Tromey <tromey@adacore.com>2023-05-25 12:47:03 -0600
commit3422b26537123bb63240996feea4aeb1a317e507 (patch)
treeec1be1f923bfd3cfbae1bb156b82bbef6b07a02b
parenta1decfc1df541de75e7506cb6ac7fbdd8648fbf6 (diff)
downloadgdb-3422b26537123bb63240996feea4aeb1a317e507.zip
gdb-3422b26537123bb63240996feea4aeb1a317e507.tar.gz
gdb-3422b26537123bb63240996feea4aeb1a317e507.tar.bz2
Fix scoped_value_mark not working with empty value chain
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.
-rw-r--r--gdb/value.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/gdb/value.h b/gdb/value.h
index a9c77a0..508367a 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;
+ m_freed = true;
}
}
private:
const struct value *m_value;
+ bool m_freed = false;
};
extern struct value *value_cstring (const char *ptr, ssize_t len,