+2016-06-01  Markus Metzger  <markus.t.metzger@intel.com>
+
+       * infcmd.c (skip_finish_frames): New.
+       (finish_command): Call skip_finish_frames.
+
 2016-06-01  Yao Qi  <yao.qi@linaro.org>
 
        PR remote/19998
 
   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
 }
 
+/* Skip frames for "finish".  */
+
+static struct frame_info *
+skip_finish_frames (struct frame_info *frame)
+{
+  struct frame_info *start;
+
+  do
+    {
+      start = frame;
+
+      frame = skip_tailcall_frames (frame);
+      if (frame == NULL)
+       break;
+
+      frame = skip_unwritable_frames (frame);
+      if (frame == NULL)
+       break;
+    }
+  while (start != frame);
+
+  return frame;
+}
+
 /* "finish": Set a temporary breakpoint at the place the selected
    frame will return to, then continue.  */
 
     finish_backward (sm);
   else
     {
-      /* Ignore TAILCALL_FRAME type frames, they were executed already before
-        entering THISFRAME.  */
-      frame = skip_tailcall_frames (frame);
-
-      frame = skip_unwritable_frames (frame);
+      frame = skip_finish_frames (frame);
 
       if (frame == NULL)
        error (_("Cannot find the caller frame."));