import gdb-2000-01-17 snapshot
[deliverable/binutils-gdb.git] / gdb / event-top.c
index 622396f1e6948626bec8988e0ea40d4d695e656f..3d21a1a2b21adc08afbfa62d79c4ea2ed4c65e43 100644 (file)
@@ -22,6 +22,7 @@
 #include "defs.h"
 #include "top.h"
 #include "inferior.h"
+#include "target.h"
 #include "terminal.h"          /* for job_control */
 #include "signals.h"
 #include "event-loop.h"
@@ -34,6 +35,8 @@
 #include <readline/readline.h>
 #include <readline/history.h>
 
+#include <signal.h>
+
 /* readline defines this.  */
 #undef savestring
 
@@ -244,22 +247,22 @@ display_gdb_prompt (char *new_prompt)
   char *gdb_prompt = get_prompt ();
 
 
-  if (target_executing && sync_execution) 
+  if (target_executing && sync_execution)
     {
       /* This is to trick readline into not trying to display the
-        prompt.  Even though we display the prompt using this
-        function, readline still tries to do its own display if we
-        don't call rl_callback_handler_install and
-        rl_callback_handler_remove (which readline detects because a
-        global variable is not set). If readline did that, it could
-        mess up gdb signal handlers for SIGINT.  Readline assumes
-        that between calls to rl_set_signals and rl_clear_signals gdb
-        doesn't do anything with the signal handlers. Well, that's
-        not the case, because when the target executes we change the
-        SIGINT signal handler. If we allowed readline to display the
-        prompt, the signal handler change would happen exactly
-        between the calls to the above two functions.
-        Calling rl_callback_handler_remove(), does the job. */
+         prompt.  Even though we display the prompt using this
+         function, readline still tries to do its own display if we
+         don't call rl_callback_handler_install and
+         rl_callback_handler_remove (which readline detects because a
+         global variable is not set). If readline did that, it could
+         mess up gdb signal handlers for SIGINT.  Readline assumes
+         that between calls to rl_set_signals and rl_clear_signals gdb
+         doesn't do anything with the signal handlers. Well, that's
+         not the case, because when the target executes we change the
+         SIGINT signal handler. If we allowed readline to display the
+         prompt, the signal handler change would happen exactly
+         between the calls to the above two functions.
+         Calling rl_callback_handler_remove(), does the job. */
 
       rl_callback_handler_remove ();
       return;
@@ -399,21 +402,58 @@ pop_prompt (void)
    instead of calling gdb_readline2, give gdb a chance to detect
    errors and do something. */
 void
-stdin_event_handler (int error, int fd, gdb_client_data client_data)
+stdin_event_handler (int error, gdb_client_data client_data)
 {
   if (error)
     {
-      printf_unfiltered ("error detected on stdin, fd %d\n", fd);
-      delete_file_handler (fd);
+      printf_unfiltered ("error detected on stdin\n");
+      delete_file_handler (input_fd);
       discard_all_continuations ();
       /* If stdin died, we may as well kill gdb. */
-      exit (1);
+      quit_command ((char *) 0, stdin == instream);
     }
   else
-    (*call_readline) (client_data);      
+    (*call_readline) (client_data);
+}
+
+/* Re-enable stdin after the end of an execution command in
+   synchronous mode, or after an error from the target, and we aborted
+   the exec operation. */
+
+void
+async_enable_stdin (void *dummy)
+{
+  /* See NOTE in async_disable_stdin() */
+  /* FIXME: cagney/1999-09-27: Call this before clearing
+     sync_execution.  Current target_terminal_ours() implementations
+     check for sync_execution before switching the terminal. */
+  target_terminal_ours ();
+  pop_prompt ();
+  sync_execution = 0;
 }
 
+/* Disable reads from stdin (the console) marking the command as
+   synchronous. */
+
+void
+async_disable_stdin (void)
+{
+  sync_execution = 1;
+  push_prompt ("", "", "");
+  /* FIXME: cagney/1999-09-27: At present this call is technically
+     redundant since infcmd.c and infrun.c both already call
+     target_terminal_inferior().  As the terminal handling (in
+     sync/async mode) is refined, the duplicate calls can be
+     eliminated (Here or in infcmd.c/infrun.c). */
+  target_terminal_inferior ();
+  /* Add the reinstate of stdin to the list of cleanups to be done
+     in case the target errors out and dies. These cleanups are also
+     done in case of normal successful termination of the execution
+     command, by complete_execution(). */
+  make_exec_error_cleanup (async_enable_stdin, NULL);
+}
 \f
+
 /* Handles a gdb command. This function is called by
    command_line_handler, which has processed one or more input lines
    into COMMAND. */
@@ -471,7 +511,7 @@ command_handler (char *command)
   /* Set things up for this function to be compete later, once the
      executin has completed, if we are doing an execution command,
      otherwise, just go ahead and finish. */
-  if (target_has_async && target_executing)
+  if (target_can_async_p () && target_executing)
     {
       arg1 =
        (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
@@ -487,7 +527,7 @@ command_handler (char *command)
   /* Do any commands attached to breakpoint we stopped at. Only if we
      are always running synchronously. Or if we have just executed a
      command that doesn't start the target. */
-  if (!target_has_async || !target_executing)
+  if (!target_can_async_p () || !target_executing)
     {
       bpstat_do_actions (&stop_bpstat);
       do_cleanups (old_chain);
@@ -1003,7 +1043,15 @@ async_stop_sig (gdb_client_data arg)
   char *prompt = get_prompt ();
 #if STOP_SIGNAL == SIGTSTP
   signal (SIGTSTP, SIG_DFL);
+#if HAVE_SIGPROCMASK
+  {
+    sigset_t zero;
+    sigemptyset (&zero);
+    sigprocmask (SIG_SETMASK, &zero, 0);
+  }
+#else
   sigsetmask (0);
+#endif
   kill (getpid (), SIGTSTP);
   signal (SIGTSTP, handle_stop_sig);
 #else
@@ -1077,7 +1125,7 @@ set_async_prompt (char *args, int from_tty, struct cmd_list_element *c)
 void
 _initialize_event_loop (void)
 {
-  if (async_p)
+  if (event_loop_p)
     {
       /* When a character is detected on instream by select or poll,
          readline will be invoked via this callback function. */
This page took 0.02682 seconds and 4 git commands to generate.