Don't rely on immediate_quit in command_line_input
[deliverable/binutils-gdb.git] / gdb / top.c
index 89fe832308e6bb8dc2322a7097651e0aa03067e1..90a3f481c27d77e0c19967e1df60a6ae9308103e 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -51,6 +51,7 @@
 #include "filenames.h"
 #include "frame.h"
 #include "buffer.h"
+#include "gdb_select.h"
 
 /* readline include files.  */
 #include "readline/readline.h"
@@ -592,6 +593,10 @@ static char *
 gdb_readline_no_editing (const char *prompt)
 {
   struct buffer line_buffer;
+  /* Read from stdin if we are executing a user defined command.  This
+     is the right thing for prompt_for_continue, at least.  */
+  FILE *stream = instream != NULL ? instream : stdin;
+  int fd = fileno (stream);
 
   buffer_init (&line_buffer);
 
@@ -607,10 +612,26 @@ gdb_readline_no_editing (const char *prompt)
   while (1)
     {
       int c;
+      int numfds;
+      fd_set readfds;
 
-      /* Read from stdin if we are executing a user defined command.
-         This is the right thing for prompt_for_continue, at least.  */
-      c = fgetc (instream ? instream : stdin);
+      QUIT;
+
+      /* Wait until at least one byte of data is available.  Control-C
+        can interrupt gdb_select, but not fgetc.  */
+      FD_ZERO (&readfds);
+      FD_SET (fd, &readfds);
+      if (gdb_select (fd + 1, &readfds, NULL, NULL, NULL) == -1)
+       {
+         if (errno == EINTR)
+           {
+             /* If this was ctrl-c, the QUIT above handles it.  */
+             continue;
+           }
+         perror_with_name (("select"));
+       }
+
+      c = fgetc (stream);
 
       if (c == EOF)
        {
@@ -1048,10 +1069,6 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
   /* Starting a new command line.  */
   cmd_line_buffer.used_size = 0;
 
-  /* Control-C quits instantly if typed while in this loop
-     since it should not wait until the user types a newline.  */
-  immediate_quit++;
-  QUIT;
 #ifdef STOP_SIGNAL
   if (job_control)
     signal (STOP_SIGNAL, handle_stop_sig);
@@ -1109,7 +1126,6 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
   if (job_control)
     signal (STOP_SIGNAL, SIG_DFL);
 #endif
-  immediate_quit--;
 
   return cmd;
 }
This page took 0.0263 seconds and 4 git commands to generate.