summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jacobowitz <dan@debian.org>2006-07-03 15:58:50 +0000
committerDaniel Jacobowitz <dan@debian.org>2006-07-03 15:58:50 +0000
commit1bf0eaec107c00f238b23a11a735535d53adac3f (patch)
tree5fd320ff08d1b328de01f8d301f9377ec2f6b5a9
parent7bd3b30deb0e0c308adf23aa6344bf7ceba33760 (diff)
downloadgdb-1bf0eaec107c00f238b23a11a735535d53adac3f.tar.gz
Backport rs->buf patch from HEAD.
-rw-r--r--ChangeLog.csl51
-rw-r--r--gdb/remote.c486
-rw-r--r--gdb/remote.h9
-rw-r--r--gdb/tracepoint.c52
4 files changed, 353 insertions, 245 deletions
diff --git a/ChangeLog.csl b/ChangeLog.csl
index 91d5a6cca5f..d0e1bb62cde 100644
--- a/ChangeLog.csl
+++ b/ChangeLog.csl
@@ -1,3 +1,54 @@
+2006-07-03 Daniel Jacobowitz <dan@codesourcery.com>
+
+ gdb/
+ * remote.c (remote_query_packet_info): Update for backported patch.
+ (fetch_registers_using_g, store_registers_using_G)
+ (remote_read_qpart): Likewise.
+
+ Backport:
+ 2006-03-30 Daniel Jacobowitz <dan@codesourcery.com>
+ * remote.c (struct remote_state): Add BUF and BUF_SIZE.
+ (init_remote_state): Initialize the new fields.
+ (get_memory_packet_size): Update BUF and BUF_SIZE if necessary.
+ (set_thread, remote_thread_alive, remote_unpack_thread_info_response)
+ (remote_get_threadinfo, parse_threadlist_response)
+ (remote_get_threadlist, remote_current_thread, remote_threads_info)
+ (remote_threads_extra_info, extended_remote_restart, get_offsets)
+ (remote_check_symbols, remote_open_1, remote_detach)
+ (remove_vcont_probe, remote_vcont_resume, remote_resume)
+ (remote_wait, remote_async_wait, fetch_register_using_p)
+ (remote_fetch_registers, store_register_using_P)
+ (remote_store_registers, check_binary_download, remote_write_bytes)
+ (remote_read_bytes, remote_insert_breakpoint)
+ (remote_remove_breakpoint, remote_insert_watchpoint)
+ (remote_remove_watchpoint, remote_insert_hw_breakpoint)
+ (remote_remove_hw_breakpoint, compare_sections_command)
+ (remote_xfer_partial, remote_rcmd, packet_command)
+ (remote_get_thread_local_address): Use the global incoming buffer
+ instead of alloca or xmalloc. Limit outgoing packets to
+ rs->remote_packet_size and incoming packets to rs->buf_size.
+ Update calls to getpkt and remote_send.
+ (remote_send): Take arguments by reference.
+ (putpkt_binary): Eliminate junkbuf. Use skip_frame.
+ (skip_frame): New function.
+ (read_frame): Take arguments by reference. Expand the packet
+ buffer instead of issuing an error.
+ (getpkt, getpkt_sane): Take arguments by reference.
+ * remote.h (getpkt): Update prototype and doc.
+ * tracepoint.c (remote_get_noisy_reply): Take arguments by
+ reference.
+ (target_buf): Change from array to pointer.
+ (target_buf_size): New variable.
+ (remote_set_transparent_ranges): Update call to getpkt.
+ (trace_start_command, trace_stop_command, trace_status_command):
+ Update calls to remote_get_noisy_reply.
+ (finish_tfind_command): Take arguments by reference.
+ (trace_find_command, trace_find_pc_command)
+ (trace_find_tracepoint_command, trace_find_line_command):
+ (trace_find_range_command, trace_find_outside_command): Update
+ calls to finish_tfind_command.
+ (_initialize_tracepoint): Initialize target_buf_size and target_buf.
+
2006-06-23 Nathan Sidwell <nathan@codesourcery.com>
gdb/testsuite/
diff --git a/gdb/remote.c b/gdb/remote.c
index 131df894c15..a59a710d874 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -64,7 +64,7 @@
/* Prototypes for local functions. */
static void cleanup_sigint_signal_handler (void *dummy);
static void initialize_sigint_signal_handler (void);
-static int getpkt_sane (char *buf, long sizeof_buf, int forever);
+static int getpkt_sane (char **buf, long *sizeof_buf, int forever);
static void handle_remote_sigint (int);
static void handle_remote_sigint_twice (int);
@@ -105,7 +105,7 @@ static void extended_remote_mourn (void);
static void remote_mourn_1 (struct target_ops *);
-static void remote_send (char *buf, long sizeof_buf);
+static void remote_send (char **buf, long *sizeof_buf_p);
static int readchar (int timeout);
@@ -133,7 +133,9 @@ static int remote_thread_alive (ptid_t);
static void get_offsets (void);
-static long read_frame (char *buf, long sizeof_buf);
+static void skip_frame (void);
+
+static long read_frame (char **buf_p, long *sizeof_buf);
static int remote_insert_breakpoint (CORE_ADDR, bfd_byte *);
@@ -243,6 +245,15 @@ struct remote_state
It is also used as a cap on the size of read/write packets. */
long remote_packet_size;
+ /* A buffer to use for incoming packets, and its current size. The
+ buffer is grown dynamically for larger incoming packets.
+ Outgoing packets may also be constructed in this buffer.
+ BUF_SIZE is always at least REMOTE_PACKET_SIZE;
+ REMOTE_PACKET_SIZE should be used to limit the length of outgoing
+ packets. */
+ char *buf;
+ long buf_size;
+
/* This flag is set if we negotiated packet size explicitly (and
can bypass various heuristics). */
int explicit_packet_size;
@@ -333,6 +344,14 @@ init_remote_state (struct gdbarch *gdbarch)
/* This one is filled in when a ``g'' packet is received. */
rs->actual_register_packet_size = 0;
+ /* Create the buffer at a default size. Note that this would
+ leak memory if the gdbarch were ever destroyed; there's no
+ way to register a destructor for it, and we can't realloc
+ using the gdbarch obstack. But gdbarches are never
+ destroyed. */
+ rs->buf_size = rs->remote_packet_size;
+ rs->buf = xmalloc (rs->buf_size);
+
return rs;
}
@@ -486,6 +505,15 @@ get_memory_packet_size (struct memory_packet_config *config)
what_they_get = MAX_REMOTE_PACKET_SIZE;
if (what_they_get < MIN_REMOTE_PACKET_SIZE)
what_they_get = MIN_REMOTE_PACKET_SIZE;
+
+ /* Make sure there is room in the global buffer for this packet
+ (including its trailing NUL byte). */
+ if (rs->buf_size < what_they_get + 1)
+ {
+ rs->buf_size = 2 * what_they_get;
+ rs->buf = xrealloc (rs->buf, 2 * what_they_get);
+ }
+
return what_they_get;
}
@@ -937,7 +965,7 @@ static void
set_thread (int th, int gen)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
int state = gen ? general_thread : continue_thread;
if (state == th)
@@ -955,7 +983,7 @@ set_thread (int th, int gen)
else
xsnprintf (&buf[2], rs->remote_packet_size - 2, "%x", th);
putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (gen)
general_thread = th;
else
@@ -967,15 +995,16 @@ set_thread (int th, int gen)
static int
remote_thread_alive (ptid_t ptid)
{
+ struct remote_state *rs = get_remote_state ();
int tid = PIDGET (ptid);
- char buf[16];
+ char *buf = rs->buf;
if (tid < 0)
- xsnprintf (buf, sizeof (buf), "T-%08x", -tid);
+ xsnprintf (buf, rs->remote_packet_size, "T-%08x", -tid);
else
- xsnprintf (buf, sizeof (buf), "T%08x", tid);
+ xsnprintf (buf, rs->remote_packet_size, "T%08x", tid);
putpkt (buf);
- getpkt (buf, sizeof (buf), 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
return (buf[0] == 'O' && buf[1] == 'K');
}
@@ -1384,7 +1413,7 @@ remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
int mask, length;
int tag;
threadref ref;
- char *limit = pkt + rs->remote_packet_size; /* Plausible parsing limit. */
+ char *limit = pkt + rs->buf_size; /* Plausible parsing limit. */
int retval = 1;
/* info->threadid = 0; FIXME: implement zero_threadref. */
@@ -1475,11 +1504,11 @@ remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
{
struct remote_state *rs = get_remote_state ();
int result;
- char *threadinfo_pkt = alloca (rs->remote_packet_size);
+ char *threadinfo_pkt = rs->buf;
pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
putpkt (threadinfo_pkt);
- getpkt (threadinfo_pkt, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
result = remote_unpack_thread_info_response (threadinfo_pkt + 2,
threadid, info);
return result;
@@ -1513,7 +1542,7 @@ parse_threadlist_response (char *pkt, int result_limit,
resultcount = 0;
/* Assume the 'q' and 'M chars have been stripped. */
- limit = pkt + (rs->remote_packet_size - BUF_THREAD_ID_SIZE);
+ limit = pkt + (rs->buf_size - BUF_THREAD_ID_SIZE);
/* done parse past here */
pkt = unpack_byte (pkt, &count); /* count field */
pkt = unpack_nibble (pkt, &done);
@@ -1536,21 +1565,19 @@ remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
{
struct remote_state *rs = get_remote_state ();
static threadref echo_nextthread;
- char *threadlist_packet = alloca (rs->remote_packet_size);
- char *t_response = alloca (rs->remote_packet_size);
+ char *threadlist_packet = rs->buf;
int result = 1;
/* Trancate result limit to be smaller than the packet size. */
if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= rs->remote_packet_size)
result_limit = (rs->remote_packet_size / BUF_THREAD_ID_SIZE) - 2;
- pack_threadlist_request (threadlist_packet,
- startflag, result_limit, nextthread);
- putpkt (threadlist_packet);
- getpkt (t_response, rs->remote_packet_size, 0);
+ pack_threadlist_request (rs->buf, startflag, result_limit, nextthread);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
*result_count =
- parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
+ parse_threadlist_response (rs->buf + 2, result_limit, &echo_nextthread,
threadlist, done);
if (!threadmatch (&echo_nextthread, nextthread))
@@ -1655,10 +1682,10 @@ static ptid_t
remote_current_thread (ptid_t oldpid)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
putpkt ("qC");
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (buf[0] == 'Q' && buf[1] == 'C')
/* Use strtoul here, so we'll correctly parse values whose highest
bit is set. The protocol carries them as a simple series of
@@ -1694,7 +1721,6 @@ static void
remote_threads_info (void)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
char *bufp;
int tid;
@@ -1704,8 +1730,8 @@ remote_threads_info (void)
if (use_threadinfo_query)
{
putpkt ("qfThreadInfo");
- bufp = buf;
- getpkt (bufp, rs->remote_packet_size, 0);
+ bufp = rs->buf;
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (bufp[0] != '\0') /* q packet recognized */
{
while (*bufp++ == 'm') /* reply contains one or more TID */
@@ -1724,8 +1750,8 @@ remote_threads_info (void)
}
while (*bufp++ == ','); /* comma-separated list */
putpkt ("qsThreadInfo");
- bufp = buf;
- getpkt (bufp, rs->remote_packet_size, 0);
+ bufp = rs->buf;
+ getpkt (&rs->buf, &rs->buf_size, 0);
}
return; /* done */
}
@@ -1755,7 +1781,6 @@ remote_threads_extra_info (struct thread_info *tp)
threadref id;
struct gdb_ext_thread_info threadinfo;
static char display_buf[100]; /* arbitrary... */
- char *bufp = alloca (rs->remote_packet_size);
int n = 0; /* position in display_buf */
if (remote_desc == 0) /* paranoia */
@@ -1764,10 +1789,12 @@ remote_threads_extra_info (struct thread_info *tp)
if (use_threadextra_query)
{
+ char *bufp = rs->buf;
+
xsnprintf (bufp, rs->remote_packet_size, "qThreadExtraInfo,%x",
PIDGET (tp->ptid));
putpkt (bufp);
- getpkt (bufp, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (bufp[0] != 0)
{
n = min (strlen (bufp) / 2, sizeof (display_buf));
@@ -1813,19 +1840,18 @@ static void
extended_remote_restart (void)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
/* Send the restart command; for reasons I don't understand the
remote side really expects a number after the "R". */
- xsnprintf (buf, rs->remote_packet_size, "R%x", 0);
- putpkt (buf);
+ xsnprintf (rs->buf, rs->remote_packet_size, "R%x", 0);
+ putpkt (rs->buf);
remote_fileio_reset ();
/* Now query for status so this looks just like we restarted
gdbserver from scratch. */
putpkt ("?");
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
}
/* Clean up connection to a remote debugger. */
@@ -1844,7 +1870,7 @@ static void
get_offsets (void)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
char *ptr;
int lose;
CORE_ADDR text_addr, data_addr, bss_addr;
@@ -1854,7 +1880,7 @@ get_offsets (void)
return;
putpkt ("qOffsets");
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
switch (packet_ok (buf, &remote_protocol_packets[PACKET_qOffsets]))
{
@@ -2016,14 +2042,17 @@ remote_check_symbols (struct objfile *objfile)
if (remote_protocol_packets[PACKET_qSymbol].support == PACKET_DISABLE)
return;
- msg = alloca (rs->remote_packet_size);
- reply = alloca (rs->remote_packet_size);
+ /* Allocate a message buffer. We can't reuse the input buffer in RS,
+ because we need both at the same time. */
+ msg = alloca (rs->remote_packet_size);
+
+ reply = rs->buf;
/* Invite target to request symbol lookups. */
putpkt ("qSymbol::");
- getpkt (reply, rs->remote_packet_size, 0);
- packet_ok (reply, &remote_protocol_packets[PACKET_qSymbol]);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSymbol]);
while (strncmp (reply, "qSymbol:", 8) == 0)
{
@@ -2038,7 +2067,7 @@ remote_check_symbols (struct objfile *objfile)
paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
&reply[8]);
putpkt (msg);
- getpkt (reply, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
}
}
@@ -2066,15 +2095,13 @@ static void
remote_query_packet_info (void)
{
struct remote_state *rs = get_remote_state ();
- char *reply, *next;
+ char *next;
int i;
- reply = alloca (rs->remote_packet_size);
-
putpkt ("qPacketInfo");
- getpkt (reply, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- next = reply;
+ next = rs->buf;
while (*next)
{
enum packet_support is_supported;
@@ -2116,9 +2143,6 @@ remote_query_packet_info (void)
packet_size = strtol (value, &value_end, 16);
if (*value != '\0' && *value_end == '\0')
{
- /* MERGE WARNING: This needs the infinite length
- incoming packet support, which in turn needs us
- to adjust rs->buf_size here. */
if (packet_size > MAX_REMOTE_PACKET_SIZE)
{
warning (_("limiting remote suggested packet size (%d bytes) to %d"),
@@ -2156,6 +2180,16 @@ remote_query_packet_info (void)
}
}
+ /* If we increased the packet size, make sure to increase the global
+ buffer size also. We delay this until after parsing the entire
+ qSupported packet, because this is the same buffer we were
+ parsing. */
+ if (rs->buf_size < rs->remote_packet_size)
+ {
+ rs->buf_size = rs->remote_packet_size;
+ rs->buf = xrealloc (rs->buf, rs->buf_size);
+ }
+
/* Default some unmentioned packets to unsupported. */
for (i = 0; i < PACKET_MAX; i++)
if (remote_protocol_packets[i].must_be_reported
@@ -2301,9 +2335,8 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target,
if (extended_p)
{
/* Tell the remote that we are using the extended protocol. */
- char *buf = alloca (rs->remote_packet_size);
putpkt ("!");
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
}
post_create_inferior (&current_target, from_tty);
@@ -2321,14 +2354,13 @@ static void
remote_detach (char *args, int from_tty)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
if (args)
error (_("Argument given to \"detach\" when remotely debugging."));
/* Tell the remote target to detach. */
- strcpy (buf, "D");
- remote_send (buf, rs->remote_packet_size);
+ strcpy (rs->buf, "D");
+ remote_send (&rs->buf, &rs->buf_size);
/* Unregister the file descriptor from the event loop. */
if (target_is_async_p ())
@@ -2422,11 +2454,13 @@ bin2hex (const gdb_byte *bin, char *hex, int count)
the response. */
static void
-remote_vcont_probe (struct remote_state *rs, char *buf)
+remote_vcont_probe (struct remote_state *rs)
{
+ char *buf = rs->buf;
+
strcpy (buf, "vCont?");
putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
/* Make sure that the features we assume are supported. */
if (strncmp (buf, "vCont", 5) == 0)
@@ -2480,17 +2514,11 @@ remote_vcont_resume (ptid_t ptid, int step, enum target_signal siggnal)
char *buf = NULL, *outbuf;
struct cleanup *old_cleanup;
- buf = xmalloc (rs->remote_packet_size);
- old_cleanup = make_cleanup (xfree, buf);
-
if (remote_protocol_packets[PACKET_vCont].support == PACKET_SUPPORT_UNKNOWN)
- remote_vcont_probe (rs, buf);
+ remote_vcont_probe (rs);
if (remote_protocol_packets[PACKET_vCont].support == PACKET_DISABLE)
- {
- do_cleanups (old_cleanup);
- return 0;
- }
+ return 0;
/* If we could generate a wider range of packets, we'd have to worry
about overflowing BUF. Should there be a generic
@@ -2538,7 +2566,7 @@ remote_vcont_resume (ptid_t ptid, int step, enum target_signal siggnal)
}
gdb_assert (outbuf && strlen (outbuf) < rs->remote_packet_size);
- make_cleanup (xfree, outbuf);
+ old_cleanup = make_cleanup (xfree, outbuf);
putpkt (outbuf);
@@ -2557,7 +2585,7 @@ static void
remote_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
int pid = PIDGET (ptid);
last_sent_signal = siggnal;
@@ -2827,7 +2855,7 @@ static ptid_t
remote_wait (ptid_t ptid, struct target_waitstatus *status)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
ULONGEST thread_num = -1;
ULONGEST addr;
@@ -2839,7 +2867,7 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
char *p;
ofunc = signal (SIGINT, remote_interrupt);
- getpkt (buf, rs->remote_packet_size, 1);
+ getpkt (&rs->buf, &rs->buf_size, 1);
signal (SIGINT, ofunc);
/* This is a hook for when we need to do something (perhaps the
@@ -3016,7 +3044,7 @@ static ptid_t
remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
ULONGEST thread_num = -1;
ULONGEST addr;
@@ -3035,7 +3063,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
_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, rs->remote_packet_size, wait_forever_enabled_p);
+ getpkt (&rs->buf, &rs->buf_size, wait_forever_enabled_p);
if (!target_is_async_p ())
signal (SIGINT, ofunc);
@@ -3214,7 +3242,7 @@ static int
fetch_register_using_p (struct packet_reg *reg)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size), *p;
+ char *buf = rs->buf, *p;
char regp[MAX_REGISTER_SIZE];
int i;
@@ -3228,7 +3256,7 @@ fetch_register_using_p (struct packet_reg *reg)
*p++ = 'p';
p += hexnumstr (p, reg->pnum);
*p++ = '\0';
- remote_send (buf, rs->remote_packet_size);
+ remote_send (&rs->buf, &rs->buf_size);
switch (packet_ok (buf, &remote_protocol_packets[PACKET_p]))
{
@@ -3267,23 +3295,22 @@ static void
fetch_registers_using_g (void)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
int i, buf_len;
char *p;
char *regs;
set_thread (PIDGET (inferior_ptid), 1);
- sprintf (buf, "g");
- remote_send (buf, rs->remote_packet_size);
+ sprintf (rs->buf, "g");
+ remote_send (&rs->buf, &rs->buf_size);
- buf_len = strlen (buf);
+ buf_len = strlen (rs->buf);
/* Sanity check the received packet. */
if (buf_len % 2 != 0)
- error (_("Remote 'g' packet reply is of odd length: %s"), buf);
+ error (_("Remote 'g' packet reply is of odd length: %s"), rs->buf);
if (REGISTER_BYTES_OK_P () && !REGISTER_BYTES_OK (buf_len / 2))
- error (_("Remote 'g' packet reply is too short: %s"), buf);
+ error (_("Remote 'g' packet reply is too short: %s"), rs->buf);
/* Save the size of the packet sent to us by the target. It is used
as a heuristic when determining the max size of packets that the
@@ -3325,22 +3352,22 @@ fetch_registers_using_g (void)
/* We can get out of synch in various cases. If the first character
in the buffer is not a hex character, assume that has happened
and try to fetch another packet to read. */
- while ((buf[0] < '0' || buf[0] > '9')
- && (buf[0] < 'A' || buf[0] > 'F')
- && (buf[0] < 'a' || buf[0] > 'f')
- && buf[0] != 'x') /* New: unavailable register value. */
+ while ((rs->buf[0] < '0' || rs->buf[0] > '9')
+ && (rs->buf[0] < 'A' || rs->buf[0] > 'F')
+ && (rs->buf[0] < 'a' || rs->buf[0] > 'f')
+ && rs->buf[0] != 'x') /* New: unavailable register value. */
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"Bad register packet; fetching a new packet\n");
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
}
/* Reply describes registers byte by byte, each byte encoded as two
hex characters. Suck them all up, then supply them to the
register cacheing/storage mechanism. */
- p = buf;
+ p = rs->buf;
for (i = 0; i < rs->sizeof_g_packet; i++)
{
if (p[0] == 0 || p[1] == 0)
@@ -3362,13 +3389,13 @@ fetch_registers_using_g (void)
struct packet_reg *r = &rs->regs[i];
if (r->in_g_packet)
{
- if (r->offset * 2 >= strlen (buf))
+ if (r->offset * 2 >= strlen (rs->buf))
/* This shouldn't happen - we adjusted in_g_packet above. */
internal_error (__FILE__, __LINE__,
"unexpected end of 'g' packet reply");
- else if (buf[r->offset * 2] == 'x')
+ else if (rs->buf[r->offset * 2] == 'x')
{
- gdb_assert (r->offset * 2 < strlen (buf));
+ gdb_assert (r->offset * 2 < strlen (rs->buf));
/* The register isn't available, mark it as such (at
the same time setting the value to zero). */
regcache_raw_supply (current_regcache, r->regnum, NULL);
@@ -3462,7 +3489,7 @@ store_register_using_P (struct packet_reg *reg)
{
struct remote_state *rs = get_remote_state ();
/* Try storing a single register. */
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
gdb_byte regp[MAX_REGISTER_SIZE];
char *p;
@@ -3476,7 +3503,7 @@ store_register_using_P (struct packet_reg *reg)
p = buf + strlen (buf);
regcache_raw_collect (current_regcache, reg->regnum, regp);
bin2hex (regp, p, register_size (current_gdbarch, reg->regnum));
- remote_send (buf, rs->remote_packet_size);
+ remote_send (&rs->buf, &rs->buf_size);
switch (packet_ok (buf, &remote_protocol_packets[PACKET_P]))
{
@@ -3499,7 +3526,6 @@ static void
store_registers_using_G ()
{
struct remote_state *rs = get_remote_state ();
- char *buf;
gdb_byte *regs;
char *p;
@@ -3519,13 +3545,12 @@ store_registers_using_G ()
/* Command describes registers byte by byte,
each byte encoded as two hex characters. */
- buf = alloca (rs->remote_packet_size);
- p = buf;
+ p = rs->buf;
*p++ = 'G';
/* remote_prepare_to_store insures that rs->sizeof_g_packet gets
updated. */
bin2hex (regs, p, rs->sizeof_g_packet);
- remote_send (buf, rs->remote_packet_size);
+ remote_send (&rs->buf, &rs->buf_size);
}
/* Store register REGNUM, or all registers if REGNUM == -1, from the contents
@@ -3654,7 +3679,7 @@ check_binary_download (CORE_ADDR addr)
break;
case PACKET_SUPPORT_UNKNOWN:
{
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
char *p;
p = buf;
@@ -3666,7 +3691,7 @@ check_binary_download (CORE_ADDR addr)
*p = '\0';
putpkt_binary (buf, (int) (p - buf));
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (buf[0] == '\0')
{
@@ -3699,10 +3724,10 @@ check_binary_download (CORE_ADDR addr)
int
remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
{
+ struct remote_state *rs = get_remote_state ();
char *buf;
char *p;
char *plen;
- long sizeof_buf;
int plenlen;
int todo;
int nr_bytes;
@@ -3714,10 +3739,9 @@ remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
payload_size = get_memory_write_packet_size ();
- /* Compute the size, and then allocate space for the largest
- possible packet. Include space for an extra trailing NUL. */
- sizeof_buf = payload_size + 1;
- buf = alloca (sizeof_buf);
+ /* The packet buffer will be large enough for the payload;
+ get_memory_packet_size ensures this. */
+ buf = rs->buf;
/* Compute the size of the actual payload by subtracting out the
packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
@@ -3824,7 +3848,7 @@ remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
}
putpkt_binary (buf, (int) (p - buf));
- getpkt (buf, sizeof_buf, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (buf[0] == 'E')
{
@@ -3859,15 +3883,15 @@ remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
int
remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
{
+ struct remote_state *rs = get_remote_state ();
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 NULL. */
- buf = alloca (sizeof_buf);
+ /* The packet buffer will be large enough for the payload;
+ get_memory_packet_size ensures this. */
+ buf = rs->buf;
origlen = len;
while (len > 0)
@@ -3889,7 +3913,7 @@ remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
*p = '\0';
putpkt (buf);
- getpkt (buf, sizeof_buf, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (buf[0] == 'E'
&& isxdigit (buf[1]) && isxdigit (buf[2])
@@ -3988,18 +4012,20 @@ readchar (int timeout)
return ch;
}
-/* Send the command in BUF to the remote machine, and read the reply
- into BUF. Report an error if we get an error reply. */
+/* Send the command in *BUF to the remote machine, and read the reply
+ into *BUF. Report an error if we get an error reply. Resize
+ *BUF using xrealloc if necessary to hold the result, and update
+ *SIZEOF_BUF. */
static void
-remote_send (char *buf,
- long sizeof_buf)
+remote_send (char **buf,
+ long *sizeof_buf)
{
- putpkt (buf);
+ putpkt (*buf);
getpkt (buf, sizeof_buf, 0);
- if (buf[0] == 'E')
- error (_("Remote failure reply: %s"), buf);
+ if ((*buf)[0] == 'E')
+ error (_("Remote failure reply: %s"), *buf);
}
/* Display a null-terminated packet on stdout, for debugging, using C
@@ -4032,8 +4058,6 @@ putpkt_binary (char *buf, int cnt)
int i;
unsigned char csum = 0;
char *buf2 = alloca (cnt + 6);
- long sizeof_junkbuf = rs->remote_packet_size;
- char *junkbuf = alloca (sizeof_junkbuf);
int ch;
int tcount = 0;
@@ -4115,7 +4139,7 @@ putpkt_binary (char *buf, int cnt)
was lost. Gobble up the packet and ack it so it
doesn't get retransmitted when we resend this
packet. */
- read_frame (junkbuf, sizeof_junkbuf);
+ skip_frame ();
serial_write (remote_desc, "+", 1);
continue; /* Now, go look for +. */
}
@@ -4149,29 +4173,65 @@ putpkt_binary (char *buf, int cnt)
}
}
+/* Come here after finding the start of a frame when we expected an
+ ack. Do our best to discard the rest of this packet. */
+
+static void
+skip_frame (void)
+{
+ int c;
+
+ while (1)
+ {
+ c = readchar (remote_timeout);
+ switch (c)
+ {
+ case SERIAL_TIMEOUT:
+ /* Nothing we can do. */
+ return;
+ case '#':
+ /* Discard the two bytes of checksum and stop. */
+ c = readchar (remote_timeout);
+ if (c >= 0)
+ c = readchar (remote_timeout);
+
+ return;
+ case '*': /* Run length encoding. */
+ /* Discard the repeat count. */
+ c = readchar (remote_timeout);
+ if (c < 0)
+ return;
+ break;
+ default:
+ /* A regular character. */
+ break;
+ }
+ }
+}
+
/* Come here after finding the start of the frame. Collect the rest
- into BUF, verifying the checksum, length, and handling run-length
- compression. No more than sizeof_buf-1 characters are read so that
- the buffer can be NUL terminated.
+ into *BUF, verifying the checksum, length, and handling run-length
+ compression. NUL terminate the buffer. If there is not enough room,
+ expand *BUF using xrealloc.
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)
+read_frame (char **buf_p,
+ long *sizeof_buf)
{
unsigned char csum;
long bc;
int c;
+ char *buf = *buf_p;
csum = 0;
bc = 0;
while (1)
{
- /* ASSERT (bc < sizeof_buf - 1) - space for trailing NULL. */
c = readchar (remote_timeout);
switch (c)
{
@@ -4238,51 +4298,53 @@ read_frame (char *buf,
/* The character before ``*'' is repeated. */
- if (repeat > 0 && repeat <= 255
- && bc > 0
- && bc + repeat - 1 < sizeof_buf - 1)
+ if (repeat > 0 && repeat <= 255 && bc > 0)
{
+ if (bc + repeat - 1 >= *sizeof_buf - 1)
+ {
+ /* Make some more room in the buffer. */
+ *sizeof_buf += repeat;
+ *buf_p = xrealloc (*buf_p, *sizeof_buf);
+ buf = *buf_p;
+ }
+
memset (&buf[bc], buf[bc - 1], repeat);
bc += repeat;
continue;
}
buf[bc] = '\0';
- printf_filtered (_("Repeat count %d too large for buffer: "),
- repeat);
- puts_filtered (buf);
- puts_filtered ("\n");
+ printf_filtered (_("Invalid run length encoding: %s\n"), buf);
return -1;
}
default:
- if (bc < sizeof_buf - 1)
+ if (bc >= *sizeof_buf - 1)
{
- buf[bc++] = c;
- csum += c;
- continue;
+ /* Make some more room in the buffer. */
+ *sizeof_buf *= 2;
+ *buf_p = xrealloc (*buf_p, *sizeof_buf);
+ buf = *buf_p;
}
- buf[bc] = '\0';
- puts_filtered ("Remote packet too long: ");
- puts_filtered (buf);
- puts_filtered ("\n");
-
- return -1;
+ buf[bc++] = c;
+ csum += c;
+ continue;
}
}
}
/* Read a packet from the remote machine, with error checking, and
- 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. */
+ store it in *BUF. Resize *BUF using xrealloc if necessary to hold
+ the result, and update *SIZEOF_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. */
/* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
don't have to change all the calls to getpkt to deal with the
return value, because at the moment I don't know what the right
thing to do it for those. */
void
-getpkt (char *buf,
- long sizeof_buf,
+getpkt (char **buf,
+ long *sizeof_buf,
int forever)
{
int timed_out;
@@ -4292,22 +4354,21 @@ getpkt (char *buf,
/* Read a packet from the remote machine, with error checking, and
- 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. If FOREVER == 0, this function is
- allowed to time out gracefully and return an indication of this to
- the caller. */
+ store it in *BUF. Resize *BUF using xrealloc if necessary to hold
+ the result, and update *SIZEOF_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. If FOREVER ==
+ 0, this function is allowed to time out gracefully and return an
+ indication of this to the caller. */
static int
-getpkt_sane (char *buf,
- long sizeof_buf,
- int forever)
+getpkt_sane (char **buf, long *sizeof_buf, int forever)
{
int c;
int tries;
int timeout;
int val;
- strcpy (buf, "timeout");
+ strcpy (*buf, "timeout");
if (forever)
{
@@ -4359,7 +4420,7 @@ getpkt_sane (char *buf,
if (remote_debug)
{
fprintf_unfiltered (gdb_stdlog, "Packet received: ");
- fputstr_unfiltered (buf, 0, gdb_stdlog);
+ fputstr_unfiltered (*buf, 0, gdb_stdlog);
fprintf_unfiltered (gdb_stdlog, "\n");
}
serial_write (remote_desc, "+", 1);
@@ -4564,8 +4625,7 @@ remote_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
{
- char *buf = alloca (rs->remote_packet_size);
- char *p = buf;
+ char *p = rs->buf;
addr = remote_address_masked (addr);
*(p++) = 'Z';
@@ -4575,10 +4635,10 @@ remote_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
BREAKPOINT_FROM_PC (&addr, &bp_size);
sprintf (p, ",%d", bp_size);
- putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- switch (packet_ok (buf, &remote_protocol_packets[PACKET_Z0]))
+ switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0]))
{
case PACKET_ERROR:
return -1;
@@ -4616,8 +4676,7 @@ remote_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
{
- char *buf = alloca (rs->remote_packet_size);
- char *p = buf;
+ char *p = rs->buf;
*(p++) = 'z';
*(p++) = '0';
@@ -4628,10 +4687,10 @@ remote_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
BREAKPOINT_FROM_PC (&addr, &bp_size);
sprintf (p, ",%d", bp_size);
- putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- return (buf[0] == 'E');
+ return (rs->buf[0] == 'E');
}
#ifdef DEPRECATED_REMOTE_BREAKPOINT
@@ -4665,23 +4724,22 @@ static int
remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
char *p;
enum Z_packet_type packet = watchpoint_to_Z_packet (type);
if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
return -1;
- sprintf (buf, "Z%x,", packet);
- p = strchr (buf, '\0');
+ sprintf (rs->buf, "Z%x,", packet);
+ p = strchr (rs->buf, '\0');
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
- putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- switch (packet_ok (buf, &remote_protocol_packets[PACKET_Z0 + packet]))
+ switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
@@ -4698,22 +4756,21 @@ static int
remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
char *p;
enum Z_packet_type packet = watchpoint_to_Z_packet (type);
if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
return -1;
- sprintf (buf, "z%x,", packet);
- p = strchr (buf, '\0');
+ sprintf (rs->buf, "z%x,", packet);
+ p = strchr (rs->buf, '\0');
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
- putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- switch (packet_ok (buf, &remote_protocol_packets[PACKET_Z0 + packet]))
+ switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
@@ -4783,8 +4840,7 @@ remote_insert_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
{
int len = 0;
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
- char *p = buf;
+ char *p = rs->buf;
/* The length field should be set to the size of a breakpoint
instruction. */
@@ -4802,10 +4858,10 @@ remote_insert_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
- putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- switch (packet_ok (buf, &remote_protocol_packets[PACKET_Z1]))
+ switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
@@ -4823,8 +4879,7 @@ remote_remove_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
{
int len;
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
- char *p = buf;
+ char *p = rs->buf;
/* The length field should be set to the size of a breakpoint
instruction. */
@@ -4842,10 +4897,10 @@ remote_remove_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
- putpkt(buf);
- getpkt (buf, rs->remote_packet_size, 0);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
- switch (packet_ok (buf, &remote_protocol_packets[PACKET_Z1]))
+ switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
@@ -4927,7 +4982,6 @@ compare_sections_command (char *args, int from_tty)
char *tmp;
char *sectdata;
const char *sectname;
- char *buf = alloca (rs->remote_packet_size);
bfd_size_type size;
bfd_vma lma;
int matched = 0;
@@ -4955,9 +5009,9 @@ compare_sections_command (char *args, int from_tty)
matched = 1; /* do this section */
lma = s->lma;
/* FIXME: assumes lma can fit into long. */
- xsnprintf (buf, rs->remote_packet_size, "qCRC:%lx,%lx",
+ xsnprintf (rs->buf, rs->remote_packet_size, "qCRC:%lx,%lx",
(long) lma, (long) size);
- putpkt (buf);
+ putpkt (rs->buf);
/* Be clever; compute the host_crc before waiting for target
reply. */
@@ -4966,14 +5020,14 @@ compare_sections_command (char *args, int from_tty)
bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
- getpkt (buf, rs->remote_packet_size, 0);
- if (buf[0] == 'E')
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (rs->buf[0] == 'E')
error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
sectname, paddr (lma), paddr (lma + size));
- if (buf[0] != 'C')
+ if (rs->buf[0] != 'C')
error (_("remote target does not support this operation"));
- for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
+ for (target_crc = 0, tmp = &rs->buf[1]; *tmp; tmp++)
target_crc = target_crc * 16 + fromhex (*tmp);
printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
@@ -5009,7 +5063,6 @@ remote_read_qpart (struct target_ops *ops, const char *object_name,
struct packet_config *packet)
{
struct remote_state *rs = get_remote_state ();
- char *buf2 = alloca (rs->remote_packet_size);
unsigned int total = 0;
LONGEST i, n;
@@ -5017,24 +5070,24 @@ remote_read_qpart (struct target_ops *ops, const char *object_name,
return -1;
n = min ((rs->remote_packet_size - 2) / 2, len);
- snprintf (buf2, rs->remote_packet_size, "qPart:%s:read:%s:%s,%s",
+ snprintf (rs->buf, rs->remote_packet_size, "qPart:%s:read:%s:%s,%s",
object_name, annex ? annex : "",
phex_nz (offset, sizeof offset),
phex_nz (n, sizeof n));
- i = putpkt (buf2);
+ i = putpkt (rs->buf);
if (i < 0)
return -1;
- buf2[0] = '\0';
- getpkt (buf2, rs->remote_packet_size, 0);
- if (packet_ok (buf2, packet) != PACKET_OK)
+ rs->buf[0] = '\0';
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (packet_ok (rs->buf, packet) != PACKET_OK)
return -1;
- if (buf2[0] == 'O' && buf2[1] == 'K' && buf2[2] == '\0')
+ if (rs->buf[0] == 'O' && rs->buf[1] == 'K' && rs->buf[2] == '\0')
return 0; /* Got EOF indicator. */
/* Got some data. */
- i = hex2bin (buf2, readbuf, len);
+ i = hex2bin (rs->buf, readbuf, len);
return i;
}
@@ -5045,7 +5098,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
{
struct remote_state *rs = get_remote_state ();
int i;
- char *buf2, *p2;
+ char *p2;
char query_type;
/* Handle memory using remote_xfer_memory. */
@@ -5118,9 +5171,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
gdb_assert (annex != NULL);
gdb_assert (readbuf != NULL);
- buf2 = alloca (rs->remote_packet_size);
- p2 = &buf2[0];
-
+ p2 = rs->buf;
*p2++ = 'q';
*p2++ = query_type;
@@ -5140,11 +5191,12 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
*p2 = '\0';
gdb_assert (annex[i] == '\0');
- i = putpkt (buf2);
+ i = putpkt (rs->buf);
if (i < 0)
return i;
- getpkt ((char *) readbuf, len, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ strcpy ((char *) readbuf, rs->buf);
return strlen ((char *) readbuf);
}
@@ -5154,7 +5206,7 @@ remote_rcmd (char *command,
struct ui_file *outbuf)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
+ char *buf = rs->buf;
char *p = buf;
if (!remote_desc)
@@ -5174,7 +5226,7 @@ remote_rcmd (char *command,
/* Encode the actual command. */
bin2hex ((gdb_byte *) command, p, 0);
- if (putpkt (buf) < 0)
+ if (putpkt (rs->buf) < 0)
error (_("Communication problem with target."));
/* get/display the response */
@@ -5182,7 +5234,7 @@ remote_rcmd (char *command,
{
/* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
buf[0] = '\0';
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
if (buf[0] == '\0')
error (_("Target does not support this command."));
if (buf[0] == 'O' && buf[1] != 'K')
@@ -5210,7 +5262,6 @@ static void
packet_command (char *args, int from_tty)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
if (!remote_desc)
error (_("command can only be used with remote target"));
@@ -5223,9 +5274,9 @@ packet_command (char *args, int from_tty)
puts_filtered ("\n");
putpkt (args);
- getpkt (buf, rs->remote_packet_size, 0);
+ getpkt (&rs->buf, &rs->buf_size, 0);
puts_filtered ("received: ");
- print_packet (buf);
+ print_packet (rs->buf);
puts_filtered ("\n");
}
@@ -5395,8 +5446,7 @@ remote_get_thread_local_address (ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
if (remote_protocol_packets[PACKET_qGetTLSAddr].support != PACKET_DISABLE)
{
struct remote_state *rs = get_remote_state ();
- char *buf = alloca (rs->remote_packet_size);
- char *p = buf;
+ char *p = rs->buf;
enum packet_result result;
strcpy (p, "qGetTLSAddr:");
@@ -5408,14 +5458,14 @@ remote_get_thread_local_address (ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
p += hexnumstr (p, lm);
*p++ = '\0';
- putpkt (buf);
- getpkt (buf, rs->remote_packet_size, 0);
- result = packet_ok (buf, &remote_protocol_packets[PACKET_qGetTLSAddr]);
+ putpkt (rs->buf);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ result = packet_ok (rs->buf, &remote_protocol_packets[PACKET_qGetTLSAddr]);
if (result == PACKET_OK)
{
ULONGEST result;
- unpack_varlen_hex (buf, &result);
+ unpack_varlen_hex (rs->buf, &result);
return result;
}
else if (result == PACKET_UNKNOWN)
diff --git a/gdb/remote.h b/gdb/remote.h
index ee34f63d529..c715e58b594 100644
--- a/gdb/remote.h
+++ b/gdb/remote.h
@@ -24,11 +24,12 @@
/* FIXME?: move this interface down to tgt vector) */
/* 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. Resize *BUF using xrealloc if necessary to hold
+ the result, and update *SIZEOF_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. */
-extern void getpkt (char *buf, long sizeof_buf, int forever);
+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
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index c40b120e466..64e8b5817b6 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -194,13 +194,15 @@ trace_error (char *buf)
/* Utility: wait for reply from stub, while accepting "O" packets. */
static char *
-remote_get_noisy_reply (char *buf,
- long sizeof_buf)
+remote_get_noisy_reply (char **buf_p,
+ long *sizeof_buf)
{
do /* Loop on reply from remote stub. */
{
+ char *buf;
QUIT; /* allow user to bail out with ^C */
- getpkt (buf, sizeof_buf, 0);
+ getpkt (buf_p, sizeof_buf, 0);
+ buf = *buf_p;
if (buf[0] == 0)
error (_("Target does not support this command."));
else if (buf[0] == 'E')
@@ -1700,7 +1702,8 @@ add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
collect->next_aexpr_elt++;
}
-static char target_buf[2048];
+static char *target_buf;
+static long target_buf_size;
/* Set "transparent" memory ranges
@@ -1742,7 +1745,7 @@ remote_set_transparent_ranges (void)
if (anysecs)
{
putpkt (target_buf);
- getpkt (target_buf, sizeof (target_buf), 0);
+ getpkt (&target_buf, &target_buf_size, 0);
}
}
@@ -1768,7 +1771,7 @@ trace_start_command (char *args, int from_tty)
if (target_is_remote ())
{
putpkt ("QTinit");
- remote_get_noisy_reply (target_buf, sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Target does not support this command."));
@@ -1785,7 +1788,7 @@ trace_start_command (char *args, int from_tty)
if (t->actions)
strcat (buf, "-");
putpkt (buf);
- remote_get_noisy_reply (target_buf, sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Target does not support tracepoints."));
@@ -1809,8 +1812,8 @@ trace_start_command (char *args, int from_tty)
((tdp_actions[ndx + 1] || stepping_actions)
? '-' : 0));
putpkt (buf);
- remote_get_noisy_reply (target_buf,
- sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf,
+ &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Error on target while setting tracepoints."));
}
@@ -1826,8 +1829,8 @@ trace_start_command (char *args, int from_tty)
stepping_actions[ndx],
(stepping_actions[ndx + 1] ? "-" : ""));
putpkt (buf);
- remote_get_noisy_reply (target_buf,
- sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf,
+ &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Error on target while setting tracepoints."));
}
@@ -1840,7 +1843,7 @@ trace_start_command (char *args, int from_tty)
remote_set_transparent_ranges ();
/* Now insert traps and begin collecting data. */
putpkt ("QTStart");
- remote_get_noisy_reply (target_buf, sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Bogus reply from target: %s"), target_buf);
set_traceframe_num (-1); /* All old traceframes invalidated. */
@@ -1862,7 +1865,7 @@ trace_stop_command (char *args, int from_tty)
if (target_is_remote ())
{
putpkt ("QTStop");
- remote_get_noisy_reply (target_buf, sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
if (strcmp (target_buf, "OK"))
error (_("Bogus reply from target: %s"), target_buf);
trace_running_p = 0;
@@ -1882,7 +1885,7 @@ trace_status_command (char *args, int from_tty)
if (target_is_remote ())
{
putpkt ("qTStatus");
- remote_get_noisy_reply (target_buf, sizeof (target_buf));
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
if (target_buf[0] != 'T' ||
(target_buf[1] != '0' && target_buf[1] != '1'))
@@ -1897,8 +1900,8 @@ trace_status_command (char *args, int from_tty)
/* Worker function for the various flavors of the tfind command. */
static void
-finish_tfind_command (char *msg,
- long sizeof_msg,
+finish_tfind_command (char **msg,
+ long *sizeof_msg,
int from_tty)
{
int target_frameno = -1, target_tracept = -1;
@@ -1909,7 +1912,7 @@ finish_tfind_command (char *msg,
old_frame_addr = get_frame_base (get_current_frame ());
old_func = find_pc_function (read_pc ());
- putpkt (msg);
+ putpkt (*msg);
reply = remote_get_noisy_reply (msg, sizeof_msg);
while (reply && *reply)
@@ -2054,7 +2057,7 @@ trace_find_command (char *args, int from_tty)
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);
+ finish_tfind_command (&target_buf, &target_buf_size, from_tty);
}
else
error (_("Trace can only be run on remote targets."));
@@ -2097,7 +2100,7 @@ trace_find_pc_command (char *args, int from_tty)
sprintf_vma (tmp, pc);
sprintf (target_buf, "QTFrame:pc:%s", tmp);
- finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
+ finish_tfind_command (&target_buf, &target_buf_size, from_tty);
}
else
error (_("Trace can only be run on remote targets."));
@@ -2122,7 +2125,7 @@ trace_find_tracepoint_command (char *args, int from_tty)
tdp = parse_and_eval_long (args);
sprintf (target_buf, "QTFrame:tdp:%x", tdp);
- finish_tfind_command (target_buf, sizeof (target_buf), from_tty);
+ finish_tfind_command (&target_buf, &target_buf_size, from_tty);
}
else
error (_("Trace can only be run on remote targets."));
@@ -2220,7 +2223,7 @@ trace_find_line_command (char *args, int from_tty)
else
sprintf (target_buf, "QTFrame:outside:%s:%s",
startpc_str, endpc_str);
- finish_tfind_command (target_buf, sizeof (target_buf),
+ finish_tfind_command (&target_buf, &target_buf_size,
from_tty);
do_cleanups (old_chain);
}
@@ -2261,7 +2264,7 @@ trace_find_range_command (char *args, int from_tty)
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);
+ finish_tfind_command (&target_buf, &target_buf_size, from_tty);
}
else
error (_("Trace can only be run on remote targets."));
@@ -2300,7 +2303,7 @@ trace_find_outside_command (char *args, int from_tty)
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);
+ finish_tfind_command (&target_buf, &target_buf_size, from_tty);
}
else
error (_("Trace can only be run on remote targets."));
@@ -2867,4 +2870,7 @@ Do \"help tracepoints\" for info on other tracepoint commands."));
add_com_alias ("tr", "trace", class_alias, 1);
add_com_alias ("tra", "trace", class_alias, 1);
add_com_alias ("trac", "trace", class_alias, 1);
+
+ target_buf_size = 2048;
+ target_buf = xmalloc (target_buf_size);
}