FYI Add sizeof_buf parameter to getpkt() et.al.

Andrew Cagney ac131313@cygnus.com
Fri Dec 3 19:58:00 GMT 1999


Hello,

[ StanS, MichaelS please make a mental note of this change.  It tweeks
both the the remote-thread and tracepoint code.  The urgent need for
this was discussed some months back :-( ]

This patch adds a sizeof_buf parameter to getpkt() along with any code
that calls getpkt().

This eliminates many many buffer over-run errors including several nasty
ones where the remote target could trash GDB's internal memory :-(

	Andrew
Sat Dec  4 01:16:47 1999  Andrew Cagney  <cagney@b1.cygnus.com>

	* tracepoint.c (remote_get_noisy_reply): Add parameter sizeof_buf.
	(finish_tfind_command): Add parameter sizeof_msg.
	
	* remote.c (remote_threads_info): Move assignment operator to
 	outside of function call.
	(remote_send): Add parameter sizeof_buf.
	(getpkt): Add parameter sizeof_buf. Call read_frame passing in
 	sizeof_buf.

	* remote.h (getpkt): Update.
	
	* tracepoint.c (remote_set_transparent_ranges,
 	remote_get_noisy_reply, trace_start_command, trace_stop_command,
 	trace_status_command, finish_tfind_command, trace_find_pc_command,
 	trace_find_tracepoint_command, trace_find_line_command,
 	trace_find_range_command, trace_find_outside_command): Update.

	* remote.c (set_thread, remote_thread_alive,
 	remote_get_threadinfo, remote_get_threadlist,
 	remote_current_thread, remote_threads_info,
 	extended_remote_restart, get_offsets, remote_open_1,
 	remote_async_open_1, remote_wait, remote_async_wait,
 	remote_fetch_registers, check_binary_download, remote_write_bytes,
 	remote_read_bytes, remote_send, remote_detach,
 	remote_async_detach, remote_fetch_registers,
 	store_register_using_P, store_register_using_P,
 	remote_fetch_registers, remote_store_registers, putpkt_binary,
 	remote_insert_breakpoint, remote_remove_breakpoint,
 	compare_sections_command, remote_rcmd, packet_command,
 	remote_info_process, remote_query, remote_insert_watchpoint,
 	remote_search, remote_remove_watchpoint,
 	remote_insert_hw_breakpoint, remote_remove_hw_breakpoint): Update.

Index: remote.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote.c,v
retrieving revision 1.260
diff -p -r1.260 remote.c
*** remote.c	1999/12/03 14:13:12	1.260
--- remote.c	1999/12/04 03:53:33
*************** static void extended_remote_async_create
*** 112,118 ****
  
  static void remote_mourn_1 PARAMS ((struct target_ops *));
  
! static void remote_send PARAMS ((char *buf));
  
  static int readchar PARAMS ((int timeout));
  
--- 112,118 ----
  
  static void remote_mourn_1 PARAMS ((struct target_ops *));
  
! static void remote_send (char *buf, long sizeof_buf);
  
  static int readchar PARAMS ((int timeout));
  
*************** set_thread (th, gen)
*** 782,788 ****
    else
      sprintf (&buf[2], "%x", th);
    putpkt (buf);
!   getpkt (buf, 0);
    if (gen)
      general_thread = th;
    else
--- 782,788 ----
    else
      sprintf (&buf[2], "%x", th);
    putpkt (buf);
!   getpkt (buf, PBUFSIZ, 0);
    if (gen)
      general_thread = th;
    else
*************** remote_thread_alive (tid)
*** 802,808 ****
    else
      sprintf (buf, "T%08x", tid);
    putpkt (buf);
!   getpkt (buf, 0);
    return (buf[0] == 'O' && buf[1] == 'K');
  }
  
--- 802,808 ----
    else
      sprintf (buf, "T%08x", tid);
    putpkt (buf);
!   getpkt (buf, sizeof (buf), 0);
    return (buf[0] == 'O' && buf[1] == 'K');
  }
  
*************** remote_get_threadinfo (threadid, fieldse
*** 1342,1348 ****
  
    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);
    return result;
--- 1342,1348 ----
  
    pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
    putpkt (threadinfo_pkt);
!   getpkt (threadinfo_pkt, PBUFSIZ, 0);
    result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
  					       info);
    return result;
*************** remote_get_threadlist (startflag, nextth
*** 1436,1442 ****
    pack_threadlist_request (threadlist_packet,
  			   startflag, result_limit, nextthread);
    putpkt (threadlist_packet);
!   getpkt (t_response, 0);
  
    *result_count =
      parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
--- 1436,1442 ----
    pack_threadlist_request (threadlist_packet,
  			   startflag, result_limit, nextthread);
    putpkt (threadlist_packet);
!   getpkt (t_response, PBUFSIZ, 0);
  
    *result_count =
      parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
*************** remote_current_thread (oldpid)
*** 1549,1555 ****
    char *buf = alloca (PBUFSIZ);
  
    putpkt ("qC");
!   getpkt (buf, 0);
    if (buf[0] == 'Q' && buf[1] == 'C')
      return strtol (&buf[2], NULL, 16);
    else
--- 1549,1555 ----
    char *buf = alloca (PBUFSIZ);
  
    putpkt ("qC");
!   getpkt (buf, PBUFSIZ, 0);
    if (buf[0] == 'Q' && buf[1] == 'C')
      return strtol (&buf[2], NULL, 16);
    else
*************** remote_threads_info (void)
*** 1578,1584 ****
      error ("Command can only be used when connected to the remote target.");
  
    putpkt ("qfThreadInfo");
!   getpkt (bufp = buf, 0);
    if (bufp[0] == '\0')		/* q packet not recognized! */
      {				/* try old jmetzler method  */
        remote_find_new_threads ();
--- 1578,1585 ----
      error ("Command can only be used when connected to the remote target.");
  
    putpkt ("qfThreadInfo");
!   bufp = buf;
!   getpkt (bufp, PBUFSIZ, 0);
    if (bufp[0] == '\0')		/* q packet not recognized! */
      {				/* try old jmetzler method  */
        remote_find_new_threads ();
*************** remote_threads_info (void)
*** 1595,1601 ****
  	  }
  	while (*bufp++ == ',');	/* comma-separated list */
  	putpkt ("qsThreadInfo");
! 	getpkt (bufp = buf, 0);
        }
  }
  
--- 1596,1603 ----
  	  }
  	while (*bufp++ == ',');	/* comma-separated list */
  	putpkt ("qsThreadInfo");
! 	bufp = buf;
! 	getpkt (bufp, PBUFSIZ, 0);
        }
  }
  
*************** extended_remote_restart ()
*** 1616,1622 ****
    /* Now query for status so this looks just like we restarted
       gdbserver from scratch.  */
    putpkt ("?");
!   getpkt (buf, 0);
  }
  
  /* Clean up connection to a remote debugger.  */
--- 1618,1624 ----
    /* Now query for status so this looks just like we restarted
       gdbserver from scratch.  */
    putpkt ("?");
!   getpkt (buf, PBUFSIZ, 0);
  }
  
  /* Clean up connection to a remote debugger.  */
*************** get_offsets ()
*** 1644,1650 ****
  
    putpkt ("qOffsets");
  
!   getpkt (buf, 0);
  
    if (buf[0] == '\000')
      return;			/* Return silently.  Stub doesn't support
--- 1646,1652 ----
  
    putpkt ("qOffsets");
  
!   getpkt (buf, PBUFSIZ, 0);
  
    if (buf[0] == '\000')
      return;			/* Return silently.  Stub doesn't support
*************** serial device is attached to the remote 
*** 1986,1992 ****
        /* tell the remote that we're using the extended protocol.  */
        char *buf = alloca (PBUFSIZ);
        putpkt ("!");
!       getpkt (buf, 0);
      }
  }
  
--- 1988,1994 ----
        /* tell the remote that we're using the extended protocol.  */
        char *buf = alloca (PBUFSIZ);
        putpkt ("!");
!       getpkt (buf, PBUFSIZ, 0);
      }
  }
  
*************** serial device is attached to the remote 
*** 2085,2091 ****
        /* tell the remote that we're using the extended protocol.  */
        char *buf = alloca (PBUFSIZ);
        putpkt ("!");
!       getpkt (buf, 0);
      }
  }
  
--- 2087,2093 ----
        /* tell the remote that we're using the extended protocol.  */
        char *buf = alloca (PBUFSIZ);
        putpkt ("!");
!       getpkt (buf, PBUFSIZ, 0);
      }
  }
  
*************** remote_detach (args, from_tty)
*** 2106,2112 ****
  
    /* Tell the remote target to detach.  */
    strcpy (buf, "D");
!   remote_send (buf);
  
    pop_target ();
    if (from_tty)
--- 2108,2114 ----
  
    /* Tell the remote target to detach.  */
    strcpy (buf, "D");
!   remote_send (buf, PBUFSIZ);
  
    pop_target ();
    if (from_tty)
*************** remote_async_detach (args, from_tty)
*** 2127,2133 ****
  
    /* Tell the remote target to detach.  */
    strcpy (buf, "D");
!   remote_send (buf);
  
    /* Unregister the file descriptor from the event loop. */
    if (SERIAL_IS_ASYNC_P (remote_desc))
--- 2129,2135 ----
  
    /* Tell the remote target to detach.  */
    strcpy (buf, "D");
!   remote_send (buf, PBUFSIZ);
  
    /* Unregister the file descriptor from the event loop. */
    if (SERIAL_IS_ASYNC_P (remote_desc))
*************** remote_wait (pid, status)
*** 2487,2493 ****
        unsigned char *p;
  
        ofunc = signal (SIGINT, remote_interrupt);
!       getpkt ((char *) buf, 1);
        signal (SIGINT, ofunc);
  
        /* This is a hook for when we need to do something (perhaps the
--- 2489,2495 ----
        unsigned char *p;
  
        ofunc = signal (SIGINT, remote_interrupt);
!       getpkt (buf, PBUFSIZ, 1);
        signal (SIGINT, ofunc);
  
        /* This is a hook for when we need to do something (perhaps the
*************** remote_async_wait (pid, status)
*** 2709,2715 ****
           _never_ wait for ever -> test on target_is_async_p().
           However, before we do that we need to ensure that the caller
           knows how to take the target into/out of async mode. */
!       getpkt ((char *) buf, wait_forever_enabled_p);
        if (!SERIAL_IS_ASYNC_P (remote_desc))
  	signal (SIGINT, ofunc);
  
--- 2711,2717 ----
           _never_ wait for ever -> test on target_is_async_p().
           However, before we do that we need to ensure that the caller
           knows how to take the target into/out of async mode. */
!       getpkt (buf, PBUFSIZ, wait_forever_enabled_p);
        if (!SERIAL_IS_ASYNC_P (remote_desc))
  	signal (SIGINT, ofunc);
  
*************** remote_fetch_registers (regno)
*** 2930,2936 ****
    set_thread (inferior_pid, 1);
  
    sprintf (buf, "g");
!   remote_send (buf);
  
    /* Save the size of the packet sent to us by the target.  Its used
       as a heuristic when determining the max size of packets that the
--- 2932,2938 ----
    set_thread (inferior_pid, 1);
  
    sprintf (buf, "g");
!   remote_send (buf, PBUFSIZ);
  
    /* Save the size of the packet sent to us by the target.  Its used
       as a heuristic when determining the max size of packets that the
*************** remote_fetch_registers (regno)
*** 2951,2957 ****
        if (remote_debug)
  	fprintf_unfiltered (gdb_stdlog,
  			    "Bad register packet; fetching a new packet\n");
!       getpkt (buf, 0);
      }
  
    /* Reply describes registers byte by byte, each byte encoded as two
--- 2953,2959 ----
        if (remote_debug)
  	fprintf_unfiltered (gdb_stdlog,
  			    "Bad register packet; fetching a new packet\n");
!       getpkt (buf, PBUFSIZ, 0);
      }
  
    /* Reply describes registers byte by byte, each byte encoded as two
*************** store_register_using_P (int regno)
*** 3035,3041 ****
        *p++ = tohex (regp[i] & 0xf);
      }
    *p = '\0';
!   remote_send (buf);
  
    return buf[0] != '\0';
  }
--- 3037,3043 ----
        *p++ = tohex (regp[i] & 0xf);
      }
    *p = '\0';
!   remote_send (buf, PBUFSIZ);
  
    return buf[0] != '\0';
  }
*************** remote_store_registers (regno)
*** 3097,3103 ****
      }
    *p = '\0';
  
!   remote_send (buf);
  }
  
  /* Use of the data cache *used* to be disabled because it loses for looking
--- 3099,3105 ----
      }
    *p = '\0';
  
!   remote_send (buf, PBUFSIZ);
  }
  
  /* Use of the data cache *used* to be disabled because it loses for looking
*************** check_binary_download (addr)
*** 3235,3241 ****
  	*p = '\0';
  	
  	putpkt_binary (buf, (int) (p - buf));
! 	getpkt (buf, 0);
  
  	if (buf[0] == '\0')
  	  {
--- 3237,3243 ----
  	*p = '\0';
  	
  	putpkt_binary (buf, (int) (p - buf));
! 	getpkt (buf, PBUFSIZ, 0);
  
  	if (buf[0] == '\0')
  	  {
*************** remote_write_bytes (CORE_ADDR memaddr, c
*** 3272,3277 ****
--- 3274,3280 ----
    int max_buf_size;		/* Max size of packet output buffer */
    unsigned char *p;
    unsigned char *plen;
+   long sizeof_buf;
    int plenlen;
    int todo;
    int nr_bytes;
*************** remote_write_bytes (CORE_ADDR memaddr, c
*** 3281,3287 ****
  
    /* Determine the max packet size. */
    max_buf_size = get_memory_write_packet_size ();
!   buf = alloca (max_buf_size + 1);
  
    /* Subtract header overhead from max payload size -  $M<memaddr>,<len>:#nn */
    max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
--- 3284,3291 ----
  
    /* Determine the max packet size. */
    max_buf_size = get_memory_write_packet_size ();
!   sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
!   buf = alloca (sizeof_buf);
  
    /* Subtract header overhead from max payload size -  $M<memaddr>,<len>:#nn */
    max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
*************** remote_write_bytes (CORE_ADDR memaddr, c
*** 3373,3379 ****
      }
    
    putpkt_binary (buf, (int) (p - buf));
!   getpkt (buf, 0);
    
    if (buf[0] == 'E')
      {
--- 3377,3383 ----
      }
    
    putpkt_binary (buf, (int) (p - buf));
!   getpkt (buf, sizeof_buf, 0);
    
    if (buf[0] == 'E')
      {
*************** remote_read_bytes (memaddr, myaddr, len)
*** 3413,3423 ****
  {
    char *buf;
    int max_buf_size;		/* Max size of packet output buffer */
    int origlen;
  
    /* Create a buffer big enough for this packet. */
    max_buf_size = get_memory_read_packet_size ();
!   buf = alloca (max_buf_size);
  
    origlen = len;
    while (len > 0)
--- 3417,3429 ----
  {
    char *buf;
    int max_buf_size;		/* Max size of packet output buffer */
+   long sizeof_buf;
    int origlen;
  
    /* Create a buffer big enough for this packet. */
    max_buf_size = get_memory_read_packet_size ();
!   sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
!   buf = alloca (sizeof_buf);
  
    origlen = len;
    while (len > 0)
*************** remote_read_bytes (memaddr, myaddr, len)
*** 3439,3445 ****
        *p = '\0';
  
        putpkt (buf);
!       getpkt (buf, 0);
  
        if (buf[0] == 'E')
  	{
--- 3445,3451 ----
        *p = '\0';
  
        putpkt (buf);
!       getpkt (buf, sizeof_buf, 0);
  
        if (buf[0] == 'E')
  	{
*************** remote_search (len, data, mask, startadd
*** 3530,3536 ****
        data_long = extract_unsigned_integer (data, len);
        sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
        putpkt (buf);
!       getpkt (buf, 0);
        if (buf[0] == '\0')
  	{
  	  /* The stub doesn't support the 't' request.  We might want to
--- 3536,3542 ----
        data_long = extract_unsigned_integer (data, len);
        sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
        putpkt (buf);
!       getpkt (buf, PBUFSIZ, 0);
        if (buf[0] == '\0')
  	{
  	  /* The stub doesn't support the 't' request.  We might want to
*************** readchar (timeout)
*** 3617,3627 ****
     into BUF.  Report an error if we get an error reply.  */
  
  static void
! remote_send (buf)
!      char *buf;
  {
    putpkt (buf);
!   getpkt (buf, 0);
  
    if (buf[0] == 'E')
      error ("Remote failure reply: %s", buf);
--- 3623,3633 ----
     into BUF.  Report an error if we get an error reply.  */
  
  static void
! remote_send (char *buf,
! 	     long sizeof_buf)
  {
    putpkt (buf);
!   getpkt (buf, sizeof_buf, 0);
  
    if (buf[0] == 'E')
      error ("Remote failure reply: %s", buf);
*************** putpkt_binary (buf, cnt)
*** 3659,3665 ****
    int i;
    unsigned char csum = 0;
    char *buf2 = alloca (cnt + 6);
!   char *junkbuf = alloca (PBUFSIZ);
  
    int ch;
    int tcount = 0;
--- 3665,3672 ----
    int i;
    unsigned char csum = 0;
    char *buf2 = alloca (cnt + 6);
!   long sizeof_junkbuf = PBUFSIZ;
!   char *junkbuf = alloca (sizeof_junkbuf);
  
    int ch;
    int tcount = 0;
*************** putpkt_binary (buf, cnt)
*** 3732,3738 ****
  	      {
  		/* It's probably an old response, and we're out of sync.
  		   Just gobble up the packet and ignore it.  */
! 		getpkt (junkbuf, 0);
  		continue;	/* Now, go look for + */
  	      }
  	    default:
--- 3739,3745 ----
  	      {
  		/* It's probably an old response, and we're out of sync.
  		   Just gobble up the packet and ignore it.  */
! 		getpkt (junkbuf, sizeof_junkbuf, 0);
  		continue;	/* Now, go look for + */
  	      }
  	    default:
*************** read_frame (char *buf,
*** 3892,3897 ****
--- 3899,3905 ----
  
  void
  getpkt (char *buf,
+ 	long sizeof_buf,
  	int forever)
  {
    int c;
*************** getpkt (char *buf,
*** 3942,3948 ****
  
        /* We've found the start of a packet, now collect the data.  */
  
!       val = read_frame (buf, PBUFSIZ);
  
        if (val >= 0)
  	{
--- 3950,3956 ----
  
        /* We've found the start of a packet, now collect the data.  */
  
!       val = read_frame (buf, sizeof_buf);
  
        if (val >= 0)
  	{
*************** remote_insert_breakpoint (addr, contents
*** 4176,4182 ****
        sprintf (p, ",%d", bp_size);
        
        putpkt (buf);
!       getpkt (buf, 0);
  
        if (buf[0] != '\0')
  	{
--- 4184,4190 ----
        sprintf (p, ",%d", bp_size);
        
        putpkt (buf);
!       getpkt (buf, PBUFSIZ, 0);
  
        if (buf[0] != '\0')
  	{
*************** remote_remove_breakpoint (addr, contents
*** 4241,4247 ****
        sprintf (p, ",%d", bp_size);
        
        putpkt (buf);
!       getpkt (buf, 0);
  
        return (buf[0] == 'E');
      }
--- 4249,4255 ----
        sprintf (p, ",%d", bp_size);
        
        putpkt (buf);
!       getpkt (buf, PBUFSIZ, 0);
  
        return (buf[0] == 'E');
      }
*************** remote_insert_watchpoint (addr, len, typ
*** 4273,4279 ****
    sprintf (p, ",%x", len);
    
    putpkt (buf);
!   getpkt (buf, 0);
  
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
--- 4281,4287 ----
    sprintf (p, ",%x", len);
    
    putpkt (buf);
!   getpkt (buf, PBUFSIZ, 0);
  
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
*************** remote_remove_watchpoint (addr, len, typ
*** 4296,4302 ****
    p += hexnumstr (p, (ULONGEST) addr);
    sprintf (p, ",%x", len);
    putpkt (buf);
!   getpkt (buf, 0);
  
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
--- 4304,4310 ----
    p += hexnumstr (p, (ULONGEST) addr);
    sprintf (p, ",%x", len);
    putpkt (buf);
!   getpkt (buf, PBUFSIZ, 0);
  
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
*************** remote_insert_hw_breakpoint (addr, len)
*** 4324,4330 ****
    *p = '\0';
  
    putpkt (buf);
!   getpkt (buf, 0);
  
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
--- 4332,4338 ----
    *p = '\0';
  
    putpkt (buf);
!   getpkt (buf, PBUFSIZ, 0);
  
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
*************** remote_remove_hw_breakpoint (addr, len)
*** 4349,4355 ****
    *p = '\0';
  
    putpkt(buf);
!   getpkt (buf, 0);
    
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
--- 4357,4363 ----
    *p = '\0';
  
    putpkt(buf);
!   getpkt (buf, PBUFSIZ, 0);
    
    if (buf[0] == '\0' || buf [0] == 'E')
      return -1;
*************** compare_sections_command (args, from_tty
*** 4486,4492 ****
        bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
        host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
  
!       getpkt (buf, 0);
        if (buf[0] == 'E')
  	error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
  	       sectname, lma, lma + size);
--- 4494,4500 ----
        bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
        host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
  
!       getpkt (buf, PBUFSIZ, 0);
        if (buf[0] == 'E')
  	error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
  	       sectname, lma, lma + size);
*************** remote_query (query_type, buf, outbuf, b
*** 4580,4586 ****
    if (i < 0)
      return i;
  
!   getpkt (outbuf, 0);
  
    return 0;
  }
--- 4588,4594 ----
    if (i < 0)
      return i;
  
!   getpkt (outbuf, *bufsiz, 0);
  
    return 0;
  }
*************** remote_rcmd (char *command,
*** 4623,4629 ****
      {
        /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
        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')
--- 4631,4637 ----
      {
        /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
        buf[0] = '\0';
!       getpkt (buf, PBUFSIZ, 0);
        if (buf[0] == '\0')
  	error ("Target does not support this command\n");
        if (buf[0] == 'O' && buf[1] != 'K')
*************** packet_command (args, from_tty)
*** 4665,4671 ****
    puts_filtered ("\n");
    putpkt (args);
  
!   getpkt (buf, 0);
    puts_filtered ("received: ");
    print_packet (buf);
    puts_filtered ("\n");
--- 4673,4679 ----
    puts_filtered ("\n");
    putpkt (args);
  
!   getpkt (buf, PBUFSIZ, 0);
    puts_filtered ("received: ");
    print_packet (buf);
    puts_filtered ("\n");
*************** remote_info_process (char *args, int fro
*** 4913,4919 ****
      error ("Command can only be used when connected to the remote target.");
  
    putpkt ("qfProcessInfo");
!   getpkt (buf, 0);
    if (buf[0] == 0)
      return;			/* Silently: target does not support this feature. */
  
--- 4921,4927 ----
      error ("Command can only be used when connected to the remote target.");
  
    putpkt ("qfProcessInfo");
!   getpkt (buf, PBUFSIZ, 0);
    if (buf[0] == 0)
      return;			/* Silently: target does not support this feature. */
  
*************** remote_info_process (char *args, int fro
*** 4924,4930 ****
      {
        remote_console_output (&buf[1]);
        putpkt ("qsProcessInfo");
!       getpkt (buf, 0);
      }
  }
  
--- 4932,4938 ----
      {
        remote_console_output (&buf[1]);
        putpkt ("qsProcessInfo");
!       getpkt (buf, PBUFSIZ, 0);
      }
  }
  
Index: remote.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/remote.h,v
retrieving revision 2.6
diff -p -r2.6 remote.h
*** remote.h	1999/10/17 06:07:28	2.6
--- remote.h	1999/12/04 03:53:33
***************
*** 28,34 ****
     FOREVER, wait forever rather than timing out; this is used while
     the target is executing user code.  */
  
! extern void getpkt (char *buf, int forever);
  
  /* Send a packet to the remote machine, with error checking.  The data
     of the packet is in BUF.  The string in BUF can be at most PBUFSIZ
--- 28,34 ----
     FOREVER, wait forever rather than timing out; this is used while
     the target is executing user code.  */
  
! extern void getpkt (char *buf, long sizeof_buf, int forever);
  
  /* Send a packet to the remote machine, with error checking.  The data
     of the packet is in BUF.  The string in BUF can be at most PBUFSIZ
Index: tracepoint.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/tracepoint.c,v
retrieving revision 2.50
diff -p -r2.50 tracepoint.c
*** tracepoint.c	1999/11/18 17:53:35	2.50
--- tracepoint.c	1999/12/04 03:53:38
*************** trace_error (buf)
*** 196,208 ****
  
  /* Utility: wait for reply from stub, while accepting "O" packets */
  static char *
! remote_get_noisy_reply (buf)
!      char *buf;
  {
    do				/* loop on reply from remote stub */
      {
        QUIT;			/* allow user to bail out with ^C */
!       getpkt (buf, 0);
        if (buf[0] == 0)
  	error ("Target does not support this command.");
        else if (buf[0] == 'E')
--- 196,208 ----
  
  /* Utility: wait for reply from stub, while accepting "O" packets */
  static char *
! remote_get_noisy_reply (char *buf,
! 			long sizeof_buf)
  {
    do				/* loop on reply from remote stub */
      {
        QUIT;			/* allow user to bail out with ^C */
!       getpkt (buf, sizeof_buf, 0);
        if (buf[0] == 0)
  	error ("Target does not support this command.");
        else if (buf[0] == 'E')
*************** remote_set_transparent_ranges (void)
*** 1736,1742 ****
    if (anysecs)
      {
        putpkt (target_buf);
!       getpkt (target_buf, 0);
      }
  }
  
--- 1736,1742 ----
    if (anysecs)
      {
        putpkt (target_buf);
!       getpkt (target_buf, sizeof (target_buf), 0);
      }
  }
  
*************** trace_start_command (args, from_tty)
*** 1764,1770 ****
    if (target_is_remote ())
      {
        putpkt ("QTinit");
!       remote_get_noisy_reply (target_buf);
        if (strcmp (target_buf, "OK"))
  	error ("Target does not support this command.");
  
--- 1764,1770 ----
    if (target_is_remote ())
      {
        putpkt ("QTinit");
!       remote_get_noisy_reply (target_buf, sizeof (target_buf));
        if (strcmp (target_buf, "OK"))
  	error ("Target does not support this command.");
  
*************** trace_start_command (args, from_tty)
*** 1780,1786 ****
  	if (t->actions)
  	  strcat (buf, "-");
  	putpkt (buf);
! 	remote_get_noisy_reply (target_buf);
  	if (strcmp (target_buf, "OK"))
  	  error ("Target does not support tracepoints.");
  
--- 1780,1786 ----
  	if (t->actions)
  	  strcat (buf, "-");
  	putpkt (buf);
! 	remote_get_noisy_reply (target_buf, sizeof (target_buf));
  	if (strcmp (target_buf, "OK"))
  	  error ("Target does not support tracepoints.");
  
*************** trace_start_command (args, from_tty)
*** 1804,1810 ****
  			     ((tdp_actions[ndx + 1] || stepping_actions)
  			      ? '-' : 0));
  		    putpkt (buf);
! 		    remote_get_noisy_reply (target_buf);
  		    if (strcmp (target_buf, "OK"))
  		      error ("Error on target while setting tracepoints.");
  		  }
--- 1804,1810 ----
  			     ((tdp_actions[ndx + 1] || stepping_actions)
  			      ? '-' : 0));
  		    putpkt (buf);
! 		    remote_get_noisy_reply (target_buf, sizeof (target_buf));
  		    if (strcmp (target_buf, "OK"))
  		      error ("Error on target while setting tracepoints.");
  		  }
*************** trace_start_command (args, from_tty)
*** 1820,1826 ****
  			     stepping_actions[ndx],
  			     (stepping_actions[ndx + 1] ? "-" : ""));
  		    putpkt (buf);
! 		    remote_get_noisy_reply (target_buf);
  		    if (strcmp (target_buf, "OK"))
  		      error ("Error on target while setting tracepoints.");
  		  }
--- 1820,1826 ----
  			     stepping_actions[ndx],
  			     (stepping_actions[ndx + 1] ? "-" : ""));
  		    putpkt (buf);
! 		    remote_get_noisy_reply (target_buf, sizeof (target_buf));
  		    if (strcmp (target_buf, "OK"))
  		      error ("Error on target while setting tracepoints.");
  		  }
*************** trace_start_command (args, from_tty)
*** 1833,1839 ****
        remote_set_transparent_ranges ();
        /* Now insert traps and begin collecting data */
        putpkt ("QTStart");
!       remote_get_noisy_reply (target_buf);
        if (strcmp (target_buf, "OK"))
  	error ("Bogus reply from target: %s", target_buf);
        set_traceframe_num (-1);	/* all old traceframes invalidated */
--- 1833,1839 ----
        remote_set_transparent_ranges ();
        /* Now insert traps and begin collecting data */
        putpkt ("QTStart");
!       remote_get_noisy_reply (target_buf, sizeof (target_buf));
        if (strcmp (target_buf, "OK"))
  	error ("Bogus reply from target: %s", target_buf);
        set_traceframe_num (-1);	/* all old traceframes invalidated */
*************** trace_stop_command (args, from_tty)
*** 1857,1863 ****
    if (target_is_remote ())
      {
        putpkt ("QTStop");
!       remote_get_noisy_reply (target_buf);
        if (strcmp (target_buf, "OK"))
  	error ("Bogus reply from target: %s", target_buf);
        trace_running_p = 0;
--- 1857,1863 ----
    if (target_is_remote ())
      {
        putpkt ("QTStop");
!       remote_get_noisy_reply (target_buf, sizeof (target_buf));
        if (strcmp (target_buf, "OK"))
  	error ("Bogus reply from target: %s", target_buf);
        trace_running_p = 0;
*************** trace_status_command (args, from_tty)
*** 1879,1885 ****
    if (target_is_remote ())
      {
        putpkt ("qTStatus");
!       remote_get_noisy_reply (target_buf);
  
        if (target_buf[0] != 'T' ||
  	  (target_buf[1] != '0' && target_buf[1] != '1'))
--- 1879,1885 ----
    if (target_is_remote ())
      {
        putpkt ("qTStatus");
!       remote_get_noisy_reply (target_buf, sizeof (target_buf));
  
        if (target_buf[0] != 'T' ||
  	  (target_buf[1] != '0' && target_buf[1] != '1'))
*************** trace_status_command (args, from_tty)
*** 1894,1902 ****
  
  /* Worker function for the various flavors of the tfind command */
  static void
! finish_tfind_command (msg, from_tty)
!      char *msg;
!      int from_tty;
  {
    int target_frameno = -1, target_tracept = -1;
    CORE_ADDR old_frame_addr;
--- 1894,1902 ----
  
  /* Worker function for the various flavors of the tfind command */
  static void
! finish_tfind_command (char *msg,
! 		      long sizeof_msg,
! 		      int from_tty)
  {
    int target_frameno = -1, target_tracept = -1;
    CORE_ADDR old_frame_addr;
*************** finish_tfind_command (msg, from_tty)
*** 1907,1913 ****
    old_func = find_pc_function (read_pc ());
  
    putpkt (msg);
!   reply = remote_get_noisy_reply (msg);
  
    while (reply && *reply)
      switch (*reply)
--- 1907,1913 ----
    old_func = find_pc_function (read_pc ());
  
    putpkt (msg);
!   reply = remote_get_noisy_reply (msg, sizeof_msg);
  
    while (reply && *reply)
      switch (*reply)
*************** trace_find_command (args, from_tty)
*** 2051,2057 ****
  	error ("invalid input (%d is less than zero)", frameno);
  
        sprintf (target_buf, "QTFrame:%x", frameno);
!       finish_tfind_command (target_buf, from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
--- 2051,2057 ----
  	error ("invalid input (%d is less than zero)", frameno);
  
        sprintf (target_buf, "QTFrame:%x", frameno);
!       finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
*************** trace_find_pc_command (args, from_tty)
*** 2102,2108 ****
  
        sprintf_vma (tmp, pc);
        sprintf (target_buf, "QTFrame:pc:%s", tmp);
!       finish_tfind_command (target_buf, from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
--- 2102,2108 ----
  
        sprintf_vma (tmp, pc);
        sprintf (target_buf, "QTFrame:pc:%s", tmp);
!       finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
*************** trace_find_tracepoint_command (args, fro
*** 2127,2133 ****
  	tdp = parse_and_eval_address (args);
  
        sprintf (target_buf, "QTFrame:tdp:%x", tdp);
!       finish_tfind_command (target_buf, from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
--- 2127,2133 ----
  	tdp = parse_and_eval_address (args);
  
        sprintf (target_buf, "QTFrame:tdp:%x", tdp);
!       finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
*************** trace_find_line_command (args, from_tty)
*** 2223,2229 ****
  	sprintf (target_buf, "QTFrame:range:%s:%s", startpc_str, endpc_str);
        else			/* find OUTSIDE OF range of CURRENT line */
  	sprintf (target_buf, "QTFrame:outside:%s:%s", startpc_str, endpc_str);
!       finish_tfind_command (target_buf, from_tty);
        do_cleanups (old_chain);
      }
    else
--- 2223,2229 ----
  	sprintf (target_buf, "QTFrame:range:%s:%s", startpc_str, endpc_str);
        else			/* find OUTSIDE OF range of CURRENT line */
  	sprintf (target_buf, "QTFrame:outside:%s:%s", startpc_str, endpc_str);
!       finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
        do_cleanups (old_chain);
      }
    else
*************** trace_find_range_command (args, from_tty
*** 2265,2271 ****
        sprintf_vma (start_str, start);
        sprintf_vma (stop_str, stop);
        sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str);
!       finish_tfind_command (target_buf, from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
--- 2265,2271 ----
        sprintf_vma (start_str, start);
        sprintf_vma (stop_str, stop);
        sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str);
!       finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
*************** trace_find_outside_command (args, from_t
*** 2306,2312 ****
        sprintf_vma (start_str, start);
        sprintf_vma (stop_str, stop);
        sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str);
!       finish_tfind_command (target_buf, from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");
--- 2306,2312 ----
        sprintf_vma (start_str, start);
        sprintf_vma (stop_str, stop);
        sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str);
!       finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
      }
    else
      error ("Trace can only be run on remote targets.");


More information about the Gdb-patches mailing list