* inftarg.c (child_thread_alive): New function to see if a
[deliverable/binutils-gdb.git] / gdb / infrun.c
index 850f88fa04a4fff943a9dbd20c3a44e4df72101e..5ad2bfc45dbf47159f80bf40c3b61d25312ab2ba 100644 (file)
@@ -136,11 +136,13 @@ static struct symbol *step_start_function;
 
 static int trap_expected;
 
+#ifdef HP_OS_BUG
 /* Nonzero if the next time we try to continue the inferior, it will
    step one instruction and generate a spurious trace trap.
    This is used to compensate for a bug in HP-UX.  */
 
 static int trap_expected_after_continue;
+#endif
 
 /* Nonzero means expecting a trace trap
    and should stop the inferior and return silently when it happens.  */
@@ -317,6 +319,7 @@ proceed (addr, siggnal, step)
     oneproc = 1;
 #endif /* PREPARE_TO_PROCEED */
 
+#ifdef HP_OS_BUG
   if (trap_expected_after_continue)
     {
       /* If (step == 0), a trap will be automatically generated after
@@ -326,6 +329,7 @@ proceed (addr, siggnal, step)
       oneproc = 1;
       trap_expected_after_continue = 0;
     }
+#endif /* HP_OS_BUG */
 
   if (oneproc)
     /* We will get a trace trap after one instruction.
@@ -352,6 +356,10 @@ The same program may be running in another process.");
 
   annotate_starting ();
 
+  /* Make sure that output from GDB appears before output from the
+     inferior.  */
+  gdb_flush (gdb_stdout);
+
   /* Resume inferior.  */
   resume (oneproc || step || bpstat_should_step (), stop_signal);
 
@@ -395,7 +403,9 @@ init_wait_for_inferior ()
   prev_func_start = 0;
   prev_func_name = NULL;
 
+#ifdef HP_OS_BUG
   trap_expected_after_continue = 0;
+#endif
   breakpoints_inserted = 0;
   breakpoint_init_inferior ();
 
@@ -469,6 +479,8 @@ wait_for_inferior ()
       else
        pid = target_wait (-1, &w);
 
+    have_waited:
+
       flush_cached_frames ();
 
       /* If it's a new process, add it to the thread database */
@@ -575,7 +587,7 @@ wait_for_inferior ()
          if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
            {
              /* Saw a breakpoint, but it was hit by the wrong thread.  Just continue. */
-             write_pc (stop_pc - DECR_PC_AFTER_BREAK);
+             write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
 
              remove_breakpoints ();
              target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
@@ -587,7 +599,9 @@ wait_for_inferior ()
              else
                target_wait (pid, &w);
              insert_breakpoints ();
-             target_resume (pid, 0, TARGET_SIGNAL_0);
+
+             /* We need to restart all the threads now.  */
+             target_resume (-1, 0, TARGET_SIGNAL_0);
              continue;
            }
        }
@@ -697,19 +711,34 @@ wait_for_inferior ()
         here?  */
       if (STOPPED_BY_WATCHPOINT (w))
        {
+/* At this point, we are stopped at an instruction which has attempted to write
+   to a piece of memory under control of a watchpoint.  The instruction hasn't
+   actually executed yet.  If we were to evaluate the watchpoint expression
+   now, we would get the old value, and therefore no change would seem to have
+   occurred.
+
+   In order to make watchpoints work `right', we really need to complete the
+   memory write, and then evaluate the watchpoint expression.  The following
+   code does that by removing the watchpoint (actually, all watchpoints and
+   breakpoints), single-stepping the target, re-inserting watchpoints, and then
+   falling through to let normal single-step processing handle proceed.  Since
+   this includes evaluating watchpoints, things will come to a stop in the
+   correct manner.  */
+
+         write_pc (stop_pc - DECR_PC_AFTER_BREAK);
+
          remove_breakpoints ();
-         resume (1, 0);
+         target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
 
-         /* FIXME: This is bogus.  You can't interact with the
-            inferior except when it is stopped.  It apparently
-            happens to work on Irix4, but it depends on /proc
-            allowing us to muck with the memory of a running process,
-            and the kernel deciding to run one instruction of the
-            inferior before it executes our insert_breakpoints code,
-            which seems like an awfully dubious assumption.  */
+         if (target_wait_hook)
+           target_wait_hook (pid, &w);
+         else
+           target_wait (pid, &w);
          insert_breakpoints ();
-
-         continue;
+         /* FIXME-maybe: is this cleaner than setting a flag?  Does it
+            handle things like signals arriving and other things happening
+            in combination correctly?  */
+         goto have_waited;
        }
 #endif
 
@@ -1748,10 +1777,11 @@ handle_command (args, from_tty)
             anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
             will work right anyway.  */
 
-         sigfirst = siglast = atoi (*argv);
+         sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
          if ((*argv)[digits] == '-')
            {
-             siglast = atoi ((*argv) + digits + 1);
+             siglast =
+               (int) target_signal_from_command (atoi ((*argv) + digits + 1));
            }
          if (sigfirst > siglast)
            {
@@ -1760,14 +1790,6 @@ handle_command (args, from_tty)
              sigfirst = siglast;
              siglast = signum;
            }
-         if (sigfirst < 0 || sigfirst >= nsigs)
-           {
-             error ("Signal %d not in range 0-%d", sigfirst, nsigs - 1);
-           }
-         if (siglast < 0 || siglast >= nsigs)
-           {
-             error ("Signal %d not in range 0-%d", siglast, nsigs - 1);
-           }
        }
       else
        {
@@ -1808,6 +1830,11 @@ Are you sure you want to change it? ",
                      }
                  }
                break;
+             case TARGET_SIGNAL_0:
+             case TARGET_SIGNAL_DEFAULT:
+             case TARGET_SIGNAL_UNKNOWN:
+               /* Make sure that "all" doesn't print these.  */
+               break;
              default:
                sigs[signum] = 1;
                break;
@@ -1854,20 +1881,9 @@ signals_info (signum_exp, from_tty)
       oursig = target_signal_from_name (signum_exp);
       if (oursig == TARGET_SIGNAL_UNKNOWN)
        {
-         /* Nope, maybe it's an address which evaluates to a signal
-            number.  */
-         /* The numeric signal refers to our own internal
-            signal numbering from target.h, not to host/target signal number.
-            This is a feature; users really should be using symbolic names
-            anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
-            will work right anyway.  */
-         int i = parse_and_eval_address (signum_exp);
-         if (i >= (int)TARGET_SIGNAL_LAST
-             || i < 0
-             || i == (int)TARGET_SIGNAL_UNKNOWN
-             || i == (int)TARGET_SIGNAL_DEFAULT)
-           error ("Signal number out of bounds.");
-         oursig = (enum target_signal)i;
+         /* No, try numeric.  */
+         oursig =
+           target_signal_from_command (parse_and_eval_address (signum_exp));
        }
       sig_print_info (oursig);
       return;
@@ -2029,23 +2045,24 @@ _initialize_infrun ()
 
   add_info ("signals", signals_info,
            "What debugger does when program gets various signals.\n\
-Specify a signal number as argument to print info on that signal only.");
+Specify a signal as argument to print info on that signal only.");
   add_info_alias ("handle", "signals", 0);
 
   add_com ("handle", class_run, handle_command,
-          "Specify how to handle a signal.\n\
-Args are signal numbers and actions to apply to those signals.\n\
-Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
-Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
+          concat ("Specify how to handle a signal.\n\
+Args are signals and actions to apply to those signals.\n\
+Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
+from 1-15 are allowed for compatibility with old versions of GDB.\n\
+Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
 The special arg \"all\" is recognized to mean all signals except those\n\
-used by the debugger, typically SIGTRAP and SIGINT.\n\
-Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
+used by the debugger, typically SIGTRAP and SIGINT.\n",
+"Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
 Stop means reenter debugger if this signal happens (implies print).\n\
 Print means print a message if this signal happens.\n\
 Pass means let program see this signal; otherwise program doesn't know.\n\
 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
-Pass and Stop may be combined.");
+Pass and Stop may be combined.", NULL));
 
   stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
           "There is no `stop' command, but you can set a hook on `stop'.\n\
This page took 0.025827 seconds and 4 git commands to generate.