Minor bug fixes from last big checkin.
[deliverable/binutils-gdb.git] / gdb / remote.c
index 85621249df4429b0db4eca669030d885d440a5d4..03d4deeb093d29653b412ae4165f6273ad7d85a6 100644 (file)
@@ -63,19 +63,25 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
        The reply comes when the machine stops.
        It is           SAA             AA is the "signal number"
 
+       or...           TAAPPPPPPPPFFFFFFFF
+                                       where AA is the signal number,
+                                       PPPPPPPP is the PC (PC_REGNUM), and
+                                       FFFFFFFF is the frame ptr (FP_REGNUM).
+
        kill req        k
 */
 
-#include <stdio.h>
+#include "defs.h"
 #include <string.h>
 #include <fcntl.h>
-#include "defs.h"
 #include "frame.h"
 #include "inferior.h"
 #include "target.h"
 #include "wait.h"
 #include "terminal.h"
+#include "gdbcmd.h"
 
+#if !defined(DONT_USE_REMOTE)
 #ifdef USG
 #include <sys/types.h>
 #endif
@@ -141,7 +147,7 @@ remote_detach PARAMS ((char *, int));
 
 extern struct target_ops remote_ops;   /* Forward decl */
 
-static int kiodebug;
+static int kiodebug = 0;
 static int timeout = 5;
 
 #if 0
@@ -168,7 +174,8 @@ int remote_desc = -1;
 /* Called when SIGALRM signal sent due to alarm() timeout.  */
 #ifndef HAVE_TERMIO
 void
-remote_timer ()
+remote_timer (signo)
+     int signo;
 {
   if (kiodebug)
     printf ("remote_timer called\n");
@@ -199,6 +206,8 @@ remote_close (quitting)
 #define B38400 EXTB
 #endif
 
+
+
 static struct {int rate, damn_b;} baudtab[] = {
        {0, B0},
        {50, B50},
@@ -239,7 +248,7 @@ remote_open (name, from_tty)
      int from_tty;
 {
   TERMINAL sg;
-  int a_rate, b_rate;
+  int a_rate, b_rate = 0;
   int baudrate_set = 0;
 
   if (name == 0)
@@ -276,7 +285,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
   sg.c_cflag &= ~PARENB;       /* No parity */
   sg.c_cflag |= CS8;           /* 8-bit path */
   if (baudrate_set)
-    sg.c_cflag = (sb.c_cflag & ~CBAUD) | b_rate;
+    sg.c_cflag = (sg.c_cflag & ~CBAUD) | b_rate;
 #else
   sg.sg_flags |= RAW | ANYP;
   sg.sg_flags &= ~ECHO;
@@ -305,7 +314,7 @@ device is attached to the remote system (e.g. /dev/ttya).");
 #endif
 
   /* Ack any packet which the remote side has already sent.  */
-  write (remote_desc, "+", 1);
+  write (remote_desc, "+\r", 2);
   putpkt ("?");                        /* initiate a query from remote machine */
 
   start_remote ();             /* Initialize gdb process mechanisms */
@@ -368,7 +377,8 @@ remote_resume (step, siggnal)
   char buf[PBUFSIZ];
 
   if (siggnal)
-    error ("Can't send signals to a remote system.");
+    error ("Can't send signals to a remote system.  Try `handle %d ignore'.",
+          siggnal);
 
 #if 0
   dcache_flush ();
@@ -382,8 +392,13 @@ remote_resume (step, siggnal)
 /* Send ^C to target to halt it.  Target will respond, and send us a
    packet.  */
 
-void remote_interrupt()
+void remote_interrupt(signo)
+     int signo;
 {
+  
+  if (kiodebug)
+    printf ("remote_interrupt called\n");
+
   write (remote_desc, "\003", 1);      /* Send a ^C */
 }
 
@@ -399,23 +414,52 @@ remote_wait (status)
 {
   unsigned char buf[PBUFSIZ];
   void (*ofunc)();
-  
+  unsigned char *p;
+  int i;
+  int regno;
+  unsigned char regs[8];       /* Better be big enough for largest reg */
+
   WSETEXIT ((*status), 0);
 
-  ofunc = signal (SIGINT, remote_interrupt);
+  ofunc = (void (*)()) signal (SIGINT, remote_interrupt);
   getpkt ((char *) buf);
   signal (SIGINT, ofunc);
 
   if (buf[0] == 'E')
     error ("Remote failure reply: %s", buf);
-  if (buf[0] != 'S')
+  if (buf[0] == 'T')
+    {
+      /* Expedited reply, containing Signal, {regno, reg} repeat */
+      p = &buf[3];             /* after Txx */
+
+      while (*p)
+       {
+         regno = fromhex (p[0]) * 16 + fromhex (p[1]);
+         p += 2;
+         if (regno >= NUM_REGS)
+           error ("Remote sent illegal register number %d (0x%x)", regno,
+                  regno);
+
+         for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
+           {
+             if (p[0] == 0 || p[1] == 0)
+               error ("Remote reply is too short: %s", buf);
+             regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
+             p += 2;
+           }
+
+         supply_register (regno, regs);
+       }
+    }
+  else if (buf[0] != 'S')
     error ("Invalid remote reply: %s", buf);
+
   WSETSTOP ((*status), (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))));
+
   return 0;
 }
 
 /* Read the remote registers into the block REGS.  */
-
 /* Currently we just read all the registers, so we don't use regno.  */
 /* ARGSUSED */
 static void
@@ -621,10 +665,10 @@ remote_xfer_memory(memaddr, myaddr, len, should_write, target)
 }
 
 static void
-remote_files_info (target)
-struct target_ops *target;
+remote_files_info (ignore)
+struct target_ops *ignore;
 {
-  printf ("remote files info missing here.  FIXME.\n");
+  printf ("Debugging a target over a serial line.\n");
 }
 \f
 /*
@@ -654,7 +698,6 @@ Receiver responds with:
 static int
 readchar ()
 {
-  char buf;
   static int inbuf_index, inbuf_count;
 #define        INBUFSIZE       PBUFSIZ
   static char inbuf[INBUFSIZE];
@@ -733,19 +776,25 @@ putpkt (buf)
     if (kiodebug)
       {
        *p = '\0';
-       printf ("Sending packet: %s (%s)\n", buf2, buf);
+       printf ("Sending packet: %s...", buf2);  fflush(stdout);
       }
     write (remote_desc, buf2, p - buf2);
 
     /* read until either a timeout occurs (\0) or '+' is read */
     do {
       ch = readchar ();
+      if (kiodebug) {
+       if (ch == '+')
+         printf("Ack\n");
+       else
+         printf ("%02X%c ", ch&0xFF, ch);
+      }
     } while ((ch != '+') && (ch != '\0'));
   } while (ch != '+');
 }
 
 /* Read a packet from the remote machine, with error checking,
-   and store it in BUF.  */
+   and store it in BUF.  BUF is expected to be of size PBUFSIZ.  */
 
 static void
 getpkt (buf)
@@ -755,6 +804,8 @@ getpkt (buf)
   unsigned char csum;
   int c;
   unsigned char c1, c2;
+  int retries = 0;
+#define MAX_RETRIES    10
 
 #if 0
   /* Sorry, this will cause all hell to break loose, i.e. we'll end
@@ -784,6 +835,12 @@ getpkt (buf)
          c = readchar ();
          if (c == '#')
            break;
+         if (bp >= buf+PBUFSIZ-1)
+         {
+           *bp = '\0';
+           printf_filtered ("Remote packet too long: %s\n", buf);
+           goto whole;
+         }
          *bp++ = c;
          csum += c;
        }
@@ -793,9 +850,20 @@ getpkt (buf)
       c2 = fromhex (readchar ());
       if ((csum & 0xff) == (c1 << 4) + c2)
        break;
-      printf ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
+      printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
              (c1 << 4) + c2, csum & 0xff, buf);
-      write (remote_desc, "-", 1);
+
+      /* Try the whole thing again.  */
+whole:
+      if (++retries < MAX_RETRIES)
+       {
+         write (remote_desc, "-", 1);
+       }
+      else
+       {
+         printf ("Ignoring packet error, continuing...\n");
+         break;
+       }
     }
 
 #if 0
@@ -805,7 +873,7 @@ getpkt (buf)
   write (remote_desc, "+", 1);
 
   if (kiodebug)
-    fprintf (stderr,"Packet received :%s\n", buf);
+    fprintf (stderr,"Packet received%s\n", buf);
 }
 \f
 /* The data cache leads to incorrect results because it doesn't know about
@@ -1009,4 +1077,13 @@ void
 _initialize_remote ()
 {
   add_target (&remote_ops);
+
+  add_show_from_set (
+    add_set_cmd ("remotedebug", no_class, var_boolean, (char *)&kiodebug,
+                  "Set debugging of remote serial I/O.\n\
+When enabled, each packet sent or received with the remote target\n\
+is displayed.", &setlist),
+       &showlist);
 }
+
+#endif
This page took 0.027035 seconds and 4 git commands to generate.