Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA] Use TRY/CATCH in remove_prev_frame
Date: Fri, 25 May 2018 09:55:00 -0000	[thread overview]
Message-ID: <20180525033628.25677-1-tom@tromey.com> (raw)

This changes remove_prev_frame to use TRY/CATCH instead of a cleanup.
TRY/CATCH seemed appropriate here because the cleanup is only needed
in the case where an exception is thrown.

Tested by the buildbot.

ChangeLog
2018-05-24  Tom Tromey  <tom@tromey.com>

	* frame.c (remove_prev_frame): Remove.
	(get_prev_frame_if_no_cycle): Use TRY/CATCH.
---
 gdb/ChangeLog |  5 +++++
 gdb/frame.c   | 58 +++++++++++++++++++++++++---------------------------------
 2 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index 1d0eb72514..e55b4e1630 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1871,22 +1871,6 @@ frame_register_unwind_location (struct frame_info *this_frame, int regnum,
     }
 }
 
-/* Called during frame unwinding to remove a previous frame pointer from a
-   frame passed in ARG.  */
-
-static void
-remove_prev_frame (void *arg)
-{
-  struct frame_info *this_frame, *prev_frame;
-
-  this_frame = (struct frame_info *) arg;
-  prev_frame = this_frame->prev;
-  gdb_assert (prev_frame != NULL);
-
-  prev_frame->next = NULL;
-  this_frame->prev = NULL;
-}
-
 /* Get the previous raw frame, and check that it is not identical to
    same other frame frame already in the chain.  If it is, there is
    most likely a stack cycle, so we discard it, and mark THIS_FRAME as
@@ -1899,7 +1883,6 @@ static struct frame_info *
 get_prev_frame_if_no_cycle (struct frame_info *this_frame)
 {
   struct frame_info *prev_frame;
-  struct cleanup *prev_frame_cleanup;
 
   prev_frame = get_prev_frame_raw (this_frame);
 
@@ -1915,29 +1898,38 @@ get_prev_frame_if_no_cycle (struct frame_info *this_frame)
   if (prev_frame->level == 0)
     return prev_frame;
 
-  /* The cleanup will remove the previous frame that get_prev_frame_raw
-     linked onto THIS_FRAME.  */
-  prev_frame_cleanup = make_cleanup (remove_prev_frame, this_frame);
-
-  compute_frame_id (prev_frame);
-  if (!frame_stash_add (prev_frame))
+  TRY
     {
-      /* Another frame with the same id was already in the stash.  We just
-	 detected a cycle.  */
-      if (frame_debug)
+      compute_frame_id (prev_frame);
+      if (!frame_stash_add (prev_frame))
 	{
-	  fprintf_unfiltered (gdb_stdlog, "-> ");
-	  fprint_frame (gdb_stdlog, NULL);
-	  fprintf_unfiltered (gdb_stdlog, " // this frame has same ID }\n");
+	  /* Another frame with the same id was already in the stash.  We just
+	     detected a cycle.  */
+	  if (frame_debug)
+	    {
+	      fprintf_unfiltered (gdb_stdlog, "-> ");
+	      fprint_frame (gdb_stdlog, NULL);
+	      fprintf_unfiltered (gdb_stdlog, " // this frame has same ID }\n");
+	    }
+	  this_frame->stop_reason = UNWIND_SAME_ID;
+	  /* Unlink.  */
+	  prev_frame->next = NULL;
+	  this_frame->prev = NULL;
+	  prev_frame = NULL;
 	}
-      this_frame->stop_reason = UNWIND_SAME_ID;
-      /* Unlink.  */
+    }
+  CATCH (ex, RETURN_MASK_ERROR)
+    {
+      prev_frame = this_frame->prev;
+      gdb_assert (prev_frame != NULL);
+
       prev_frame->next = NULL;
       this_frame->prev = NULL;
-      prev_frame = NULL;
+
+      throw_exception (ex);
     }
+  END_CATCH
 
-  discard_cleanups (prev_frame_cleanup);
   return prev_frame;
 }
 
-- 
2.13.6


             reply	other threads:[~2018-05-25  3:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-25  9:55 Tom Tromey [this message]
2018-05-25 11:54 ` Pedro Alves
2018-05-25 15:04   ` Tom Tromey
2018-05-25 16:28     ` Pedro Alves
2018-05-25 16:28       ` 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=20180525033628.25677-1-tom@tromey.com \
    --to=tom@tromey.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