public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Use scoped_value_mark in two more places
Date: Thu, 25 May 2023 06:57:37 -0600	[thread overview]
Message-ID: <20230525125737.1849340-1-tromey@adacore.com> (raw)

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.
---
 gdb/f-lang.c | 15 +++++++--------
 gdb/value.c  |  8 +++-----
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 365e0c0489b..9f579c5c990 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -261,8 +261,8 @@ class fortran_array_repacker_base_impl
   {
     if (inner_p)
       {
-	gdb_assert (m_mark == nullptr);
-	m_mark = value_mark ();
+	gdb_assert (!m_mark.has_value ());
+	m_mark.emplace ();
       }
   }
 
@@ -272,9 +272,8 @@ class fortran_array_repacker_base_impl
   {
     if (inner_p)
       {
-	gdb_assert (m_mark != nullptr);
-	value_free_to_mark (m_mark);
-	m_mark = nullptr;
+	gdb_assert (m_mark.has_value ());
+	m_mark.reset ();
       }
   }
 
@@ -295,9 +294,9 @@ class fortran_array_repacker_base_impl
      written.  */
   LONGEST m_dest_offset;
 
-  /* Set with a call to VALUE_MARK, and then reset after calling
-     VALUE_FREE_TO_MARK.  */
-  struct value *m_mark = nullptr;
+  /* Set and reset to handle removing intermediate values from the
+     value chain.  */
+  gdb::optional<scoped_value_mark> m_mark;
 };
 
 /* A class used by FORTRAN_VALUE_SUBARRAY when repacking Fortran array
diff --git a/gdb/value.c b/gdb/value.c
index 980722a6dd7..fb9466493b5 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3878,7 +3878,9 @@ value::fetch_lazy_register ()
   frame_info_ptr next_frame;
   int regnum;
   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
      refer to the entire register.  */
@@ -3982,10 +3984,6 @@ value::fetch_lazy_register ()
 
       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.  */
-- 
2.40.0


             reply	other threads:[~2023-05-25 12:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 12:57 Tom Tromey [this message]
2023-06-09 13:42 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230525125737.1849340-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).