* gdbserver/remote-utils.c (remote_open): Set VMIN to 1
[deliverable/binutils-gdb.git] / gdb / gdbserver / remote-utils.c
index 2b632d6c1fddec140f1e7a7391fad29e348a1200..cfde0a7dae4c9622cc5fccce138f5485163c3fdf 100644 (file)
@@ -1,5 +1,6 @@
 /* Remote utility routines for the remote server for GDB.
-   Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.
+   Copyright 1986, 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -31,6 +32,8 @@
 #include <sys/ioctl.h>
 #include <signal.h>
 #include <fcntl.h>
+#include <sys/time.h>
+#include <unistd.h>
 
 int remote_debug = 0;
 struct ui_file *gdb_stdlog;
@@ -41,8 +44,7 @@ static int remote_desc;
    NAME is the filename used for communication.  */
 
 void
-remote_open (name)
-     char *name;
+remote_open (char *name)
 {
   int save_fcntl_flags;
 
@@ -62,7 +64,7 @@ remote_open (name)
        termios.c_lflag = 0;
        termios.c_cflag &= ~(CSIZE | PARENB);
        termios.c_cflag |= CLOCAL | CS8;
-       termios.c_cc[VMIN] = 0;
+       termios.c_cc[VMIN] = 1;
        termios.c_cc[VTIME] = 0;
 
        tcsetattr (remote_desc, TCSANOW, &termios);
@@ -79,7 +81,7 @@ remote_open (name)
        termio.c_lflag = 0;
        termio.c_cflag &= ~(CSIZE | PARENB);
        termio.c_cflag |= CLOCAL | CS8;
-       termio.c_cc[VMIN] = 0;
+       termio.c_cc[VMIN] = 1;
        termio.c_cc[VTIME] = 0;
 
        ioctl (remote_desc, TCSETA, &termio);
@@ -156,13 +158,16 @@ remote_open (name)
 #if defined(F_SETFL) && defined (FASYNC)
   save_fcntl_flags = fcntl (remote_desc, F_GETFL, 0);
   fcntl (remote_desc, F_SETFL, save_fcntl_flags | FASYNC);
+#if defined (F_SETOWN)
+  fcntl (remote_desc, F_SETOWN, getpid ());
+#endif
+#endif
   disable_async_io ();
-#endif /* FASYNC */
   fprintf (stderr, "Remote debugging using %s\n", name);
 }
 
 void
-remote_close ()
+remote_close (void)
 {
   close (remote_desc);
 }
@@ -170,8 +175,7 @@ remote_close ()
 /* Convert hex digit A to a number.  */
 
 static int
-fromhex (a)
-     int a;
+fromhex (int a)
 {
   if (a >= '0' && a <= '9')
     return a - '0';
@@ -184,8 +188,7 @@ fromhex (a)
 /* Convert number NIB to a hex digit.  */
 
 static int
-tohex (nib)
-     int nib;
+tohex (int nib)
 {
   if (nib < 10)
     return '0' + nib;
@@ -197,8 +200,7 @@ tohex (nib)
    The data of the packet is in BUF.  Returns >= 0 on success, -1 otherwise. */
 
 int
-putpkt (buf)
-     char *buf;
+putpkt (char *buf)
 {
   int i;
   unsigned char csum = 0;
@@ -262,30 +264,41 @@ putpkt (buf)
    will cause us to send a SIGINT to the child.  */
 
 static void
-input_interrupt ()
+input_interrupt (void)
 {
-  int cc;
-  char c;
+  fd_set readset;
+  struct timeval immediate = { 0, 0 };
 
-  cc = read (remote_desc, &c, 1);
+  /* Protect against spurious interrupts.  This has been observed to
+     be a problem under NetBSD 1.4 and 1.5.  */
 
-  if (cc != 1 || c != '\003')
+  FD_ZERO (&readset);
+  FD_SET (remote_desc, &readset);
+  if (select (remote_desc + 1, &readset, 0, 0, &immediate) > 0)
     {
-      fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
-      return;
-    }
+      int cc;
+      char c;
+      
+      cc = read (remote_desc, &c, 1);
 
-  kill (inferior_pid, SIGINT);
+      if (cc != 1 || c != '\003')
+       {
+         fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
+         return;
+       }
+      
+      kill (inferior_pid, SIGINT);
+    }
 }
 
 void
-enable_async_io ()
+enable_async_io (void)
 {
   signal (SIGIO, input_interrupt);
 }
 
 void
-disable_async_io ()
+disable_async_io (void)
 {
   signal (SIGIO, SIG_IGN);
 }
@@ -293,7 +306,7 @@ disable_async_io ()
 /* Returns next char from remote GDB.  -1 if error.  */
 
 static int
-readchar ()
+readchar (void)
 {
   static char buf[BUFSIZ];
   static int bufcnt = 0;
@@ -323,8 +336,7 @@ readchar ()
    and store it in BUF.  Returns length of packet, or negative if error. */
 
 int
-getpkt (buf)
-     char *buf;
+getpkt (char *buf)
 {
   char *bp;
   unsigned char csum, c1, c2;
@@ -380,8 +392,7 @@ getpkt (buf)
 }
 
 void
-write_ok (buf)
-     char *buf;
+write_ok (char *buf)
 {
   buf[0] = 'O';
   buf[1] = 'K';
@@ -389,8 +400,7 @@ write_ok (buf)
 }
 
 void
-write_enn (buf)
-     char *buf;
+write_enn (char *buf)
 {
   buf[0] = 'E';
   buf[1] = 'N';
@@ -399,9 +409,7 @@ write_enn (buf)
 }
 
 void
-convert_int_to_ascii (from, to, n)
-     char *from, *to;
-     int n;
+convert_int_to_ascii (char *from, char *to, int n)
 {
   int nib;
   char ch;
@@ -418,9 +426,7 @@ convert_int_to_ascii (from, to, n)
 
 
 void
-convert_ascii_to_int (from, to, n)
-     char *from, *to;
-     int n;
+convert_ascii_to_int (char *from, char *to, int n)
 {
   int nib1, nib2;
   while (n--)
@@ -432,9 +438,7 @@ convert_ascii_to_int (from, to, n)
 }
 
 static char *
-outreg (regno, buf)
-     int regno;
-     char *buf;
+outreg (int regno, char *buf)
 {
   int regsize = REGISTER_RAW_SIZE (regno);
 
@@ -453,10 +457,7 @@ outreg (regno, buf)
 }
 
 void
-prepare_resume_reply (buf, status, signo)
-     char *buf;
-     char status;
-     unsigned char signo;
+prepare_resume_reply (char *buf, char status, unsigned char signo)
 {
   int nib;
 
@@ -512,10 +513,7 @@ prepare_resume_reply (buf, status, signo)
 }
 
 void
-decode_m_packet (from, mem_addr_ptr, len_ptr)
-     char *from;
-     CORE_ADDR *mem_addr_ptr;
-     unsigned int *len_ptr;
+decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
 {
   int i = 0, j = 0;
   char ch;
@@ -537,10 +535,8 @@ decode_m_packet (from, mem_addr_ptr, len_ptr)
 }
 
 void
-decode_M_packet (from, mem_addr_ptr, len_ptr, to)
-     char *from, *to;
-     CORE_ADDR *mem_addr_ptr;
-     unsigned int *len_ptr;
+decode_M_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr,
+                char *to)
 {
   int i = 0;
   char ch;
This page took 0.041009 seconds and 4 git commands to generate.