proceed_to_finish.
	(save_infrun_state, load_infrun_state): Remove proceed_to_finish
	argument.
	* thread.c (load_infrun_state, save_infrun_state): Delete
	proceed_to_finish argument and references to it.
	* infcall.c (call_function_by_hand): Adjust.
	* infcmd.c (finish_command): Adjust.
	* infrun.c (proceed_to_finish): Delete.
	(clear_proceed_status): Adjust.
	(context_switch): Don't context-switch proceed_to_finish.
	(normal_stop, save_inferior_status, restore_inferior_status):
	Adjust.
+2008-09-08  Pedro Alves  <pedro@codesourcery.com>
+
+       * gdbthread.h (struct thread_info): Add comments around
+       proceed_to_finish.
+       (save_infrun_state, load_infrun_state): Remove proceed_to_finish
+       argument.
+       * thread.c (load_infrun_state, save_infrun_state): Delete
+       proceed_to_finish argument and references to it.
+
+       * infcall.c (call_function_by_hand): Adjust.
+       * infcmd.c (finish_command): Adjust.
+       * infrun.c (proceed_to_finish): Delete.
+       (clear_proceed_status): Adjust.
+       (context_switch): Don't context-switch proceed_to_finish.
+       (normal_stop, save_inferior_status, restore_inferior_status):
+       Adjust.
+
 2008-09-08  Pedro Alves  <pedro@codesourcery.com>
 
        * inferior.h (stop_bpstat): Delete.
 
   /* Per-thread command support.  */
   struct continuation *continuations;
   struct continuation *intermediate_continuations;
+
+  /* Nonzero if the thread is being proceeded for a "finish" command
+     or a similar situation when stop_registers should be saved.  */
   int proceed_to_finish;
+
   enum step_over_calls_kind step_over_calls;
   int stop_step;
   int step_multi;
 extern void save_infrun_state (ptid_t ptid,
                               struct continuation *continuations,
                               struct continuation *intermediate_continuations,
-                              int proceed_to_finish,
                               int stop_step,
                               int step_multi,
                               enum target_signal stop_signal);
 extern void load_infrun_state (ptid_t ptid,
                               struct continuation **continuations,
                               struct continuation **intermediate_continuations,
-                              int *proceed_to_finish,
                               int *stop_step,
                               int *step_multi,
                               enum target_signal *stop_signal);
 
     struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
     struct cleanup *old_cleanups2;
     int saved_async = 0;
+    struct thread_info *tp = inferior_thread ();
 
     /* If all error()s out of proceed ended up calling normal_stop
        (and perhaps they should; it already does in the special case
     make_cleanup (breakpoint_auto_delete_contents, NULL);
 
     disable_watchpoints_before_interactive_call_start ();
-    proceed_to_finish = 1;     /* We want stop_registers, please... */
+    tp->proceed_to_finish = 1; /* We want stop_registers, please... */
 
     if (target_can_async_p ())
       saved_async = target_async_mask (0);
 
   struct breakpoint *breakpoint;
   struct cleanup *old_chain;
   struct finish_command_continuation_args *cargs;
+  struct thread_info *tp;
 
   int async_exec = 0;
 
   if (frame == 0)
     error (_("\"finish\" not meaningful in the outermost frame."));
 
+  tp = inferior_thread ();
+
   clear_proceed_status ();
 
   sal = find_pc_line (get_frame_pc (frame), 0);
       print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
     }
 
-  proceed_to_finish = 1;       /* We want stop_registers, please...  */
+  tp->proceed_to_finish = 1;   /* We want stop_registers, please...  */
   make_cleanup_restore_integer (&suppress_stop_observer);
   suppress_stop_observer = 1;
   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
 
 
 enum stop_kind stop_soon;
 
-/* Nonzero if proceed is being used for a "finish" command or a similar
-   situation when stop_registers should be saved.  */
-
-int proceed_to_finish;
-
 /* Save register contents here when about to pop a stack dummy frame,
    if-and-only-if proceed_to_finish is set.
    Thus this contains the return value from the called function (assuming
       tp->step_range_end = 0;
       tp->step_frame_id = null_frame_id;
       tp->step_over_calls = STEP_OVER_UNDEBUGGABLE;
+
+      tp->proceed_to_finish = 0;
+
       /* Discard any remaining commands or status from previous
         stop.  */
       bpstat_clear (&tp->stop_bpstat);
 
   stop_after_trap = 0;
   stop_soon = NO_STOP_QUIETLY;
-  proceed_to_finish = 0;
   breakpoint_proceeded = 1;    /* We're about to proceed... */
 
   if (stop_registers)
       /* Save infrun state for the old thread.  */
       save_infrun_state (inferior_ptid,
                         cmd_continuation, intermediate_continuation,
-                        proceed_to_finish,
                         stop_step,
                         step_multi,
                         stop_signal);
       /* Load infrun state for the new thread.  */
       load_infrun_state (ptid,
                         &cmd_continuation, &intermediate_continuation,
-                        &proceed_to_finish,
                         &stop_step,
                         &step_multi,
                         &stop_signal);
       goto done;
     }
 
+  if (last.kind == TARGET_WAITKIND_SIGNALLED
+      || last.kind == TARGET_WAITKIND_EXITED)
+    goto done;
+
   /* Select innermost stack frame - i.e., current frame is frame 0,
      and current location is based on that.
      Don't do this on return from a stack dummy routine,
 
   /* Save the function value return registers, if we care.
      We might be about to restore their previous contents.  */
-  if (proceed_to_finish)
+  if (inferior_thread ()->proceed_to_finish)
     {
       /* This should not be necessary.  */
       if (stop_registers)
   tp->stop_bpstat = bpstat_copy (tp->stop_bpstat);
   inf_status->breakpoint_proceeded = breakpoint_proceeded;
   inf_status->restore_stack_info = restore_stack_info;
-  inf_status->proceed_to_finish = proceed_to_finish;
+  inf_status->proceed_to_finish = tp->proceed_to_finish;
 
   inf_status->registers = regcache_dup (get_current_regcache ());
 
   bpstat_clear (&tp->stop_bpstat);
   tp->stop_bpstat = inf_status->stop_bpstat;
   breakpoint_proceeded = inf_status->breakpoint_proceeded;
-  proceed_to_finish = inf_status->proceed_to_finish;
+  tp->proceed_to_finish = inf_status->proceed_to_finish;
 
   /* The inferior can be gone if the user types "print exit(0)"
      (and perhaps other times).  */
 
 load_infrun_state (ptid_t ptid,
                   struct continuation **continuations,
                   struct continuation **intermediate_continuations,
-                  int *proceed_to_finish,
                   int *stop_step,
                   int *step_multi,
                   enum target_signal *stop_signal)
       tp->continuations = NULL;
       *intermediate_continuations = tp->intermediate_continuations;
       tp->intermediate_continuations = NULL;
-      *proceed_to_finish = tp->proceed_to_finish;
       *stop_step = tp->stop_step;
       *step_multi = tp->step_multi;
       *stop_signal = tp->stop_signal;
 save_infrun_state (ptid_t ptid,
                   struct continuation *continuations,
                   struct continuation *intermediate_continuations,
-                  int proceed_to_finish,
                   int stop_step,
                   int step_multi,
                   enum target_signal stop_signal)
     {
       tp->continuations = continuations;
       tp->intermediate_continuations = intermediate_continuations;
-      tp->proceed_to_finish = proceed_to_finish;
       tp->stop_step = stop_step;
       tp->step_multi = step_multi;
       tp->stop_signal = stop_signal;