gdb/
[binutils-gdb.git] / gdb / infrun.c
index 83cfe3c124be228d6df9f59858fa61ef469dbd43..9f4c298ebee870cfe24182b1565622aa03161b91 100644 (file)
@@ -179,16 +179,6 @@ show_debug_infrun (struct ui_file *file, int from_tty,
 #endif
 
 
-/* Convert the #defines into values.  This is temporary until wfi control
-   flow is completely sorted out.  */
-
-#ifndef CANNOT_STEP_HW_WATCHPOINTS
-#define CANNOT_STEP_HW_WATCHPOINTS 0
-#else
-#undef  CANNOT_STEP_HW_WATCHPOINTS
-#define CANNOT_STEP_HW_WATCHPOINTS 1
-#endif
-
 /* Tables of how to react to signals; the user sets them.  */
 
 static unsigned char *signal_stop;
@@ -660,7 +650,6 @@ show_follow_exec_mode_string (struct ui_file *file, int from_tty,
 static void
 follow_exec (ptid_t pid, char *execd_pathname)
 {
-  struct target_ops *tgt;
   struct thread_info *th = inferior_thread ();
   struct inferior *inf = current_inferior ();
 
@@ -720,6 +709,7 @@ follow_exec (ptid_t pid, char *execd_pathname)
       char *name = alloca (strlen (gdb_sysroot)
                            + strlen (execd_pathname)
                            + 1);
+
       strcpy (name, gdb_sysroot);
       strcat (name, execd_pathname);
       execd_pathname = name;
@@ -736,7 +726,6 @@ follow_exec (ptid_t pid, char *execd_pathname)
   if (follow_exec_mode_string == follow_exec_mode_new)
     {
       struct program_space *pspace;
-      struct inferior *new_inf;
 
       /* The user wants to keep the old inferior and program spaces
         around.  Create a new fresh one, and switch to it.  */
@@ -1222,6 +1211,7 @@ static void
 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
 {
   struct cleanup *ptid_cleanup = save_inferior_ptid ();
+
   inferior_ptid = ptid;
   write_memory (memaddr, myaddr, len);
   do_cleanups (ptid_cleanup);
@@ -1248,6 +1238,7 @@ displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
   /* Restore the contents of the copy area.  */
   {
     ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
+
     write_memory_ptid (displaced->step_ptid, displaced->step_copy,
                       displaced->step_saved_copy, len);
     if (debug_displaced)
@@ -1272,6 +1263,7 @@ displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
          relocate the PC.  */
       struct regcache *regcache = get_thread_regcache (event_ptid);
       CORE_ADDR pc = regcache_read_pc (regcache);
+
       pc = displaced->step_original + (pc - displaced->step_copy);
       regcache_write_pc (regcache, pc);
     }
@@ -1484,18 +1476,6 @@ resume (int step, enum target_signal sig)
                        "trap_expected=%d\n",
                        step, sig, tp->trap_expected);
 
-  /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
-     over an instruction that causes a page fault without triggering
-     a hardware watchpoint. The kernel properly notices that it shouldn't
-     stop, because the hardware watchpoint is not triggered, but it forgets
-     the step request and continues the program normally.
-     Work around the problem by removing hardware watchpoints if a step is
-     requested, GDB will check for a hardware watchpoint trigger after the
-     step anyway.  */
-  if (CANNOT_STEP_HW_WATCHPOINTS && step)
-    remove_hw_watchpoints ();
-
-
   /* Normally, by the time we reach `resume', the breakpoints are either
      removed or inserted, as appropriate.  The exception is if we're sitting
      at a permanent breakpoint; we need to step over it, but permanent
@@ -2014,8 +1994,8 @@ void
 start_remote (int from_tty)
 {
   struct inferior *inferior;
-  init_wait_for_inferior ();
 
+  init_wait_for_inferior ();
   inferior = current_inferior ();
   inferior->stop_soon = STOP_QUIETLY_REMOTE;
 
@@ -2276,6 +2256,7 @@ delete_step_thread_step_resume_breakpoint (void)
         longjmp-resume breakpoint of the thread that just stopped
         stepping.  */
       struct thread_info *tp = inferior_thread ();
+
       delete_step_resume_breakpoint (tp);
     }
   else
@@ -2390,6 +2371,14 @@ prepare_for_detach (void)
         state.  */
       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);
 
@@ -2740,6 +2729,7 @@ adjust_pc_after_break (struct execution_control_state *ecs)
       || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
     {
       struct cleanup *old_cleanups = NULL;
+
       if (RECORD_IS_USED)
        old_cleanups = record_gdb_operation_disable_set ();
 
@@ -2893,6 +2883,7 @@ handle_inferior_event (struct execution_control_state *ecs)
       && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
     {
       struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
+
       gdb_assert (inf);
       stop_soon = inf->stop_soon;
     }
@@ -2904,7 +2895,7 @@ handle_inferior_event (struct execution_control_state *ecs)
   target_last_waitstatus = ecs->ws;
 
   /* Always clear state belonging to the previous time we stopped.  */
-  stop_stack_dummy = 0;
+  stop_stack_dummy = STOP_NONE;
 
   /* If it's a new process, add it to the thread database */
 
@@ -3364,6 +3355,7 @@ targets should add new threads to the thread list themselves in non-stop mode.")
       if (target_stopped_by_watchpoint ())
        {
           CORE_ADDR addr;
+
          fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
 
           if (target_stopped_data_address (&current_target, &addr))
@@ -3702,6 +3694,7 @@ targets should add new threads to the thread list themselves in non-stop mode.")
         the instruction and once for the delay slot.  */
       int step_through_delay
        = gdbarch_single_step_through_delay (gdbarch, frame);
+
       if (debug_infrun && step_through_delay)
        fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
       if (ecs->event_thread->step_range_end == 0 && step_through_delay)
@@ -3970,7 +3963,7 @@ process_event_stop_test:
 
     if (what.call_dummy)
       {
-       stop_stack_dummy = 1;
+       stop_stack_dummy = what.call_dummy;
       }
 
     switch (what.main_action)
@@ -4153,6 +4146,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
   if (!non_stop)
     {
       struct thread_info *tp;
+
       tp = iterate_over_threads (currently_stepping_or_nexting_callback,
                                 ecs->event_thread);
       if (tp)
@@ -4341,6 +4335,7 @@ infrun: not switching back to stepped thread, it has vanished\n");
          /* Set up a step-resume breakpoint at the address
             indicated by SKIP_SOLIB_RESOLVER.  */
          struct symtab_and_line sr_sal;
+
          init_sal (&sr_sal);
          sr_sal.pc = pc_after_resolver;
          sr_sal.pspace = get_frame_program_space (frame);
@@ -4479,6 +4474,7 @@ infrun: not switching back to stepped thread, it has vanished\n");
       if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
        {
          struct symtab_and_line sr_sal;
+
          init_sal (&sr_sal);
          sr_sal.pc = ecs->stop_func_start;
          sr_sal.pspace = get_frame_program_space (frame);
@@ -4527,6 +4523,7 @@ infrun: not switching back to stepped thread, it has vanished\n");
          /* Set a breakpoint at callee's start address.
             From there we can step once and be back in the caller.  */
          struct symtab_and_line sr_sal;
+
          init_sal (&sr_sal);
          sr_sal.pc = ecs->stop_func_start;
          sr_sal.pspace = get_frame_program_space (frame);
@@ -4565,6 +4562,7 @@ infrun: not switching back to stepped thread, it has vanished\n");
             Set a breakpoint at its start and continue, then
             one more step will take us out.  */
          struct symtab_and_line sr_sal;
+
          init_sal (&sr_sal);
          sr_sal.pc = ecs->stop_func_start;
          sr_sal.pspace = get_frame_program_space (frame);
@@ -4582,6 +4580,7 @@ infrun: not switching back to stepped thread, it has vanished\n");
     {
       /* Determine where this trampoline returns.  */
       CORE_ADDR real_stop_pc;
+
       real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
 
       if (debug_infrun)
@@ -4898,7 +4897,7 @@ handle_step_into_function_backward (struct gdbarch *gdbarch,
                                    struct execution_control_state *ecs)
 {
   struct symtab *s;
-  struct symtab_and_line stop_func_sal, sr_sal;
+  struct symtab_and_line stop_func_sal;
 
   s = find_pc_symtab (stop_pc);
   if (s && s->language != language_asm)
@@ -5090,6 +5089,7 @@ keep_going (struct execution_control_state *ecs)
       if (ecs->event_thread->stepping_over_breakpoint)
        {
          struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
+
          if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
            /* Since we can't do a displaced step, we have to remove
               the breakpoint while we step it.  To keep things
@@ -5099,6 +5099,7 @@ keep_going (struct execution_control_state *ecs)
       else
        {
          struct gdb_exception e;
+
          /* Stop stepping when inserting breakpoints
             has failed.  */
          TRY_CATCH (e, RETURN_MASK_ERROR)
@@ -5460,12 +5461,13 @@ Further execution is probably impossible.\n"));
       stop_registers = regcache_dup (get_current_regcache ());
     }
 
-  if (stop_stack_dummy)
+  if (stop_stack_dummy == STOP_STACK_DUMMY)
     {
       /* Pop the empty frame that contains the stack dummy.
         This also restores inferior state prior to the call
         (struct inferior_thread_state).  */
       struct frame_info *frame = get_current_frame ();
+
       gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
       frame_pop (frame);
       /* frame_pop() calls reinit_frame_cache as the last thing it does
@@ -5553,6 +5555,7 @@ int
 signal_stop_update (int signo, int state)
 {
   int ret = signal_stop[signo];
+
   signal_stop[signo] = state;
   return ret;
 }
@@ -5561,6 +5564,7 @@ int
 signal_print_update (int signo, int state)
 {
   int ret = signal_print[signo];
+
   signal_print[signo] = state;
   return ret;
 }
@@ -5569,6 +5573,7 @@ int
 signal_pass_update (int signo, int state)
 {
   int ret = signal_program[signo];
+
   signal_program[signo] = state;
   return ret;
 }
@@ -5852,6 +5857,7 @@ static void
 signals_info (char *signum_exp, int from_tty)
 {
   enum target_signal oursig;
+
   sig_print_header ();
 
   if (signum_exp)
@@ -5950,6 +5956,7 @@ siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
       && gdbarch_get_siginfo_type_p (gdbarch))
     {
       struct type *type = gdbarch_get_siginfo_type (gdbarch);
+
       return allocate_computed_value (type, &siginfo_value_funcs, NULL);
     }
 
@@ -6038,7 +6045,7 @@ struct inferior_status
 {
   bpstat stop_bpstat;
   int stop_step;
-  int stop_stack_dummy;
+  enum stop_stack_kind stop_stack_dummy;
   int stopped_by_random_signal;
   int stepping_over_breakpoint;
   CORE_ADDR step_range_start;
@@ -6325,8 +6332,7 @@ ptid_match (ptid_t ptid, ptid_t filter)
   /* Since both parameters have the same type, prevent easy mistakes
      from happening.  */
   gdb_assert (!ptid_equal (ptid, minus_one_ptid)
-             && !ptid_equal (ptid, null_ptid)
-             && !ptid_is_pid (ptid));
+             && !ptid_equal (ptid, null_ptid));
 
   if (ptid_equal (filter, minus_one_ptid))
     return 1;
@@ -6347,6 +6353,7 @@ static void
 restore_inferior_ptid (void *arg)
 {
   ptid_t *saved_ptid_ptr = arg;
+
   inferior_ptid = *saved_ptid_ptr;
   xfree (arg);
 }
@@ -6453,7 +6460,6 @@ _initialize_infrun (void)
 {
   int i;
   int numsigs;
-  struct cmd_list_element *c;
 
   add_info ("signals", signals_info, _("\
 What debugger does when program gets various signals.\n\