gdb/
[deliverable/binutils-gdb.git] / gdb / infrun.c
index 210cdd7f49aec4d99ef76a91c5a8a34128622f96..53db3350aec14f7bd06c0d100a552e26da16b0a6 100644 (file)
@@ -2437,8 +2437,6 @@ infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
 
       old_chain = make_cleanup_restore_current_thread ();
 
-      switch_to_thread (info->ptid);
-
       /* Go through handle_inferior_event/normal_stop, so we always
         have consistent output as if the stop event had been
         reported.  */
@@ -2655,14 +2653,6 @@ prepare_for_detach (void)
       old_chain_2 = make_cleanup (finish_thread_state_cleanup,
                                  &minus_one_ptid);
 
-      /* In non-stop mode, each thread is handled individually.
-        Switch early, so the global state is set correctly for this
-        thread.  */
-      if (non_stop
-         && ecs->ws.kind != TARGET_WAITKIND_EXITED
-         && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
-       context_switch (ecs->ptid);
-
       /* Now figure out what to do with the result of the result.  */
       handle_inferior_event (ecs);
 
@@ -2789,16 +2779,6 @@ fetch_inferior_event (void *client_data)
   if (debug_infrun)
     print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
 
-  if (non_stop
-      && ecs->ws.kind != TARGET_WAITKIND_IGNORE
-      && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
-      && ecs->ws.kind != TARGET_WAITKIND_EXITED
-      && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
-    /* In non-stop mode, each thread is handled individually.  Switch
-       early, so the global state is set correctly for this
-       thread.  */
-    context_switch (ecs->ptid);
-
   /* If an error happens while handling the event, propagate GDB's
      knowledge of the executing state to the frontend/user running
      state.  */
@@ -3380,6 +3360,9 @@ handle_inferior_event (struct execution_control_state *ecs)
         we're attaching or setting up a remote connection.  */
       if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
        {
+         if (!ptid_equal (ecs->ptid, inferior_ptid))
+           context_switch (ecs->ptid);
+
          /* Loading of shared libraries might have changed breakpoint
             addresses.  Make sure new breakpoints are inserted.  */
          if (stop_soon == NO_STOP_QUIETLY
@@ -3395,6 +3378,9 @@ handle_inferior_event (struct execution_control_state *ecs)
     case TARGET_WAITKIND_SPURIOUS:
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
+      if (!ptid_equal (ecs->ptid, inferior_ptid)
+         && !ptid_equal (ecs->ptid, minus_one_ptid))
+       context_switch (ecs->ptid);
       resume (0, GDB_SIGNAL_0);
       prepare_to_wait (ecs);
       return;
@@ -3769,6 +3755,8 @@ handle_inferior_event (struct execution_control_state *ecs)
                                "infrun: stepping_past_"
                                "singlestep_breakpoint\n");
          /* Pull the single step breakpoints out of the target.  */
+         if (!ptid_equal (ecs->ptid, inferior_ptid))
+           context_switch (ecs->ptid);
          remove_single_step_breakpoints ();
          singlestep_breakpoints_inserted_p = 0;
 
@@ -3801,6 +3789,8 @@ handle_inferior_event (struct execution_control_state *ecs)
          /* Pull the single step breakpoints out of the target.  */
          if (singlestep_breakpoints_inserted_p)
            {
+             if (!ptid_equal (ecs->ptid, inferior_ptid))
+               context_switch (ecs->ptid);
              remove_single_step_breakpoints ();
              singlestep_breakpoints_inserted_p = 0;
            }
@@ -4079,12 +4069,19 @@ handle_inferior_event (struct execution_control_state *ecs)
         skip_inline_frames call would break things.  Fortunately
         that's an extremely unlikely scenario.  */
       if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
-          && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
-               && ecs->event_thread->control.trap_expected
-               && pc_at_non_inline_function (aspace,
-                                             ecs->event_thread->prev_pc,
+         && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
+              && ecs->event_thread->control.trap_expected
+              && pc_at_non_inline_function (aspace,
+                                            ecs->event_thread->prev_pc,
                                             &ecs->ws)))
-       skip_inline_frames (ecs->ptid);
+       {
+         skip_inline_frames (ecs->ptid);
+
+         /* Re-fetch current thread's frame in case that invalidated
+            the frame cache.  */
+         frame = get_current_frame ();
+         gdbarch = get_frame_arch (frame);
+       }
     }
 
   if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
@@ -4423,10 +4420,6 @@ process_event_stop_test:
                return;
              }
 
-           /* We're going to replace the current step-resume breakpoint
-              with a longjmp-resume breakpoint.  */
-           delete_step_resume_breakpoint (ecs->event_thread);
-
            /* Insert a breakpoint at resume address.  */
            insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
          }
@@ -4436,62 +4429,75 @@ process_event_stop_test:
        return;
 
       case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
-        if (debug_infrun)
-         fprintf_unfiltered (gdb_stdlog,
-                             "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
+       {
+         struct frame_info *init_frame;
 
-       if (what.is_longjmp)
-         {
-           gdb_assert (ecs->event_thread->control.step_resume_breakpoint
-                       != NULL);
-           delete_step_resume_breakpoint (ecs->event_thread);
-         }
-       else
-         {
-           /* There are several cases to consider.
+         /* There are several cases to consider.
 
-              1. The initiating frame no longer exists.  In this case
-              we must stop, because the exception has gone too far.
+            1. The initiating frame no longer exists.  In this case
+            we must stop, because the exception or longjmp has gone
+            too far.
 
-              2. The initiating frame exists, and is the same as the
-              current frame.  We stop, because the exception has been
-              caught.
+            2. The initiating frame exists, and is the same as the
+            current frame.  We stop, because the exception or longjmp
+            has been caught.
 
-              3. The initiating frame exists and is different from
-              the current frame.  This means the exception has been
-              caught beneath the initiating frame, so keep going.  */
-           struct frame_info *init_frame
-             = frame_find_by_id (ecs->event_thread->initiating_frame);
+            3. The initiating frame exists and is different from the
+            current frame.  This means the exception or longjmp has
+            been caught beneath the initiating frame, so keep
+            going.
 
-           gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
-                       != NULL);
-           delete_exception_resume_breakpoint (ecs->event_thread);
+            4. longjmp breakpoint has been placed just to protect
+            against stale dummy frames and user is not interested in
+            stopping around longjmps.  */
 
-           if (init_frame)
-             {
-               struct frame_id current_id
-                 = get_frame_id (get_current_frame ());
-               if (frame_id_eq (current_id,
-                                ecs->event_thread->initiating_frame))
-                 {
-                   /* Case 2.  Fall through.  */
-                 }
-               else
-                 {
-                   /* Case 3.  */
-                   keep_going (ecs);
-                   return;
-                 }
-             }
+         if (debug_infrun)
+           fprintf_unfiltered (gdb_stdlog,
+                               "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
 
-           /* For Cases 1 and 2, remove the step-resume breakpoint,
-              if it exists.  */
-           delete_step_resume_breakpoint (ecs->event_thread);
-         }
+         gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
+                     != NULL);
+         delete_exception_resume_breakpoint (ecs->event_thread);
 
-       ecs->event_thread->control.stop_step = 1;
-       print_end_stepping_range_reason ();
-       stop_stepping (ecs);
+         if (what.is_longjmp)
+           {
+             check_longjmp_breakpoint_for_call_dummy (ecs->event_thread->num);
+
+             if (!frame_id_p (ecs->event_thread->initiating_frame))
+               {
+                 /* Case 4.  */
+                 keep_going (ecs);
+                 return;
+               }
+           }
+
+         init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
+
+         if (init_frame)
+           {
+             struct frame_id current_id
+               = get_frame_id (get_current_frame ());
+             if (frame_id_eq (current_id,
+                              ecs->event_thread->initiating_frame))
+               {
+                 /* Case 2.  Fall through.  */
+               }
+             else
+               {
+                 /* Case 3.  */
+                 keep_going (ecs);
+                 return;
+               }
+           }
+
+         /* For Cases 1 and 2, remove the step-resume breakpoint,
+            if it exists.  */
+         delete_step_resume_breakpoint (ecs->event_thread);
+
+         ecs->event_thread->control.stop_step = 1;
+         print_end_stepping_range_reason ();
+         stop_stepping (ecs);
+       }
        return;
 
       case BPSTAT_WHAT_SINGLE:
@@ -5461,17 +5467,17 @@ insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
 static void
 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  /* There should never be more than one step-resume or longjmp-resume
-     breakpoint per thread, so we should never be setting a new
+  /* There should never be more than one longjmp-resume breakpoint per
+     thread, so we should never be setting a new
      longjmp_resume_breakpoint when one is already active.  */
-  gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
+  gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
 
   if (debug_infrun)
     fprintf_unfiltered (gdb_stdlog,
                        "infrun: inserting longjmp-resume breakpoint at %s\n",
                        paddress (gdbarch, pc));
 
-  inferior_thread ()->control.step_resume_breakpoint =
+  inferior_thread ()->control.exception_resume_breakpoint =
     set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
 }
 
@@ -6646,7 +6652,9 @@ siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
 struct infcall_suspend_state
 {
   struct thread_suspend_state thread_suspend;
+#if 0 /* Currently unused and empty structures are not valid C.  */
   struct inferior_suspend_state inferior_suspend;
+#endif
 
   /* Other fields:  */
   CORE_ADDR stop_pc;
@@ -6700,7 +6708,9 @@ save_infcall_suspend_state (void)
     }
 
   inf_state->thread_suspend = tp->suspend;
+#if 0 /* Currently unused and empty structures are not valid C.  */
   inf_state->inferior_suspend = inf->suspend;
+#endif
 
   /* run_inferior_call will not use the signal due to its `proceed' call with
      GDB_SIGNAL_0 anyway.  */
@@ -6724,7 +6734,9 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
 
   tp->suspend = inf_state->thread_suspend;
+#if 0 /* Currently unused and empty structures are not valid C.  */
   inf->suspend = inf_state->inferior_suspend;
+#endif
 
   stop_pc = inf_state->stop_pc;
 
This page took 0.028135 seconds and 4 git commands to generate.