static void remote_mourn_1 PARAMS ((struct target_ops *));
-static void remote_send PARAMS ((char *buf));
+static void remote_send (char *buf, long sizeof_buf);
static int readchar PARAMS ((int timeout));
static void get_offsets PARAMS ((void));
-static int read_frame PARAMS ((char *));
+static long read_frame (char *buf, long sizeof_buf);
static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
static void
build_remote_packet_sizes (void)
{
- /* Maximum number of characters in a packet. This default m68k-stub.c and
- i386-stub.c stubs. */
- remote_packet_size = 400;
+ /* Default maximum number of characters in a packet body. Many
+ remote stubs have a hardwired buffer size of 400 bytes
+ (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
+ as the maximum packet-size to ensure that the packet and an extra
+ NUL character can always fit in the buffer. This stops GDB
+ trashing stubs that try to squeeze an extra NUL into what is
+ already a full buffer (As of 1999-12-04 that was most stubs. */
+ remote_packet_size = 400 - 1;
/* Should REGISTER_BYTES needs more space than the default, adjust
the size accordingly. Remember that each byte is encoded as two
characters. 32 is the overhead for the packet header /
else
sprintf (&buf[2], "%x", th);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (gen)
general_thread = th;
else
else
sprintf (buf, "T%08x", tid);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, sizeof (buf), 0);
return (buf[0] == 'O' && buf[1] == 'K');
}
pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
putpkt (threadinfo_pkt);
- getpkt (threadinfo_pkt, 0);
+ getpkt (threadinfo_pkt, PBUFSIZ, 0);
result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
info);
return result;
pack_threadlist_request (threadlist_packet,
startflag, result_limit, nextthread);
putpkt (threadlist_packet);
- getpkt (t_response, 0);
+ getpkt (t_response, PBUFSIZ, 0);
*result_count =
parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
char *buf = alloca (PBUFSIZ);
putpkt ("qC");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == 'Q' && buf[1] == 'C')
return strtol (&buf[2], NULL, 16);
else
error ("Command can only be used when connected to the remote target.");
putpkt ("qfThreadInfo");
- getpkt (bufp = buf, 0);
+ bufp = buf;
+ getpkt (bufp, PBUFSIZ, 0);
if (bufp[0] == '\0') /* q packet not recognized! */
{ /* try old jmetzler method */
remote_find_new_threads ();
}
while (*bufp++ == ','); /* comma-separated list */
putpkt ("qsThreadInfo");
- getpkt (bufp = buf, 0);
+ bufp = buf;
+ getpkt (bufp, PBUFSIZ, 0);
}
}
\f
/* Now query for status so this looks just like we restarted
gdbserver from scratch. */
putpkt ("?");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
}
\f
/* Clean up connection to a remote debugger. */
putpkt ("qOffsets");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\000')
return; /* Return silently. Stub doesn't support
*/
static int
-remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
- text_offs, data_offs, bss_offs)
- bfd_vma text_addr;
- bfd_vma data_addr;
- bfd_vma bss_addr;
- bfd_signed_vma *text_offs;
- bfd_signed_vma *data_offs;
- bfd_signed_vma *bss_offs;
+remote_cisco_section_offsets (bfd_vma text_addr,
+ bfd_vma data_addr,
+ bfd_vma bss_addr,
+ bfd_signed_vma *text_offs,
+ bfd_signed_vma *data_offs,
+ bfd_signed_vma *bss_offs)
{
bfd_vma text_base, data_base, bss_base;
struct minimal_symbol *start;
/* Stub for catch_errors. */
static int
-remote_start_remote_dummy (dummy)
- char *dummy;
+remote_start_remote_dummy (void *dummy)
{
start_remote (); /* Initialize gdb process mechanisms */
return 1;
/* tell the remote that we're using the extended protocol. */
char *buf = alloca (PBUFSIZ);
putpkt ("!");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
}
}
/* tell the remote that we're using the extended protocol. */
char *buf = alloca (PBUFSIZ);
putpkt ("!");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
}
}
/* Tell the remote target to detach. */
strcpy (buf, "D");
- remote_send (buf);
+ remote_send (buf, PBUFSIZ);
pop_target ();
if (from_tty)
/* Tell the remote target to detach. */
strcpy (buf, "D");
- remote_send (buf);
+ remote_send (buf, PBUFSIZ);
/* Unregister the file descriptor from the event loop. */
if (SERIAL_IS_ASYNC_P (remote_desc))
unsigned char *p;
ofunc = signal (SIGINT, remote_interrupt);
- getpkt ((char *) buf, 1);
+ getpkt (buf, PBUFSIZ, 1);
signal (SIGINT, ofunc);
/* This is a hook for when we need to do something (perhaps the
_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);
+ getpkt (buf, PBUFSIZ, wait_forever_enabled_p);
if (!SERIAL_IS_ASYNC_P (remote_desc))
signal (SIGINT, ofunc);
set_thread (inferior_pid, 1);
sprintf (buf, "g");
- remote_send (buf);
+ 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
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"Bad register packet; fetching a new packet\n");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
}
/* Reply describes registers byte by byte, each byte encoded as two
packet was not recognized. */
static int
-store_register_using_P (regno)
- int regno;
+store_register_using_P (int regno)
{
/* Try storing a single register. */
char *buf = alloca (PBUFSIZ);
*p++ = tohex (regp[i] & 0xf);
}
*p = '\0';
- remote_send (buf);
+ remote_send (buf, PBUFSIZ);
return buf[0] != '\0';
}
}
*p = '\0';
- remote_send (buf);
+ remote_send (buf, PBUFSIZ);
}
/* Use of the data cache *used* to be disabled because it loses for looking
*p = '\0';
putpkt_binary (buf, (int) (p - buf));
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0')
{
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;
/* Determine the max packet size. */
max_buf_size = get_memory_write_packet_size ();
- buf = alloca (max_buf_size + 1);
+ 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;
}
putpkt_binary (buf, (int) (p - buf));
- getpkt (buf, 0);
+ getpkt (buf, sizeof_buf, 0);
if (buf[0] == 'E')
{
{
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 ();
- buf = alloca (max_buf_size);
+ sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
+ buf = alloca (sizeof_buf);
origlen = len;
while (len > 0)
*p = '\0';
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, sizeof_buf, 0);
if (buf[0] == 'E')
{
data_long = extract_unsigned_integer (data, len);
sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0')
{
/* The stub doesn't support the 't' request. We might want to
into BUF. Report an error if we get an error reply. */
static void
-remote_send (buf)
- char *buf;
+remote_send (char *buf,
+ long sizeof_buf)
{
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, sizeof_buf, 0);
if (buf[0] == 'E')
error ("Remote failure reply: %s", buf);
int i;
unsigned char csum = 0;
char *buf2 = alloca (cnt + 6);
- char *junkbuf = alloca (PBUFSIZ);
+ long sizeof_junkbuf = PBUFSIZ;
+ char *junkbuf = alloca (sizeof_junkbuf);
int ch;
int tcount = 0;
{
/* It's probably an old response, and we're out of sync.
Just gobble up the packet and ignore it. */
- getpkt (junkbuf, 0);
+ getpkt (junkbuf, sizeof_junkbuf, 0);
continue; /* Now, go look for + */
}
default:
/* Come here after finding the start of the frame. Collect the rest
into BUF, verifying the checksum, length, and handling run-length
- compression. Returns 0 on any error, 1 on success. */
+ compression. No more than sizeof_buf-1 characters are read so that
+ the buffer can be NUL terminated.
-static int
-read_frame (buf)
- char *buf;
+ Returns -1 on error, number of characters in buffer (ignoring the
+ trailing NULL) on success. (could be extended to return one of the
+ SERIAL status indications). */
+
+static long
+read_frame (char *buf,
+ long sizeof_buf)
{
unsigned char csum;
- char *bp;
+ long bc;
int c;
csum = 0;
- bp = buf;
+ bc = 0;
while (1)
{
+ /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
c = readchar (remote_timeout);
-
switch (c)
{
case SERIAL_TIMEOUT:
if (remote_debug)
fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
- return 0;
+ return -1;
case '$':
if (remote_debug)
fputs_filtered ("Saw new packet start in middle of old one\n",
gdb_stdlog);
- return 0; /* Start a new packet, count retries */
+ return -1; /* Start a new packet, count retries */
case '#':
{
unsigned char pktcsum;
- *bp = '\000';
+ buf[bc] = '\0';
pktcsum = fromhex (readchar (remote_timeout)) << 4;
pktcsum |= fromhex (readchar (remote_timeout));
if (csum == pktcsum)
- return 1;
+ return bc;
if (remote_debug)
{
fputs_filtered (buf, gdb_stdlog);
fputs_filtered ("\n", gdb_stdlog);
}
- return 0;
+ /* Number of characters in buffer ignoring trailing
+ NUL. */
+ return -1;
}
case '*': /* Run length encoding */
{
repeat += fromhex (c);
}
+ /* The character before ``*'' is repeated. */
+
if (repeat > 0 && repeat <= 255
- && bp + repeat - 1 < buf + PBUFSIZ - 1)
+ && bc > 0
+ && bc + repeat < sizeof_buf - 1)
{
- memset (bp, *(bp - 1), repeat);
- bp += c;
+ memset (&buf[bc], buf[bc - 1], repeat);
+ bc += repeat;
continue;
}
- *bp = '\0';
+ buf[bc] = '\0';
printf_filtered ("Repeat count %d too large for buffer: ", repeat);
puts_filtered (buf);
puts_filtered ("\n");
- return 0;
+ return -1;
}
default:
- if (bp < buf + PBUFSIZ - 1)
+ if (bc < sizeof_buf - 1)
{
- *bp++ = c;
+ buf[bc++] = c;
csum += c;
continue;
}
- *bp = '\0';
+ buf[bc] = '\0';
puts_filtered ("Remote packet too long: ");
puts_filtered (buf);
puts_filtered ("\n");
- return 0;
+ return -1;
}
}
}
/* Read a packet from the remote machine, with error checking, and
- store it in BUF. BUF is expected to be of size PBUFSIZ. If
- FOREVER, wait forever rather than timing out; this is used while
- the target is executing user code. */
+ store it in BUF. If FOREVER, wait forever rather than timing out;
+ this is used (in synchronous mode) to wait for a target that is is
+ executing user code to stop. */
void
-getpkt (buf, forever)
- char *buf;
- int forever;
+getpkt (char *buf,
+ long sizeof_buf,
+ int forever)
{
int c;
int tries;
/* We've found the start of a packet, now collect the data. */
- val = read_frame (buf);
+ val = read_frame (buf, sizeof_buf);
- if (val == 1)
+ if (val >= 0)
{
if (remote_debug)
{
sprintf (p, ",%d", bp_size);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] != '\0')
{
sprintf (p, ",%d", bp_size);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
return (buf[0] == 'E');
}
sprintf (p, ",%x", len);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0' || buf [0] == 'E')
return -1;
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0' || buf [0] == 'E')
return -1;
*p = '\0';
putpkt (buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0' || buf [0] == 'E')
return -1;
*p = '\0';
putpkt(buf);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0' || buf [0] == 'E')
return -1;
bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == 'E')
error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
sectname, lma, lma + size);
if (i < 0)
return i;
- getpkt (outbuf, 0);
+ getpkt (outbuf, *bufsiz, 0);
return 0;
}
{
/* XXX - see also tracepoint.c:remote_get_noisy_reply() */
buf[0] = '\0';
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == '\0')
error ("Target does not support this command\n");
if (buf[0] == 'O' && buf[1] != 'K')
puts_filtered ("\n");
putpkt (args);
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
puts_filtered ("received: ");
print_packet (buf);
puts_filtered ("\n");
*/
static void
-remote_info_process (args, from_tty)
- char *args;
- int from_tty;
+remote_info_process (char *args, int from_tty)
{
char *buf = alloca (PBUFSIZ);
error ("Command can only be used when connected to the remote target.");
putpkt ("qfProcessInfo");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
if (buf[0] == 0)
return; /* Silently: target does not support this feature. */
{
remote_console_output (&buf[1]);
putpkt ("qsProcessInfo");
- getpkt (buf, 0);
+ getpkt (buf, PBUFSIZ, 0);
}
}
*/
static void
-remote_cisco_open (name, from_tty)
- char *name;
- int from_tty;
+remote_cisco_open (char *name, int from_tty)
{
if (name == 0)
error (
}
static void
-remote_cisco_close (quitting)
- int quitting;
+remote_cisco_close (int quitting)
{
remote_cisco_mode = 0;
remote_close (quitting);
extern int quit_flag;
static int
-readsocket ()
+readsocket (void)
{
int data;
}
static int
-readtty ()
+readtty (void)
{
int tty_bytecount;
}
static int
-minitelnet ()
+minitelnet (void)
{
fd_set input; /* file descriptors for select */
int tablesize; /* max number of FDs for select */
}
static int
-remote_cisco_wait (pid, status)
- int pid;
- struct target_waitstatus *status;
+remote_cisco_wait (int pid, struct target_waitstatus *status)
{
if (minitelnet () != ENTER_DEBUG)
{
target. */
static void
-init_remote_async_ops ()
+init_remote_async_ops (void)
{
remote_async_ops.to_shortname = "async";
remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
remote vector and adding to it. */
static void
-init_extended_async_remote_ops ()
+init_extended_async_remote_ops (void)
{
extended_async_remote_ops = remote_async_ops;
}
static void
-set_remote_cmd (args, from_tty)
- char *args;
- int from_tty;
+set_remote_cmd (char *args, int from_tty)
{
}