Use scoped_value_mark in two more places

I found a couple of spots that could use scoped_value_mark.  One of
them is a spot that didn't consider the possibility that value_mark
can return NULL.  I tend to doubt this can be seen in this context,
but nevertheless this is safer.

Regression tested on x86-64 Fedora 36.
This commit is contained in:
Tom Tromey
2023-05-24 13:59:58 -06:00
parent 30711c89cc
commit 8945920275
2 changed files with 10 additions and 13 deletions

View File

@@ -271,8 +271,8 @@ public:
{ {
if (inner_p) if (inner_p)
{ {
gdb_assert (m_mark == nullptr); gdb_assert (!m_mark.has_value ());
m_mark = value_mark (); m_mark.emplace ();
} }
} }
@@ -282,9 +282,8 @@ public:
{ {
if (inner_p) if (inner_p)
{ {
gdb_assert (m_mark != nullptr); gdb_assert (m_mark.has_value ());
value_free_to_mark (m_mark); m_mark.reset ();
m_mark = nullptr;
} }
} }
@@ -305,9 +304,9 @@ protected:
written. */ written. */
LONGEST m_dest_offset; LONGEST m_dest_offset;
/* Set with a call to VALUE_MARK, and then reset after calling /* Set and reset to handle removing intermediate values from the
VALUE_FREE_TO_MARK. */ value chain. */
struct value *m_mark = nullptr; gdb::optional<scoped_value_mark> m_mark;
}; };
/* A class used by FORTRAN_VALUE_SUBARRAY when repacking Fortran array /* A class used by FORTRAN_VALUE_SUBARRAY when repacking Fortran array

View File

@@ -3879,7 +3879,9 @@ value::fetch_lazy_register ()
frame_info_ptr next_frame; frame_info_ptr next_frame;
int regnum; int regnum;
struct type *type = check_typedef (this->type ()); struct type *type = check_typedef (this->type ());
struct value *new_val = this, *mark = value_mark (); struct value *new_val = this;
scoped_value_mark mark;
/* Offsets are not supported here; lazy register values must /* Offsets are not supported here; lazy register values must
refer to the entire register. */ refer to the entire register. */
@@ -3983,10 +3985,6 @@ value::fetch_lazy_register ()
frame_debug_printf ("%s", debug_file.c_str ()); frame_debug_printf ("%s", debug_file.c_str ());
} }
/* Dispose of the intermediate values. This prevents
watchpoints from trying to watch the saved frame pointer. */
value_free_to_mark (mark);
} }
/* See value.h. */ /* See value.h. */