* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[deliverable/binutils-gdb.git] / gdb / remote.c
index c2945adb8afccb418a295ce7e45a315c6a34f145..d3fef8ba12b440c4b283dec1875f3cb25909dd78 100644 (file)
@@ -133,6 +133,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "gdb-stabs.h"
 
 #include "dcache.h"
+#include "remote-utils.h"
 
 #if !defined(DONT_USE_REMOTE)
 #ifdef USG
@@ -293,20 +294,18 @@ device is attached to the remote system (e.g. /dev/ttya).");
   if (!remote_desc)
     perror_with_name (name);
 
-  if (baud_rate)
+  if (SERIAL_SETBAUDRATE (remote_desc, sr_get_baud_rate()))
     {
-      int rate;
-
-      if (sscanf (baud_rate, "%d", &rate) == 1)
-       if (SERIAL_SETBAUDRATE (remote_desc, rate))
-         {
-           SERIAL_CLOSE (remote_desc);
-           perror_with_name (name);
-         }
+      SERIAL_CLOSE (remote_desc);
+      perror_with_name (name);
     }
 
   SERIAL_RAW (remote_desc);
 
+  /* If there is something sitting in the buffer we might take it as a
+     response to a command, which would be bad.  */
+  SERIAL_FLUSH_INPUT (remote_desc);
+
   if (from_tty)
     {
       puts_filtered ("Remote debugging using ");
@@ -410,7 +409,7 @@ remote_interrupt (signo)
   /* If this doesn't work, try more severe steps.  */
   signal (signo, remote_interrupt_twice);
   
-  if (remote_debug)
+  if (sr_get_debug ())
     printf ("remote_interrupt called\n");
 
   SERIAL_WRITE (remote_desc, "\003", 1); /* Send a ^C */
@@ -538,8 +537,15 @@ remote_wait (status)
            {
              struct section_offsets *offs;
 
+             /* FIXME: This code assumes gdb-stabs.h is being used;
+                it's broken for xcoff, dwarf, sdb-coff, etc.  But
+                there is no simple canonical representation for this
+                stuff.  (Just what does "text" as seen by the stub
+                mean, anyway?).  */
+
              /* FIXME: Why don't the various symfile_offsets routines
-                in the sym_fns vectors set this?  */
+                in the sym_fns vectors set this?
+                (no good reason -kingdon).  */
              if (symfile_objfile->num_sections == 0)
                symfile_objfile->num_sections = SECT_OFF_MAX;
 
@@ -576,6 +582,9 @@ remote_wait (status)
   return 0;
 }
 
+/* Number of bytes of registers this stub implements.  */
+static int register_bytes_found;
+
 /* Read the remote registers into the block REGS.  */
 /* Currently we just read all the registers, so we don't use regno.  */
 /* ARGSUSED */
@@ -591,6 +600,9 @@ remote_fetch_registers (regno)
   sprintf (buf, "g");
   remote_send (buf);
 
+  /* Unimplemented registers read as all bits zero.  */
+  memset (regs, 0, REGISTER_BYTES);
+
   /* Reply describes registers byte by byte, each byte encoded as two
      hex characters.  Suck them all up, then supply them to the
      register cacheing/storage mechanism.  */
@@ -598,11 +610,29 @@ remote_fetch_registers (regno)
   p = buf;
   for (i = 0; i < REGISTER_BYTES; i++)
     {
-      if (p[0] == 0 || p[1] == 0)
-       error ("Remote reply is too short: %s", buf);
+      if (p[0] == 0)
+       break;
+      if (p[1] == 0)
+       {
+         warning ("Remote reply is of odd length: %s", buf);
+         /* Don't change register_bytes_found in this case, and don't
+            print a second warning.  */
+         goto supply_them;
+       }
       regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
       p += 2;
     }
+
+  if (i != register_bytes_found)
+    {
+      register_bytes_found = i;
+#ifdef REGISTER_BYTES_OK
+      if (!REGISTER_BYTES_OK (i))
+       warning ("Remote reply is too short: %s", buf);
+#endif
+    }
+
+ supply_them:
   for (i = 0; i < NUM_REGS; i++)
     supply_register (i, &regs[REGISTER_BYTE(i)]);
 }
@@ -635,7 +665,8 @@ remote_store_registers (regno)
      each byte encoded as two hex characters.  */
 
   p = buf + 1;
-  for (i = 0; i < REGISTER_BYTES; i++)
+  /* remote_prepare_to_store insures that register_bytes_found gets set.  */
+  for (i = 0; i < register_bytes_found; i++)
     {
       *p++ = tohex ((registers[i] >> 4) & 0xf);
       *p++ = tohex (registers[i] & 0xf);
@@ -909,7 +940,7 @@ putpkt (buf)
 
   while (1)
     {
-      if (remote_debug)
+      if (sr_get_debug ())
        {
          *p = '\0';
          printf ("Sending packet: %s...", buf2);  fflush(stdout);
@@ -925,7 +956,7 @@ putpkt (buf)
          switch (ch)
            {
            case '+':
-             if (remote_debug)
+             if (sr_get_debug ())
                printf("Ack\n");
              return;
            case SERIAL_TIMEOUT:
@@ -935,7 +966,7 @@ putpkt (buf)
            case SERIAL_EOF:
              error ("putpkt: EOF while trying to read ACK");
            default:
-             if (remote_debug)
+             if (sr_get_debug ())
                printf ("%02X %c ", ch&0xFF, ch);
              continue;
            }
@@ -976,7 +1007,7 @@ getpkt (buf, forever)
          if (forever)
            continue;
          if (++retries >= MAX_RETRIES)
-           if (remote_debug) puts_filtered ("Timed out.\n");
+           if (sr_get_debug ()) puts_filtered ("Timed out.\n");
          goto out;
        }
 
@@ -994,13 +1025,13 @@ getpkt (buf, forever)
          c = readchar ();
          if (c == SERIAL_TIMEOUT)
            {
-             if (remote_debug)
+             if (sr_get_debug ())
                puts_filtered ("Timeout in mid-packet, retrying\n");
              goto whole;               /* Start a new packet, count retries */
            } 
          if (c == '$')
            {
-             if (remote_debug)
+             if (sr_get_debug ())
                puts_filtered ("Saw new packet start in middle of old one\n");
              goto whole;               /* Start a new packet, count retries */
            }
@@ -1045,7 +1076,7 @@ out:
 
   SERIAL_WRITE (remote_desc, "+", 1);
 
-  if (remote_debug)
+  if (sr_get_debug ())
     fprintf (stderr,"Packet received: %s\n", buf);
 }
 \f
This page took 0.025302 seconds and 4 git commands to generate.