This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

sample stub patch: getpacket()


The enclosed patch cleans up the getpacket() routine used by all the
sample stubs distributed with GDB.

I began this when I noticed that getpacket() physically moves packet
contents when a checksum sequence is present.  This used strlen() to
determine the packet length, and (most of) the stubs did not provide
their own private strlen() implementation.  This, of course, results
in bad things happening if users set a breakpoint on strlen().

To eliminate both these problems, I decided to change getpacket() to
return a pointer to the first character in the packet.  In that way,
an entire packet can be read into a buffer, but only the protocol 
data portion returned to the application.

Another problem I addressed at this time was removing the & 0x7f's
that were masking the return value of getDebugChar().  This is needed
if support for binary memory writes added to those stubs without it.


As I write this up, I'm thinking that I may not have taken this far
enough.  remcomInBuffer is still passed to getpacket(), when the
packet buffer logic should be opaque to handle_exception().  The
packet data is null terminated, when getpacket() should probably
return a 'packet descriptor' with pointers to the physical begining
and end of the packet as well as pointers to the beggining and end of
RDP data.  I also noticed that none of the stubs handle run-length
encoding of packets from GDB (good thing GDB doesn't perform this
optimization), and none handle '$' (beginning of packet framing)
specially after a packet is being received.  Plenty of ideas for 
subsequent patches...

1999-08-17  J.T. Conklin  <jtc@redback.com>

	* i386-stub.c, m32r-stub.c, m68k-stub.c, sh-stub.c, sparc-stub.c,
 	sparcl-stub.c sparclet-stub.c (getpacket): Changed to return ptr
 	to first character of input buffer.  Removed & 0x7f masks.
	(handle_exception): Don't access remcomInBuffer directly.

Index: i386-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/i386-stub.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 i386-stub.c
*** i386-stub.c	1999/05/19 17:38:22	1.1.1.1
--- i386-stub.c	1999/08/17 02:53:55
***************
*** 458,522 ****
    return (-1);
  }
  
- 
  /* scan for the sequence $<data>#<checksum>     */
! void getpacket(buffer)
! char * buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
!   int  i;
!   int  count;
    char ch;
  
!   do {
!     /* wait around for the start character, ignore all other characters */
!     while ((ch = (getDebugChar() & 0x7f)) != '$');
!     checksum = 0;
!     xmitcsum = -1;
! 
!     count = 0;
! 
!     /* now, read until a # or end of buffer is found */
!     while (count < BUFMAX) {
!       ch = getDebugChar() & 0x7f;
!       if (ch == '#') break;
!       checksum = checksum + ch;
!       buffer[count] = ch;
!       count = count + 1;
!       }
!     buffer[count] = 0;
! 
!     if (ch == '#') {
!       xmitcsum = hex(getDebugChar() & 0x7f) << 4;
!       xmitcsum += hex(getDebugChar() & 0x7f);
!       if ((remote_debug ) && (checksum != xmitcsum)) {
!         fprintf (stderr ,"bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
! 		 checksum,xmitcsum,buffer);
!       }
! 
!       if (checksum != xmitcsum) putDebugChar('-');  /* failed checksum */
!       else {
! 	 putDebugChar('+');  /* successful transfer */
! 	 /* if a sequence char is present, reply the sequence ID */
! 	 if (buffer[2] == ':') {
! 	    putDebugChar( buffer[0] );
! 	    putDebugChar( buffer[1] );
! 	    /* remove sequence chars from buffer */
! 	    count = strlen(buffer);
! 	    for (i=3; i <= count; i++) buffer[i-3] = buffer[i];
! 	 }
!       }
      }
-   } while (checksum != xmitcsum);
- 
  }
  
  /* send the packet in buffer.  */
  
- 
  void putpacket(buffer)
! char * buffer;
  {
    unsigned char checksum;
    int  count;
--- 458,536 ----
    return (-1);
  }
  
  /* scan for the sequence $<data>#<checksum>     */
! 
! unsigned char *
! getpacket (buffer)
!      unsigned char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
!   int count;
    char ch;
  
!   while (1)
!     {
!       /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
! 	;
! 
!       checksum = 0;
!       xmitcsum = -1;
!       count = 0;
! 
!       /* now, read until a # or end of buffer is found */
!       while (count < BUFMAX)
! 	{
! 	  ch = getDebugChar ();
! 	  if (ch == '#')
! 	    break;
! 	  checksum = checksum + ch;
! 	  buffer[count] = ch;
! 	  count = count + 1;
! 	}
!       buffer[count] = 0;
! 
!       if (ch == '#')
! 	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
! 
! 	  if (checksum != xmitcsum)
! 	    {
! 	      if (remote_debug)
! 		{
! 		  fprintf (stderr,
! 		      "bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
! 			   checksum, xmitcsum, buffer);
! 		}
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
! 	  else
! 	    {
! 	      putDebugChar ('+');	/* successful transfer */
! 
! 	      /* if a sequence char is present, reply the sequence ID */
! 	      if (buffer[2] == ':')
! 		{
! 		  putDebugChar (buffer[0]);
! 		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
! 		}
! 
! 	      return &buffer[0];
! 	    }
! 	}
      }
  }
  
  /* send the packet in buffer.  */
  
  void putpacket(buffer)
!     unsigned char *buffer;
  {
    unsigned char checksum;
    int  count;
***************
*** 538,544 ****
    putDebugChar(hexchars[checksum >> 4]);
    putDebugChar(hexchars[checksum % 16]);
  
!   } while ((getDebugChar() & 0x7f) != '+');
  
  }
  
--- 552,558 ----
    putDebugChar(hexchars[checksum >> 4]);
    putDebugChar(hexchars[checksum % 16]);
  
!   } while (getDebugChar() != '+');
  
  }
  
***************
*** 700,706 ****
   */
  void handle_exception(int exceptionVector)
  {
!   int    sigval;
    int    addr, length;
    char * ptr;
    int    newPC;
--- 714,720 ----
   */
  void handle_exception(int exceptionVector)
  {
!   int    sigval, stepping;
    int    addr, length;
    char * ptr;
    int    newPC;
***************
*** 721,731 ****
  
    putpacket(remcomOutBuffer);
  
    while (1==1) {
      error = 0;
      remcomOutBuffer[0] = 0;
!     getpacket(remcomInBuffer);
!     switch (remcomInBuffer[0]) {
        case '?' :   remcomOutBuffer[0] = 'S';
                     remcomOutBuffer[1] =  hexchars[sigval >> 4];
                     remcomOutBuffer[2] =  hexchars[sigval % 16];
--- 735,748 ----
  
    putpacket(remcomOutBuffer);
  
+   stepping = 0;
+ 
    while (1==1) {
      error = 0;
      remcomOutBuffer[0] = 0;
!     ptr = getpacket(remcomInBuffer);
! 
!     switch (*ptr++) {
        case '?' :   remcomOutBuffer[0] = 'S';
                     remcomOutBuffer[1] =  hexchars[sigval >> 4];
                     remcomOutBuffer[2] =  hexchars[sigval % 16];
***************
*** 737,750 ****
                  mem2hex((char*) registers, remcomOutBuffer, NUMREGBYTES, 0);
                  break;
        case 'G' : /* set the value of the CPU registers - return OK */
!                 hex2mem(&remcomInBuffer[1], (char*) registers, NUMREGBYTES, 0);
                  strcpy(remcomOutBuffer,"OK");
                  break;
        case 'P' : /* set the value of a single CPU register - return OK */
                  {
                    int regno;
  
-                   ptr = &remcomInBuffer[1];
                    if (hexToInt (&ptr, &regno) && *ptr++ == '=') 
                    if (regno >= 0 && regno < NUMREGS)
                      {
--- 754,766 ----
                  mem2hex((char*) registers, remcomOutBuffer, NUMREGBYTES, 0);
                  break;
        case 'G' : /* set the value of the CPU registers - return OK */
!                 hex2mem(ptr, (char*) registers, NUMREGBYTES, 0);
                  strcpy(remcomOutBuffer,"OK");
                  break;
        case 'P' : /* set the value of a single CPU register - return OK */
                  {
                    int regno;
  
                    if (hexToInt (&ptr, &regno) && *ptr++ == '=') 
                    if (regno >= 0 && regno < NUMREGS)
                      {
***************
*** 760,766 ****
        /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
        case 'm' :
  		    /* TRY TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
-                     ptr = &remcomInBuffer[1];
                      if (hexToInt(&ptr,&addr))
                          if (*(ptr++) == ',')
                              if (hexToInt(&ptr,&length))
--- 776,781 ----
***************
*** 777,790 ****
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E01");
- 		      debug_error("malformed read memory command: %s",remcomInBuffer);
  		    }
  	          break;
  
        /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
        case 'M' :
  		    /* TRY TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
-                     ptr = &remcomInBuffer[1];
                      if (hexToInt(&ptr,&addr))
                          if (*(ptr++) == ',')
                              if (hexToInt(&ptr,&length))
--- 792,803 ----
***************
*** 805,820 ****
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E02");
- 		      debug_error("malformed write memory command: %s",remcomInBuffer);
  		    }
                  break;
  
       /* cAA..AA    Continue at address AA..AA(optional) */
       /* sAA..AA   Step one instruction from AA..AA(optional) */
-      case 'c' :
       case 's' :
            /* try to read optional parameter, pc unchanged if no parm */
-          ptr = &remcomInBuffer[1];
           if (hexToInt(&ptr,&addr))
               registers[ PC ] = addr;
  
--- 818,832 ----
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E02");
  		    }
                  break;
  
       /* cAA..AA    Continue at address AA..AA(optional) */
       /* sAA..AA   Step one instruction from AA..AA(optional) */
       case 's' :
+ 	 stepping = 1;
+      case 'c' :
            /* try to read optional parameter, pc unchanged if no parm */
           if (hexToInt(&ptr,&addr))
               registers[ PC ] = addr;
  
***************
*** 824,830 ****
            registers[ PS ] &= 0xfffffeff;
  
            /* set the trace bit if we're stepping */
!           if (remcomInBuffer[0] == 's') registers[ PS ] |= 0x100;
  
            /*
             * If we found a match for the PC AND we are not returning
--- 836,842 ----
            registers[ PS ] &= 0xfffffeff;
  
            /* set the trace bit if we're stepping */
!           if (stepping) registers[ PS ] |= 0x100;
  
            /*
             * If we found a match for the PC AND we are not returning
Index: m32r-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/m32r-stub.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 m32r-stub.c
*** m32r-stub.c	1999/05/19 17:38:26	1.1.1.1
--- m32r-stub.c	1999/08/17 02:54:17
***************
*** 179,185 ****
  
  static int  computeSignal(int);
  static void putpacket(unsigned char *);
! static void getpacket(unsigned char *);
  
  static unsigned char *mem2hex(unsigned char *, unsigned char *, int, int);
  static unsigned char *hex2mem(unsigned char *, unsigned char *, int, int);
--- 179,185 ----
  
  static int  computeSignal(int);
  static void putpacket(unsigned char *);
! static unsigned char *getpacket(unsigned char *);
  
  static unsigned char *mem2hex(unsigned char *, unsigned char *, int, int);
  static unsigned char *hex2mem(unsigned char *, unsigned char *, int, int);
***************
*** 204,210 ****
  void 
  handle_exception(int exceptionVector)
  {
!   int    sigval;
    int    addr, length, i;
    unsigned char * ptr;
    unsigned char   buf[16];
--- 204,210 ----
  void 
  handle_exception(int exceptionVector)
  {
!   int    sigval, stepping;
    int    addr, length, i;
    unsigned char * ptr;
    unsigned char   buf[16];
***************
*** 306,320 ****
  
    putpacket(remcomOutBuffer);
  
    while (1==1) {
      remcomOutBuffer[0] = 0;
!     getpacket(remcomInBuffer);
      binary = 0;
!     switch (remcomInBuffer[0]) {
        default:	/* Unknown code.  Return an empty reply message. */
  	break;
        case 'R':
- 	ptr = &remcomInBuffer[1];
  	if (hexToInt (&ptr, &addr))
  	  registers[PC] = addr;
  	strcpy(remcomOutBuffer, "OK");
--- 306,321 ----
  
    putpacket(remcomOutBuffer);
  
+   stepping = 0;
+ 
    while (1==1) {
      remcomOutBuffer[0] = 0;
!     ptr = getpacket(remcomInBuffer);
      binary = 0;
!     switch (*ptr++) {
        default:	/* Unknown code.  Return an empty reply message. */
  	break;
        case 'R':
  	if (hexToInt (&ptr, &addr))
  	  registers[PC] = addr;
  	strcpy(remcomOutBuffer, "OK");
***************
*** 327,333 ****
      case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
        /* TRY TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
        {
-         ptr = &remcomInBuffer[1];
          if (hexToInt(&ptr,&addr))
            if (*(ptr++) == ',')
              if (hexToInt(&ptr,&length))
--- 328,333 ----
***************
*** 349,362 ****
          if (ptr)
            {
              strcpy(remcomOutBuffer,"E02");
-             gdb_error("malformed write memory command: %s",
-                       remcomInBuffer);
            }
        }
  	break;
        case 'm': /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
  		/* TRY TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
- 	ptr = &remcomInBuffer[1];
  	if (hexToInt(&ptr,&addr))
  	  if (*(ptr++) == ',')
  	    if (hexToInt(&ptr,&length))
--- 349,359 ----
***************
*** 372,379 ****
  	if (ptr)
  	  {
  	    strcpy(remcomOutBuffer,"E01");
- 	    gdb_error("malformed read memory command: %s",
- 			remcomInBuffer);
  	  }
  	break;
        case '?': 
--- 369,374 ----
***************
*** 392,398 ****
  	{
  	  int regno;
  
- 	  ptr = &remcomInBuffer[1];
  	  if (hexToInt (&ptr, &regno) && *ptr++ == '=')
  	    if (regno >= 0 && regno < NUMREGS)
  	      {
--- 387,392 ----
***************
*** 435,451 ****
  	  break;
  	}
        case 'G': /* set the value of the CPU registers - return OK */
! 	hex2mem(&remcomInBuffer[1], (unsigned char*) registers, NUMREGBYTES, 0);
  	strcpy(remcomOutBuffer,"OK");
  	break;
        case 's': /* sAA..AA	Step one instruction from AA..AA(optional) */
        case 'c': /* cAA..AA	Continue from address AA..AA(optional) */
  		/* try to read optional parameter, pc unchanged if no parm */
- 	ptr = &remcomInBuffer[1];
  	if (hexToInt(&ptr,&addr))
  	  registers[ PC ] = addr;
  	
! 	if (remcomInBuffer[0] == 's')	/* single-stepping */
  	  {
  	    if (!prepare_to_step(0))	/* set up for single-step */
  	      {
--- 429,445 ----
  	  break;
  	}
        case 'G': /* set the value of the CPU registers - return OK */
! 	hex2mem(&ptr, (unsigned char*) registers, NUMREGBYTES, 0);
  	strcpy(remcomOutBuffer,"OK");
  	break;
        case 's': /* sAA..AA	Step one instruction from AA..AA(optional) */
+ 	stepping = 1;
        case 'c': /* cAA..AA	Continue from address AA..AA(optional) */
  		/* try to read optional parameter, pc unchanged if no parm */
  	if (hexToInt(&ptr,&addr))
  	  registers[ PC ] = addr;
  	
! 	if (stepping)	/* single-stepping */
  	  {
  	    if (!prepare_to_step(0))	/* set up for single-step */
  	      {
***************
*** 505,511 ****
  	break;
  #endif
      case 'q':
-       ptr = &remcomInBuffer[1];
        if (*ptr++ == 'C' &&
  	  *ptr++ == 'R' &&
  	  *ptr++ == 'C' &&
--- 499,504 ----
***************
*** 581,645 ****
  
  /* scan for the sequence $<data>#<checksum>     */
  
! static void 
! getpacket(buffer)
!      unsigned char * buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
!   int  i;
!   int  count;
!   unsigned char ch;
! 
!   do {
!     /* wait around for the start character, ignore all other characters */
!     while ((ch = getDebugChar()) != '$');
!     checksum = 0;
!     xmitcsum = -1;
! 
!     count = 0;
! 
!     /* now, read until a # or end of buffer is found */
!     while (count < BUFMAX) {
!       ch = getDebugChar();
!       
!       if (ch == '#' && (count == 0 || buffer[count-1] != 0x7d))
!         break;
! 
!       checksum = checksum + ch;
!       buffer[count] = ch;
!       count = count + 1;
!       }
!     buffer[count] = 0;
  
!     if (ch == '#') {
!       xmitcsum = hex(getDebugChar()) << 4;
!       xmitcsum += hex(getDebugChar());
!       if (checksum != xmitcsum) {
!         if (remote_debug) {
!           unsigned char buf[16];
! 
!           mem2hex((unsigned char *) &checksum, buf, 4, 0);
!           gdb_error("Bad checksum: my count = %s, ", buf);
!           mem2hex((unsigned char *) &xmitcsum, buf, 4, 0);
!           gdb_error("sent count = %s\n", buf);
!           gdb_error(" -- Bad buffer: \"%s\"\n", buffer); 
!         }
! 
!         putDebugChar('-');  /* failed checksum */
!       } else {
! 	putDebugChar('+');  /* successful transfer */
! 	/* if a sequence char is present, reply the sequence ID */
! 	if (buffer[2] == ':') {
! 	  putDebugChar( buffer[0] );
! 	  putDebugChar( buffer[1] );
! 	  /* remove sequence chars from buffer */
! 	  count = strlen(buffer);
! 	  for (i=3; i <= count; i++) buffer[i-3] = buffer[i];
  	}
-       }
      }
-   } while (checksum != xmitcsum);
  }
  
  /* send the packet in buffer.  */
--- 574,648 ----
  
  /* scan for the sequence $<data>#<checksum>     */
  
! unsigned char *
! getpacket (buffer)
!      unsigned char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
!   int count;
!   char ch;
  
!   while (1)
!     {
!       /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
! 	;
! 
!       checksum = 0;
!       xmitcsum = -1;
!       count = 0;
! 
!       /* now, read until a # or end of buffer is found */
!       while (count < BUFMAX)
! 	{
! 	  ch = getDebugChar ();
! 	  if (ch == '#')
! 	    break;
! 	  checksum = checksum + ch;
! 	  buffer[count] = ch;
! 	  count = count + 1;
! 	}
!       buffer[count] = 0;
! 
!       if (ch == '#')
! 	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
! 
! 	  if (checksum != xmitcsum)
! 	    {
! 	      if (remote_debug)
! 		{
! 		  unsigned char buf[16];
! 
! 		  mem2hex((unsigned char *) &checksum, buf, 4, 0);
! 		  gdb_error("Bad checksum: my count = %s, ", buf);
! 		  mem2hex((unsigned char *) &xmitcsum, buf, 4, 0);
! 		  gdb_error("sent count = %s\n", buf);
! 		  gdb_error(" -- Bad buffer: \"%s\"\n", buffer); 
! 		}
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
! 	  else
! 	    {
! 	      putDebugChar ('+');	/* successful transfer */
! 
! 	      /* if a sequence char is present, reply the sequence ID */
! 	      if (buffer[2] == ':')
! 		{
! 		  putDebugChar (buffer[0]);
! 		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
! 		}
! 
! 	      return &buffer[0];
! 	    }
  	}
      }
  }
  
  /* send the packet in buffer.  */
Index: m68k-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/m68k-stub.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 m68k-stub.c
*** m68k-stub.c	1999/05/19 17:38:26	1.1.1.1
--- m68k-stub.c	1999/08/17 02:54:47
***************
*** 522,585 ****
    return (-1);
  }
  
- 
  /* scan for the sequence $<data>#<checksum>     */
! void getpacket(buffer)
! char * buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
!   int  i;
!   int  count;
    char ch;
-   
-   do {
-     /* wait around for the start character, ignore all other characters */
-     while ((ch = (getDebugChar() & 0x7f)) != '$'); 
-     checksum = 0;
-     xmitcsum = -1;
-     
-     count = 0;
-     
-     /* now, read until a # or end of buffer is found */
-     while (count < BUFMAX) {
-       ch = getDebugChar() & 0x7f;
-       if (ch == '#') break;
-       checksum = checksum + ch;
-       buffer[count] = ch;
-       count = count + 1;
-       }
-     buffer[count] = 0;
  
!     if (ch == '#') {
!       xmitcsum = hex(getDebugChar() & 0x7f) << 4;
!       xmitcsum += hex(getDebugChar() & 0x7f);
!       if ((remote_debug ) && (checksum != xmitcsum)) {
!         fprintf (stderr,"bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
! 						     checksum,xmitcsum,buffer);
!       }
!       
!       if (checksum != xmitcsum) putDebugChar('-');  /* failed checksum */ 
!       else {
! 	 putDebugChar('+');  /* successful transfer */
! 	 /* if a sequence char is present, reply the sequence ID */
! 	 if (buffer[2] == ':') {
! 	    putDebugChar( buffer[0] );
! 	    putDebugChar( buffer[1] );
! 	    /* remove sequence chars from buffer */
! 	    count = strlen(buffer);
! 	    for (i=3; i <= count; i++) buffer[i-3] = buffer[i];
! 	 } 
!       } 
!     } 
!   } while (checksum != xmitcsum);
!   
  }
  
  /* send the packet in buffer.  The host get's one chance to read it.  
     This routine does not wait for a positive acknowledge.  */
  
- 
  void putpacket(buffer)
  char * buffer;
  {
--- 522,599 ----
    return (-1);
  }
  
  /* scan for the sequence $<data>#<checksum>     */
! 
! unsigned char *
! getpacket (buffer)
!      unsigned char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
!   int count;
    char ch;
  
!   while (1)
!     {
!       /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
! 	;
! 
!       checksum = 0;
!       xmitcsum = -1;
!       count = 0;
! 
!       /* now, read until a # or end of buffer is found */
!       while (count < BUFMAX)
! 	{
! 	  ch = getDebugChar ();
! 	  if (ch == '#')
! 	    break;
! 	  checksum = checksum + ch;
! 	  buffer[count] = ch;
! 	  count = count + 1;
! 	}
!       buffer[count] = 0;
! 
!       if (ch == '#')
! 	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
! 
! 	  if (checksum != xmitcsum)
! 	    {
! 	      if (remote_debug)
! 		{
! 		  fprintf (stderr,
! 		      "bad checksum.  My count = 0x%x, sent=0x%x. buf=%s\n",
! 			   checksum, xmitcsum, buffer);
! 		}
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
! 	  else
! 	    {
! 	      putDebugChar ('+');	/* successful transfer */
! 
! 	      /* if a sequence char is present, reply the sequence ID */
! 	      if (buffer[2] == ':')
! 		{
! 		  putDebugChar (buffer[0]);
! 		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
! 		}
! 
! 	      return &buffer[0];
! 	    }
! 	}
!     }
  }
  
  /* send the packet in buffer.  The host get's one chance to read it.  
     This routine does not wait for a positive acknowledge.  */
  
  void putpacket(buffer)
  char * buffer;
  {
***************
*** 739,745 ****
   */
  void handle_exception(int exceptionVector)
  {
!   int    sigval;
    int    addr, length;
    char * ptr;
    int    newPC;
--- 753,759 ----
   */
  void handle_exception(int exceptionVector)
  {
!   int    sigval, stepping;
    int    addr, length;
    char * ptr;
    int    newPC;
***************
*** 759,769 ****
  
    putpacket(remcomOutBuffer); 
  
    while (1==1) { 
      error = 0;
      remcomOutBuffer[0] = 0;
!     getpacket(remcomInBuffer);
!     switch (remcomInBuffer[0]) {
        case '?' :   remcomOutBuffer[0] = 'S';
                     remcomOutBuffer[1] =  hexchars[sigval >> 4];
                     remcomOutBuffer[2] =  hexchars[sigval % 16];
--- 773,785 ----
  
    putpacket(remcomOutBuffer); 
  
+   stepping = 0;
+ 
    while (1==1) { 
      error = 0;
      remcomOutBuffer[0] = 0;
!     ptr = getpacket(remcomInBuffer);
!     switch (*ptr++) {
        case '?' :   remcomOutBuffer[0] = 'S';
                     remcomOutBuffer[1] =  hexchars[sigval >> 4];
                     remcomOutBuffer[2] =  hexchars[sigval % 16];
***************
*** 775,781 ****
                  mem2hex((char*) registers, remcomOutBuffer, NUMREGBYTES);
                  break;
        case 'G' : /* set the value of the CPU registers - return OK */
!                 hex2mem(&remcomInBuffer[1], (char*) registers, NUMREGBYTES);
                  strcpy(remcomOutBuffer,"OK");
                  break;
        
--- 791,797 ----
                  mem2hex((char*) registers, remcomOutBuffer, NUMREGBYTES);
                  break;
        case 'G' : /* set the value of the CPU registers - return OK */
!                 hex2mem(&ptr, (char*) registers, NUMREGBYTES);
                  strcpy(remcomOutBuffer,"OK");
                  break;
        
***************
*** 786,792 ****
                      exceptionHandler(2,handle_buserror); 
  
  		    /* TRY TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
-                     ptr = &remcomInBuffer[1];
                      if (hexToInt(&ptr,&addr))
                          if (*(ptr++) == ',')
                              if (hexToInt(&ptr,&length)) 
--- 802,807 ----
***************
*** 798,811 ****
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E01");
! 		      debug_error("malformed read memory command: %s",remcomInBuffer);
!                   }     
!                 } 
! 		else {
  		  exceptionHandler(2,_catchException);   
  		  strcpy(remcomOutBuffer,"E03");
  		  debug_error("bus error");
! 		  }     
                  
  		/* restore handler for bus error */
  		exceptionHandler(2,_catchException);   
--- 813,824 ----
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E01");
!                     }     
!                 } else {
  		  exceptionHandler(2,_catchException);   
  		  strcpy(remcomOutBuffer,"E03");
  		  debug_error("bus error");
! 		}     
                  
  		/* restore handler for bus error */
  		exceptionHandler(2,_catchException);   
***************
*** 817,823 ****
  		    exceptionHandler(2,handle_buserror); 
                      
  		    /* TRY TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
-                     ptr = &remcomInBuffer[1];
                      if (hexToInt(&ptr,&addr))
                          if (*(ptr++) == ',')
                              if (hexToInt(&ptr,&length))
--- 830,835 ----
***************
*** 830,843 ****
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E02");
! 		      debug_error("malformed write memory command: %s",remcomInBuffer);
! 		      }     
!                 } 
! 		else {
  		  exceptionHandler(2,_catchException);   
  		  strcpy(remcomOutBuffer,"E03");
  		  debug_error("bus error");
! 		  }     
  
                  /* restore handler for bus error */
                  exceptionHandler(2,_catchException);   
--- 842,853 ----
                      if (ptr)
                      {
  		      strcpy(remcomOutBuffer,"E02");
! 		    }     
!                 } else {
  		  exceptionHandler(2,_catchException);   
  		  strcpy(remcomOutBuffer,"E03");
  		  debug_error("bus error");
! 		}     
  
                  /* restore handler for bus error */
                  exceptionHandler(2,_catchException);   
***************
*** 845,854 ****
       
       /* cAA..AA    Continue at address AA..AA(optional) */
       /* sAA..AA   Step one instruction from AA..AA(optional) */
-      case 'c' : 
       case 's' : 
            /* try to read optional parameter, pc unchanged if no parm */
-          ptr = &remcomInBuffer[1];
           if (hexToInt(&ptr,&addr))
               registers[ PC ] = addr;
               
--- 855,864 ----
       
       /* cAA..AA    Continue at address AA..AA(optional) */
       /* sAA..AA   Step one instruction from AA..AA(optional) */
       case 's' : 
+ 	 stepping = 1;
+      case 'c' : 
            /* try to read optional parameter, pc unchanged if no parm */
           if (hexToInt(&ptr,&addr))
               registers[ PC ] = addr;
               
***************
*** 858,864 ****
            registers[ PS ] &= 0x7fff;
            
            /* set the trace bit if we're stepping */
!           if (remcomInBuffer[0] == 's') registers[ PS ] |= 0x8000;
            
            /*
             * look for newPC in the linked list of exception frames.
--- 868,874 ----
            registers[ PS ] &= 0x7fff;
            
            /* set the trace bit if we're stepping */
!           if (stepping) registers[ PS ] |= 0x8000;
            
            /*
             * look for newPC in the linked list of exception frames.
Index: sh-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sh-stub.c,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 sh-stub.c
*** sh-stub.c	1999/05/28 18:14:04	1.1.1.2
--- sh-stub.c	1999/08/17 02:55:24
***************
*** 199,205 ****
  static char *mem2hex (char *, char *, int);
  static char *hex2mem (char *, char *, int);
  static int hexToInt (char **, int *);
! static void getpacket (char *);
  static void putpacket (char *);
  static void handle_buserror (void);
  static int computeSignal (int exceptionVector);
--- 199,205 ----
  static char *mem2hex (char *, char *, int);
  static char *hex2mem (char *, char *, int);
  static int hexToInt (char **, int *);
! static unsigned char *getpacket (unsigned char *);
  static void putpacket (char *);
  static void handle_buserror (void);
  static int computeSignal (int exceptionVector);
***************
*** 382,403 ****
  
  /* scan for the sequence $<data>#<checksum>     */
  
! static
! void
! getpacket (char *buffer)
  {
    unsigned char checksum;
    unsigned char xmitcsum;
    int i;
    int count;
    char ch;
!   do
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$');
        checksum = 0;
        xmitcsum = -1;
- 
        count = 0;
  
        /* now, read until a # or end of buffer is found */
--- 382,405 ----
  
  /* scan for the sequence $<data>#<checksum>     */
  
! char *
! getpacket (buffer)
!      char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
    int i;
    int count;
    char ch;
! 
!   while (1)
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
! 	;
! 
        checksum = 0;
        xmitcsum = -1;
        count = 0;
  
        /* now, read until a # or end of buffer is found */
***************
*** 414,444 ****
  
        if (ch == '#')
  	{
! 	  xmitcsum = hex (getDebugChar ()) << 4;
! 	  xmitcsum += hex (getDebugChar ());
  	  if (checksum != xmitcsum)
! 	    putDebugChar ('-');	/* failed checksum */
  	  else
  	    {
  	      putDebugChar ('+');	/* successful transfer */
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
  		  putDebugChar (buffer[0]);
  		  putDebugChar (buffer[1]);
! 		  /* remove sequence chars from buffer */
! 		  count = strlen (buffer);
! 		  for (i = 3; i <= count; i++)
! 		    buffer[i - 3] = buffer[i];
  		}
  	    }
  	}
      }
-   while (checksum != xmitcsum);
- 
  }
  
- 
  /* send the packet in buffer.  The host get's one chance to read it.
     This routine does not wait for a positive acknowledge.  */
  
--- 416,449 ----
  
        if (ch == '#')
  	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
! 
  	  if (checksum != xmitcsum)
! 	    {
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
  	  else
  	    {
  	      putDebugChar ('+');	/* successful transfer */
+ 
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
  		  putDebugChar (buffer[0]);
  		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
  		}
+ 
+ 	      return &buffer[0];
  	    }
  	}
      }
  }
  
  /* send the packet in buffer.  The host get's one chance to read it.
     This routine does not wait for a positive acknowledge.  */
  
***************
*** 493,499 ****
        putDebugChar (lowhex(checksum));
      }
    while  (getDebugChar() != '+');
- 
  }
  
  
--- 498,503 ----
***************
*** 649,655 ****
  void
  gdb_handle_exception (int exceptionVector)
  {
!   int sigval;
    int addr, length;
    char *ptr;
  
--- 653,659 ----
  void
  gdb_handle_exception (int exceptionVector)
  {
!   int sigval, stepping;
    int addr, length;
    char *ptr;
  
***************
*** 678,689 ****
     */
    undoSStep ();
  
    while (1)
      {
        remcomOutBuffer[0] = 0;
!       getpacket (remcomInBuffer);
  
!       switch (remcomInBuffer[0])
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
--- 682,695 ----
     */
    undoSStep ();
  
+   stepping = 0;
+ 
    while (1)
      {
        remcomOutBuffer[0] = 0;
!       ptr = getpacket (remcomInBuffer);
  
!       switch (*ptr++)
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
***************
*** 698,704 ****
  	  mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES);
  	  break;
  	case 'G':		/* set the value of the CPU registers - return OK */
! 	  hex2mem (&remcomInBuffer[1], (char *) registers, NUMREGBYTES);
  	  strcpy (remcomOutBuffer, "OK");
  	  break;
  
--- 704,710 ----
  	  mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES);
  	  break;
  	case 'G':		/* set the value of the CPU registers - return OK */
! 	  hex2mem (&ptr, (char *) registers, NUMREGBYTES);
  	  strcpy (remcomOutBuffer, "OK");
  	  break;
  
***************
*** 708,714 ****
  	    {
  	      dofault = 0;
  	      /* TRY, TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
- 	      ptr = &remcomInBuffer[1];
  	      if (hexToInt (&ptr, &addr))
  		if (*(ptr++) == ',')
  		  if (hexToInt (&ptr, &length))
--- 714,719 ----
***************
*** 733,739 ****
  	      dofault = 0;
  
  	      /* TRY, TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
- 	      ptr = &remcomInBuffer[1];
  	      if (hexToInt (&ptr, &addr))
  		if (*(ptr++) == ',')
  		  if (hexToInt (&ptr, &length))
--- 738,743 ----
***************
*** 755,769 ****
  
  	  /* cAA..AA    Continue at address AA..AA(optional) */
  	  /* sAA..AA   Step one instruction from AA..AA(optional) */
- 	case 'c':
  	case 's':
  	  {
  	    /* tRY, to read optional parameter, pc unchanged if no parm */
- 	    ptr = &remcomInBuffer[1];
  	    if (hexToInt (&ptr, &addr))
  	      registers[PC] = addr;
  
! 	    if (remcomInBuffer[0] == 's')
  	      doSStep ();
  	  }
  	  return;
--- 759,773 ----
  
  	  /* cAA..AA    Continue at address AA..AA(optional) */
  	  /* sAA..AA   Step one instruction from AA..AA(optional) */
  	case 's':
+ 	  stepping = 1;
+ 	case 'c':
  	  {
  	    /* tRY, to read optional parameter, pc unchanged if no parm */
  	    if (hexToInt (&ptr, &addr))
  	      registers[PC] = addr;
  
! 	    if (stepping)
  	      doSStep ();
  	  }
  	  return;
Index: sparc-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sparc-stub.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 sparc-stub.c
*** sparc-stub.c	1999/05/19 17:38:37	1.1.1.1
--- sparc-stub.c	1999/08/17 02:55:48
***************
*** 286,355 ****
  
  /* scan for the sequence $<data>#<checksum>     */
  
! static void
! getpacket(buffer)
!      char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
-   int i;
    int count;
!   unsigned char ch;
  
!   do
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = (getDebugChar() & 0x7f)) != '$') ;
  
        checksum = 0;
        xmitcsum = -1;
- 
        count = 0;
  
        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
  	{
! 	  ch = getDebugChar() & 0x7f;
  	  if (ch == '#')
  	    break;
  	  checksum = checksum + ch;
  	  buffer[count] = ch;
  	  count = count + 1;
  	}
- 
-       if (count >= BUFMAX)
- 	continue;
- 
        buffer[count] = 0;
  
        if (ch == '#')
  	{
! 	  xmitcsum = hex(getDebugChar() & 0x7f) << 4;
! 	  xmitcsum |= hex(getDebugChar() & 0x7f);
! #if 0
! 	  /* Humans shouldn't have to figure out checksums to type to it. */
! 	  putDebugChar ('+');
! 	  return;
! #endif
  	  if (checksum != xmitcsum)
! 	    putDebugChar('-');	/* failed checksum */
  	  else
  	    {
! 	      putDebugChar('+'); /* successful transfer */
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
! 		  putDebugChar(buffer[0]);
! 		  putDebugChar(buffer[1]);
! 		  /* remove sequence chars from buffer */
! 		  count = strlen(buffer);
! 		  for (i=3; i <= count; i++)
! 		    buffer[i-3] = buffer[i];
  		}
  	    }
  	}
      }
-   while (checksum != xmitcsum);
  }
  
  /* send the packet in buffer.  */
--- 286,350 ----
  
  /* scan for the sequence $<data>#<checksum>     */
  
! unsigned char *
! getpacket (buffer)
!      unsigned char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
    int count;
!   char ch;
  
!   while (1)
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
! 	;
  
        checksum = 0;
        xmitcsum = -1;
        count = 0;
  
        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
  	{
! 	  ch = getDebugChar ();
  	  if (ch == '#')
  	    break;
  	  checksum = checksum + ch;
  	  buffer[count] = ch;
  	  count = count + 1;
  	}
        buffer[count] = 0;
  
        if (ch == '#')
  	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
! 
  	  if (checksum != xmitcsum)
! 	    {
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
  	  else
  	    {
! 	      putDebugChar ('+');	/* successful transfer */
! 
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
! 		  putDebugChar (buffer[0]);
! 		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
  		}
+ 
+ 	      return &buffer[0];
  	    }
  	}
      }
  }
  
  /* send the packet in buffer.  */
***************
*** 381,387 ****
        putDebugChar(hexchars[checksum & 0xf]);
  
      }
!   while ((getDebugChar() & 0x7f) != '+');
  }
  
  static char remcomInBuffer[BUFMAX];
--- 376,382 ----
        putDebugChar(hexchars[checksum & 0xf]);
  
      }
!   while (getDebugChar() != '+');
  }
  
  static char remcomInBuffer[BUFMAX];
***************
*** 660,667 ****
      {
        remcomOutBuffer[0] = 0;
  
!       getpacket(remcomInBuffer);
!       switch (remcomInBuffer[0])
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
--- 655,662 ----
      {
        remcomOutBuffer[0] = 0;
  
!       ptr = getpacket(remcomInBuffer);
!       switch (*ptr++)
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
***************
*** 670,677 ****
  	  remcomOutBuffer[3] = 0;
  	  break;
  
! 	case 'd':
! 				/* toggle debug flag */
  	  break;
  
  	case 'g':		/* return the value of the CPU registers */
--- 665,671 ----
  	  remcomOutBuffer[3] = 0;
  	  break;
  
! 	case 'd':		/* toggle debug flag */
  	  break;
  
  	case 'g':		/* return the value of the CPU registers */
***************
*** 693,699 ****
  
  	    psr = registers[PSR];
  
- 	    ptr = &remcomInBuffer[1];
  	    hex2mem(ptr, (char *)registers, 16 * 4, 0); /* G & O regs */
  	    hex2mem(ptr + 16 * 4 * 2, sp + 0, 16 * 4, 0); /* L & I regs */
  	    hex2mem(ptr + 64 * 4 * 2, (char *)&registers[Y],
--- 687,692 ----
***************
*** 719,726 ****
  	case 'm':	  /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
  	  /* Try to read %x,%x.  */
  
- 	  ptr = &remcomInBuffer[1];
- 
  	  if (hexToInt(&ptr, &addr)
  	      && *ptr++ == ','
  	      && hexToInt(&ptr, &length))
--- 712,717 ----
***************
*** 737,744 ****
  	case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
  	  /* Try to read '%x,%x:'.  */
  
- 	  ptr = &remcomInBuffer[1];
- 
  	  if (hexToInt(&ptr, &addr)
  	      && *ptr++ == ','
  	      && hexToInt(&ptr, &length)
--- 728,733 ----
***************
*** 756,762 ****
  	case 'c':    /* cAA..AA    Continue at address AA..AA(optional) */
  	  /* try to read optional parameter, pc unchanged if no parm */
  
- 	  ptr = &remcomInBuffer[1];
  	  if (hexToInt(&ptr, &addr))
  	    {
  	      registers[PC] = addr;
--- 745,750 ----
***************
*** 792,798 ****
  	    int baudrate;
  	    extern void set_timer_3();
  
- 	    ptr = &remcomInBuffer[1];
  	    if (!hexToInt(&ptr, &baudrate))
  	      {
  		strcpy(remcomOutBuffer,"B01");
--- 780,785 ----
Index: sparcl-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sparcl-stub.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 sparcl-stub.c
*** sparcl-stub.c	1999/05/19 17:38:38	1.1.1.1
--- sparcl-stub.c	1999/08/17 02:56:10
***************
*** 136,151 ****
     nasty interactions between app code and the stub (for instance if user steps
     into strlen, etc..) */
  
- static int
- strlen (const char *s)
- {
-   const char *s1 = s;
- 
-   while (*s1++ != '\000');
- 
-   return s1 - s;
- }
- 
  static char *
  strcpy (char *dst, const char *src)
  {
--- 136,141 ----
***************
*** 392,461 ****
  
  /* scan for the sequence $<data>#<checksum>     */
  
! static void
! getpacket(buffer)
!      char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
-   int i;
    int count;
!   unsigned char ch;
  
!   do
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = (getDebugChar() & 0x7f)) != '$') ;
  
        checksum = 0;
        xmitcsum = -1;
- 
        count = 0;
  
        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
  	{
! 	  ch = getDebugChar() & 0x7f;
  	  if (ch == '#')
  	    break;
  	  checksum = checksum + ch;
  	  buffer[count] = ch;
  	  count = count + 1;
  	}
- 
-       if (count >= BUFMAX)
- 	continue;
- 
        buffer[count] = 0;
  
        if (ch == '#')
  	{
! 	  xmitcsum = hex(getDebugChar() & 0x7f) << 4;
! 	  xmitcsum |= hex(getDebugChar() & 0x7f);
! #if 0
! 	  /* Humans shouldn't have to figure out checksums to type to it. */
! 	  putDebugChar ('+');
! 	  return;
! #endif
  	  if (checksum != xmitcsum)
! 	    putDebugChar('-');	/* failed checksum */
  	  else
  	    {
! 	      putDebugChar('+'); /* successful transfer */
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
! 		  putDebugChar(buffer[0]);
! 		  putDebugChar(buffer[1]);
! 		  /* remove sequence chars from buffer */
! 		  count = strlen(buffer);
! 		  for (i=3; i <= count; i++)
! 		    buffer[i-3] = buffer[i];
  		}
  	    }
  	}
      }
-   while (checksum != xmitcsum);
  }
  
  /* send the packet in buffer.  */
--- 382,446 ----
  
  /* scan for the sequence $<data>#<checksum>     */
  
! unsigned char *
! getpacket (buffer)
!      unsigned char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
    int count;
!   char ch;
  
!   while (1)
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
! 	;
  
        checksum = 0;
        xmitcsum = -1;
        count = 0;
  
        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
  	{
! 	  ch = getDebugChar ();
  	  if (ch == '#')
  	    break;
  	  checksum = checksum + ch;
  	  buffer[count] = ch;
  	  count = count + 1;
  	}
        buffer[count] = 0;
  
        if (ch == '#')
  	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
! 
  	  if (checksum != xmitcsum)
! 	    {
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
  	  else
  	    {
! 	      putDebugChar ('+');	/* successful transfer */
! 
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
! 		  putDebugChar (buffer[0]);
! 		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
  		}
+ 
+ 	      return &buffer[0];
  	    }
  	}
      }
  }
  
  /* send the packet in buffer.  */
***************
*** 487,493 ****
        putDebugChar(hexchars[checksum & 0xf]);
  
      }
!   while ((getDebugChar() & 0x7f) != '+');
  }
  
  static char remcomInBuffer[BUFMAX];
--- 472,478 ----
        putDebugChar(hexchars[checksum & 0xf]);
  
      }
!   while (getDebugChar() != '+');
  }
  
  static char remcomInBuffer[BUFMAX];
***************
*** 813,820 ****
      {
        remcomOutBuffer[0] = 0;
  
!       getpacket(remcomInBuffer);
!       switch (remcomInBuffer[0])
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
--- 798,805 ----
      {
        remcomOutBuffer[0] = 0;
  
!       ptr = getpacket(remcomInBuffer);
!       switch (*ptr++)
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
***************
*** 839,847 ****
  
  	    psr = registers[PSR];
  
! 	    ptr = &remcomInBuffer[1];
! 
! 	    if (remcomInBuffer[0] == 'P')
  	      {
  		int regno;
  
--- 824,830 ----
  
  	    psr = registers[PSR];
  
! 	    if (ptr[-1] == 'P')
  	      {
  		int regno;
  
***************
*** 883,890 ****
  	case 'm':	  /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
  	  /* Try to read %x,%x.  */
  
- 	  ptr = &remcomInBuffer[1];
- 
  	  if (hexToInt(&ptr, &addr)
  	      && *ptr++ == ','
  	      && hexToInt(&ptr, &length))
--- 866,871 ----
***************
*** 901,908 ****
  	case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
  	  /* Try to read '%x,%x:'.  */
  
- 	  ptr = &remcomInBuffer[1];
- 
  	  if (hexToInt(&ptr, &addr)
  	      && *ptr++ == ','
  	      && hexToInt(&ptr, &length)
--- 882,887 ----
***************
*** 919,926 ****
  
  	case 'c':    /* cAA..AA    Continue at address AA..AA(optional) */
  	  /* try to read optional parameter, pc unchanged if no parm */
- 
- 	  ptr = &remcomInBuffer[1];
  	  if (hexToInt(&ptr, &addr))
  	    {
  	      registers[PC] = addr;
--- 898,903 ----
***************
*** 970,976 ****
  	    int baudrate;
  	    extern void set_timer_3();
  
- 	    ptr = &remcomInBuffer[1];
  	    if (!hexToInt(&ptr, &baudrate))
  	      {
  		strcpy(remcomOutBuffer,"B01");
--- 947,952 ----
Index: sparclet-stub.c
===================================================================
RCS file: /home/jtc/CVSROOT/gdb/gdb/sparclet-stub.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 sparclet-stub.c
*** sparclet-stub.c	1999/05/19 17:38:38	1.1.1.1
--- sparclet-stub.c	1999/08/17 02:56:32
***************
*** 452,518 ****
  
  /* scan for the sequence $<data>#<checksum>     */
  
! static void
! getpacket(buffer)
!      char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
-   int i;
    int count;
!   unsigned char ch;
  
!   do
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = (getDebugChar() & 0x7f)) != '$') 
  	;
  
        checksum = 0;
        xmitcsum = -1;
- 
        count = 0;
  
        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
  	{
! 	  ch = getDebugChar() & 0x7f;
  	  if (ch == '#')
  	    break;
  	  checksum = checksum + ch;
  	  buffer[count] = ch;
  	  count = count + 1;
  	}
- 
-       if (count >= BUFMAX)
- 	continue;
- 
        buffer[count] = 0;
  
        if (ch == '#')
  	{
! 	  xmitcsum = hex(ch = getDebugChar() & 0x7f) << 4;
! 	  xmitcsum |= hex(ch = getDebugChar() & 0x7f);
  
  	  if (checksum != xmitcsum)
! 	    putDebugChar('-');	/* failed checksum */
  	  else
  	    {
! 	      putDebugChar('+'); /* successful transfer */
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
! 		  putDebugChar(buffer[0]);
! 		  putDebugChar(buffer[1]);
! 		  /* remove sequence chars from buffer */
! 		  count = strlen(buffer);
! 		  for (i=3; i <= count; i++)
! 		    buffer[i-3] = buffer[i];
  		}
  	    }
  	}
      }
-   while (checksum != xmitcsum);
  }
  
  /* send the packet in buffer.  */
--- 452,516 ----
  
  /* scan for the sequence $<data>#<checksum>     */
  
! unsigned char *
! getpacket (buffer)
!      unsigned char *buffer;
  {
    unsigned char checksum;
    unsigned char xmitcsum;
    int count;
!   char ch;
  
!   while (1)
      {
        /* wait around for the start character, ignore all other characters */
!       while ((ch = getDebugChar ()) != '$')
  	;
  
        checksum = 0;
        xmitcsum = -1;
        count = 0;
  
        /* now, read until a # or end of buffer is found */
        while (count < BUFMAX)
  	{
! 	  ch = getDebugChar ();
  	  if (ch == '#')
  	    break;
  	  checksum = checksum + ch;
  	  buffer[count] = ch;
  	  count = count + 1;
  	}
        buffer[count] = 0;
  
        if (ch == '#')
  	{
! 	  ch = getDebugChar ();
! 	  xmitcsum = hex (ch) << 4;
! 	  ch = getDebugChar ();
! 	  xmitcsum += hex (ch);
  
  	  if (checksum != xmitcsum)
! 	    {
! 	      putDebugChar ('-');	/* failed checksum */
! 	    }
  	  else
  	    {
! 	      putDebugChar ('+');	/* successful transfer */
! 
  	      /* if a sequence char is present, reply the sequence ID */
  	      if (buffer[2] == ':')
  		{
! 		  putDebugChar (buffer[0]);
! 		  putDebugChar (buffer[1]);
! 
! 		  return &buffer[3];
  		}
+ 
+ 	      return &buffer[0];
  	    }
  	}
      }
  }
  
  /* send the packet in buffer.  */
***************
*** 544,550 ****
        putDebugChar(hexchars[checksum & 0xf]);
  
      }
!   while ((getDebugChar() & 0x7f) != '+');
  }
  
  static char remcomInBuffer[BUFMAX];
--- 542,548 ----
        putDebugChar(hexchars[checksum & 0xf]);
  
      }
!   while (getDebugChar() != '+');
  }
  
  static char remcomInBuffer[BUFMAX];
***************
*** 884,891 ****
      {
        remcomOutBuffer[0] = 0;
  
!       getpacket(remcomInBuffer);
!       switch (remcomInBuffer[0])
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
--- 882,889 ----
      {
        remcomOutBuffer[0] = 0;
  
!       ptr = getpacket(remcomInBuffer);
!       switch (*ptr++)
  	{
  	case '?':
  	  remcomOutBuffer[0] = 'S';
***************
*** 932,940 ****
  
  	    psr = registers[PSR];
  
! 	    ptr = &remcomInBuffer[1];
! 
! 	    if (remcomInBuffer[0] == 'P')	/* do a single register */
  	      {
  		int regno;
   
--- 930,936 ----
  
  	    psr = registers[PSR];
  
! 	    if (ptr[-1] == 'P')	/* do a single register */
  	      {
  		int regno;
   
***************
*** 985,992 ****
  	case 'm':	  /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
  	  /* Try to read %x,%x.  */
  
- 	  ptr = &remcomInBuffer[1];
- 
  	  if (hexToInt(&ptr, &addr)
  	      && *ptr++ == ','
  	      && hexToInt(&ptr, &length))
--- 981,986 ----
***************
*** 1003,1010 ****
  	case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
  	  /* Try to read '%x,%x:'.  */
  
- 	  ptr = &remcomInBuffer[1];
- 
  	  if (hexToInt(&ptr, &addr)
  	      && *ptr++ == ','
  	      && hexToInt(&ptr, &length)
--- 997,1002 ----
***************
*** 1022,1028 ****
  	case 'c':    /* cAA..AA    Continue at address AA..AA(optional) */
  	  /* try to read optional parameter, pc unchanged if no parm */
  
- 	  ptr = &remcomInBuffer[1];
  	  if (hexToInt(&ptr, &addr))
  	    {
  	      registers[PC] = addr;
--- 1014,1019 ----
***************
*** 1058,1064 ****
  	    int baudrate;
  	    extern void set_timer_3();
  
- 	    ptr = &remcomInBuffer[1];
  	    if (!hexToInt(&ptr, &baudrate))
  	      {
  		strcpy(remcomOutBuffer,"B01");
--- 1049,1054 ----






-- 
J.T. Conklin
RedBack Networks

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]