+static struct frame_info *
+get_prev_frame_if_no_cycle (struct frame_info *this_frame)
+{
+ struct frame_info *prev_frame;
+
+ prev_frame = get_prev_frame_raw (this_frame);
+
+ /* Don't compute the frame id of the current frame yet. Unwinding
+ the sentinel frame can fail (e.g., if the thread is gone and we
+ can't thus read its registers). If we let the cycle detection
+ code below try to compute a frame ID, then an error thrown from
+ within the frame ID computation would result in the sentinel
+ frame as outermost frame, which is bogus. Instead, we'll compute
+ the current frame's ID lazily in get_frame_id. Note that there's
+ no point in doing cycle detection when there's only one frame, so
+ nothing is lost here. */
+ if (prev_frame->level == 0)
+ return prev_frame;
+
+ TRY
+ {
+ compute_frame_id (prev_frame);
+ if (!frame_stash_add (prev_frame))
+ {
+ /* 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;
+ }
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ prev_frame->next = NULL;
+ this_frame->prev = NULL;
+
+ throw_exception (ex);
+ }
+ END_CATCH
+
+ return prev_frame;
+}
+
+/* Helper function for get_prev_frame_always, this is called inside a
+ TRY_CATCH block. Return the frame that called THIS_FRAME or NULL if
+ there is no such frame. This may throw an exception. */