This is the mail archive of the gdb@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]

remote.c patch



Hi, 

I got this patch attached, I made it against latest snapshot I have
(gdb-19990913).

Now a few related comments:

1. I used gdbserver to test remote target.

   a. It is not part of default compilation on my Linux RH5.2.

   b. It did not compile.

   c. It was quite painful to make it work. I can clean it up too, if 
      necessary, howver, I do not have access to anything but Linux RH5.2
      and FreeBSD 3.2.  

2. If seems to me that '\0' is annoying anachonism which deserves to 
   be removed.


Thanks,

Aleksey

*** remote.c-19990913	Sat Dec  4 14:17:43 1999
--- remote.c	Sat Dec  4 14:33:33 1999
***************
*** 584,589 ****
    else
      sprintf (&buf[2], "%x", th);
!   putpkt (buf);
!   getpkt (buf, 0);
    if (gen)
      general_thread = th;
--- 584,595 ----
    else
      sprintf (&buf[2], "%x", th);
! 
!   remote_send(buf);
! 
!   if(buf[0] == '\0')
!     {
!       return;
!     }
! 
    if (gen)
      general_thread = th;
***************
*** 604,610 ****
    else
      sprintf (buf, "T%08x", tid);
!   putpkt (buf);
!   getpkt (buf, 0);
!   return (buf[0] == 'O' && buf[1] == 'K');
  }
  
--- 610,628 ----
    else
      sprintf (buf, "T%08x", tid);
! 
!   remote_send(buf);
! 
!   if(buf[0] == '\0')
!     {
!       return 0;
!     }
!   
!   if(buf[0] != 'O' || buf[1] != 'K')
!     {
!       warning("remote target returned garbage: %s", buf);
!       return 0;
!     }
!   
!   return 1;
  }
  
***************
*** 1144,1149 ****
  
    pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
!   putpkt (threadinfo_pkt);
!   getpkt (threadinfo_pkt, 0);
    result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
  					       info);
--- 1162,1178 ----
  
    pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
!   remote_send (threadinfo_pkt);
! 
!   if(threadinfo_pkt[0] == '\0')
!     {
!       return 0;
!     }
! 
!   if(threadinfo_pkt[0] != 'Q' || threadinfo_pkt[1] != 'Q')
!     {
!       warning("remote target returned garbadge: %s", threadinfo_pkt);
!       return 0;
!     }
! 
    result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
  					       info);
***************
*** 1241,1244 ****
--- 1270,1289 ----
    getpkt (t_response, 0);
  
+   if(t_response[0] == '\0')
+     {
+       return 0;
+     }
+ 
+   if(t_response[0] == 'E')
+     {
+       error ("remote target returned error");
+     }
+ 
+   if(t_response[0] != 'Q' && t_response[1] != 'M') 
+     {
+       warning("remote target returned garbage: %s", t_response);
+       return 0;
+     }
+ 
    *result_count =
      parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
***************
*** 1353,1360 ****
    putpkt ("qC");
    getpkt (buf, 0);
!   if (buf[0] == 'Q' && buf[1] == 'C')
!     return strtol (&buf[2], NULL, 16);
!   else
!     return oldpid;
  }
  
--- 1398,1419 ----
    putpkt ("qC");
    getpkt (buf, 0);
! 
!   if(buf[0] == '\0')
!     {
!       return oldpid;
!     }
! 
!   if(buf[0] == 'E')
!     {
!       error ("remote target returned error");
!     }
! 
!   if (buf[0] != 'Q' || buf[1] != 'C')
!     {
!       warning("remote target returned garbage: %s", buf);
!       return oldpid;
!     }
! 
!   return strtol (&buf[2], NULL, 16);
  }
  
***************
*** 1382,1385 ****
--- 1441,1450 ----
    putpkt ("qfThreadInfo");
    getpkt (bufp = buf, 0);
+ 
+   if(buf[0] == 'E')
+     {
+       error("remote target returned error");
+     }
+ 
    if (bufp[0] == '\0')		/* q packet not recognized! */
      {				/* try old jmetzler method  */
***************
*** 1399,1402 ****
--- 1464,1477 ----
  	putpkt ("qsThreadInfo");
  	getpkt (bufp = buf, 0);
+ 
+ 	if(buf[0] == 'E')
+ 	  {
+ 	    error("remote target retrurned error");
+ 	  }
+ 	
+ 	if (bufp[0] == '\0')
+ 	  {
+ 	    error("remote stopped support in the middle of operation");
+ 	  }
        }
  }
***************
*** 1420,1423 ****
--- 1495,1504 ----
    putpkt ("?");
    getpkt (buf, 0);
+ 
+   if(buf[0] == '\0' || buf[0] == 'E')
+     {
+       /* No support for '?' is a fatal error too */
+       error("remote failed to restart");
+     }
  }
  
***************
*** 1449,1459 ****
    getpkt (buf, 0);
  
!   if (buf[0] == '\000')
      return;			/* Return silently.  Stub doesn't support
  				   this command. */
    if (buf[0] == 'E')
      {
!       warning ("Remote failure reply: %s", buf);
!       return;
      }
  
--- 1530,1539 ----
    getpkt (buf, 0);
  
!   if (buf[0] == '\0')
      return;			/* Return silently.  Stub doesn't support
  				   this command. */
    if (buf[0] == 'E')
      {
!       error ("remote target returned error");
      }
  
***************
*** 1790,1793 ****
--- 1870,1883 ----
        putpkt ("!");
        getpkt (buf, 0);
+ 
+       if(buf[0] == '\0')
+ 	{
+ 	  error("extened remote protocol is not supported by target");
+ 	}
+ 
+       if(buf[0] == 'E')
+ 	{
+ 	  error("remote target retruned error");
+ 	}
      }
  }
***************
*** 1892,1895 ****
--- 1982,1995 ----
  	  putpkt ("!");
  	  getpkt (buf, 0);
+ 
+ 	  if(buf[0] == '\0')
+ 	    {
+ 	      error("extended remote protocol is not supported by target");
+ 	    }
+ 	  
+ 	  if(buf[0] == 'E')
+ 	    {
+ 	      error("remote target returned error");
+ 	    }
  	}
      }
***************
*** 1906,1909 ****
--- 2006,2014 ----
    putpkt ("!");
    getpkt (buf, 0);
+   
+   if(buf[0] == 'E')
+     {
+       error("remote target returned error");
+     }
  }
  
***************
*** 2269,2274 ****
  	{
  	case 'E':		/* Error of some sort */
! 	  warning ("Remote failure reply: %s", buf);
! 	  continue;
  	case 'T':		/* Status with PC, SP, FP, ... */
  	  {
--- 2374,2379 ----
  	{
  	case 'E':		/* Error of some sort */
! 	  error ("remote targted returned error");
! 	  break;
  	case 'T':		/* Status with PC, SP, FP, ... */
  	  {
***************
*** 2488,2493 ****
  	{
  	case 'E':		/* Error of some sort */
! 	  warning ("Remote failure reply: %s", buf);
! 	  continue;
  	case 'T':		/* Status with PC, SP, FP, ... */
  	  {
--- 2593,2598 ----
  	{
  	case 'E':		/* Error of some sort */
! 	  error ("remote target returned error");
! 	  break;
  	case 'T':		/* Status with PC, SP, FP, ... */
  	  {
***************
*** 2699,2702 ****
--- 2804,2812 ----
    remote_send (buf);
  
+   if(buf[0] == '\0' || buf[0] == 'E')
+     {
+       error("remote target cannot supply registers\n");
+     }
+ 
    if (remote_register_buf_size == 0)
      remote_register_buf_size = strlen (buf);
***************
*** 2863,2866 ****
--- 2973,2981 ----
  
    remote_send (buf);
+ 
+   if(buf[0] == '\0')
+     {
+       error("remote target cannot store registers");
+     }
  }
  
***************
*** 3088,3091 ****
--- 3203,3207 ----
  		  case '$':
  		  case '#':
+                   case ':':
  		  case 0x7d:
  		    /* These must be escaped */
***************
*** 3141,3144 ****
--- 3257,3265 ----
  	}
  
+       if(buf[0] == '\0')
+ 	{
+ 	  error("remote target stopped support in the middle of operation");
+ 	}
+ 
        /* Increment by i, not by todo, in case escape chars 
           caused us to send fewer bytes than we'd planned.  */
***************
*** 3206,3209 ****
--- 3327,3336 ----
  	}
  
+       if(buf[0] == '\0')
+ 	{
+ 	  internal_error("remote_write_bytes: bad value of "
+                          "remote_protocol_bynary_download");
+ 	}
+ 
        /* Reply describes memory byte by byte,
           each byte encoded as two hex characters.  */
***************
*** 3298,3306 ****
  
        if (buf[0] == 'E')
! 	/* There is no correspondance between what the remote protocol uses
! 	   for errors and errno codes.  We would like a cleaner way of
! 	   representing errors (big enough to include errno codes, bfd_error
! 	   codes, and others).  But for now just use EIO.  */
! 	memory_error (EIO, startaddr);
        p = buf;
        addr_we_found = 0;
--- 3425,3436 ----
  
        if (buf[0] == 'E')
! 	{
! 	  /* There is no correspondance between what the remote protocol uses
! 	     for errors and errno codes.  We would like a cleaner way of
! 	     representing errors (big enough to include errno codes, bfd_error
! 	     codes, and others).  But for now just use EIO.  */
! 	  memory_error (EIO, startaddr);
! 	}
! 
        p = buf;
        addr_we_found = 0;
***************
*** 3374,3378 ****
  
    if (buf[0] == 'E')
!     error ("Remote failure reply: %s", buf);
  }
  
--- 3504,3508 ----
  
    if (buf[0] == 'E')
!     error ("remote target returned error");
  }
  
***************
*** 3581,3585 ****
  	    unsigned char pktcsum;
  
! 	    *bp = '\000';
  
  	    pktcsum = fromhex (readchar (remote_timeout)) << 4;
--- 3711,3715 ----
  	    unsigned char pktcsum;
  
! 	    *bp = '\0';
  
  	    pktcsum = fromhex (readchar (remote_timeout)) << 4;
***************
*** 3936,3947 ****
        BREAKPOINT_FROM_PC (&addr, &bp_size);
        sprintf (p, ",%d", bp_size);
!       
!       putpkt (buf);
!       getpkt (buf, 0);
  
        if (buf[0] != '\0')
  	{
  	  remote_protocol_Z.support = PACKET_ENABLE;
! 	  return (buf[0] == 'E');
  	}
        
--- 4066,4076 ----
        BREAKPOINT_FROM_PC (&addr, &bp_size);
        sprintf (p, ",%d", bp_size);
!   
!       remote_send(buf);
  
        if (buf[0] != '\0')
  	{
  	  remote_protocol_Z.support = PACKET_ENABLE;
! 	  return 0;
  	}
        
***************
*** 4001,4008 ****
        sprintf (p, ",%d", bp_size);
        
!       putpkt (buf);
!       getpkt (buf, 0);
  
!       return (buf[0] == 'E');
      }
  
--- 4130,4141 ----
        sprintf (p, ",%d", bp_size);
        
!       remote_send(buf);
  
!       if (buf[0] == '\0')
! 	{
! 	  error("remote target stopped support in the middle of operaiton");
! 	}
!       
!       return 0;
      }
  
***************
*** 4032,4039 ****
    sprintf (p, ",%x", len);
    
!   putpkt (buf);
!   getpkt (buf, 0);
  
!   if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
  
--- 4165,4171 ----
    sprintf (p, ",%x", len);
    
!   remote_send(buf);
  
!   if (buf[0] == '\0')
      return -1;
  
***************
*** 4054,4061 ****
    p += hexnumstr (p, (ULONGEST) addr);
    sprintf (p, ",%x", len);
-   putpkt (buf);
-   getpkt (buf, 0);
  
!   if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
  
--- 4186,4193 ----
    p += hexnumstr (p, (ULONGEST) addr);
    sprintf (p, ",%x", len);
  
!   remote_send(buf);
! 
!   if (buf[0] == '\0')
      return -1;
  
***************
*** 4081,4088 ****
    *p = '\0';
  
!   putpkt (buf);
!   getpkt (buf, 0);
  
!   if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
  
--- 4213,4219 ----
    *p = '\0';
  
!   remote_send(buf);
  
!   if (buf[0] == '\0')
      return -1;
  
***************
*** 4105,4112 ****
    *p = '\0';
  
!   putpkt(buf);
!   getpkt (buf, 0);
!   
!   if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
  
--- 4236,4242 ----
    *p = '\0';
  
!   remote_send(buf);
! 
!   if (buf[0] == '\0')
      return -1;
  
***************
*** 4206,4209 ****
--- 4336,4340 ----
    int matched = 0;
    int mismatched = 0;
+   int first;
  
    if (!exec_bfd)
***************
*** 4213,4217 ****
      error ("command can only be used with remote target");
  
!   for (s = exec_bfd->sections; s; s = s->next)
      {
        if (!(s->flags & SEC_LOAD))
--- 4344,4348 ----
      error ("command can only be used with remote target");
  
!   for (s = exec_bfd->sections, first = 1; s; s = s->next, first = 0)
      {
        if (!(s->flags & SEC_LOAD))
***************
*** 4239,4247 ****
  
        getpkt (buf, 0);
        if (buf[0] == 'E')
  	error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
  	       sectname, lma, lma + size);
        if (buf[0] != 'C')
! 	error ("remote target does not support this operation");
  
        for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
--- 4370,4392 ----
  
        getpkt (buf, 0);
+       
+       if(buf[0] == '\0' && first)
+ 	{
+ 	  do_cleanups (old_chain);
+ 	  warning("remote target does not support this operation");
+ 	  return;
+ 	}
+       
+       if(buf[0] = 0)
+ 	{
+ 	  error("remote target stopped support in the middle of operation");
+ 	}
+ 
        if (buf[0] == 'E')
  	error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
  	       sectname, lma, lma + size);
+ 
        if (buf[0] != 'C')
! 	error ("remote target returned garbadge: %s", buf);
  
        for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
***************
*** 4328,4337 ****
      error ("query larger than available buffer");
  
!   i = putpkt (buf2);
!   if (i < 0)
!     return i;
! 
    getpkt (outbuf, 0);
  
    return 0;
  }
--- 4473,4484 ----
      error ("query larger than available buffer");
  
!   putpkt (buf2);
    getpkt (outbuf, 0);
  
+   if(outbuf[0] == '\0')
+     {
+       error("remote target returned error");
+     }
+ 
    return 0;
  }
***************
*** 4367,4372 ****
    *p = '\0';
  
!   if (putpkt (buf) < 0)
!     error ("Communication problem with target\n");
  
    /* get/display the response */
--- 4514,4518 ----
    *p = '\0';
  
!   putpkt (buf);
  
    /* get/display the response */
***************
*** 4376,4381 ****
        buf[0] = '\0';
        getpkt (buf, 0);
        if (buf[0] == '\0')
! 	error ("Target does not support this command\n");
        if (buf[0] == 'O' && buf[1] != 'K')
  	{
--- 4522,4532 ----
        buf[0] = '\0';
        getpkt (buf, 0);
+ 
        if (buf[0] == '\0')
! 	{
! 	  warning ("Target does not support this command\n");
! 	  return;
! 	}
! 
        if (buf[0] == 'O' && buf[1] != 'K')
  	{
***************
*** 4385,4393 ****
        if (strcmp (buf, "OK") == 0)
  	break;
!       if (strlen (buf) == 3 && buf[0] == 'E'
! 	  && isdigit (buf[1]) && isdigit (buf[2]))
  	{
  	  error ("Protocol error with Rcmd");
  	}
        for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
  	{
--- 4536,4545 ----
        if (strcmp (buf, "OK") == 0)
  	break;
! 
!       if (buf[0] == 'E')
  	{
  	  error ("Protocol error with Rcmd");
  	}
+ 
        for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
  	{
***************
*** 4668,4672 ****
    putpkt ("qfProcessInfo");
    getpkt (buf, 0);
!   if (buf[0] == 0)
      return;			/* Silently: target does not support this feature. */
  
--- 4820,4824 ----
    putpkt ("qfProcessInfo");
    getpkt (buf, 0);
!   if (buf[0] == '\0')
      return;			/* Silently: target does not support this feature. */
  

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