{
adjusted_size = to - org_to;
- sprintf (buf, "qRelocInsn:%x", adjusted_size);
+ xsnprintf (buf, *sizeof_buf, "qRelocInsn:%x", adjusted_size);
putpkt (buf);
}
else if (ex.reason < 0 && ex.error == MEMORY_ERROR)
remote_query_attached (int pid)
{
struct remote_state *rs = get_remote_state ();
+ size_t size = get_remote_packet_size ();
if (remote_protocol_packets[PACKET_qAttached].support == PACKET_DISABLE)
return 0;
if (remote_multi_process_p (rs))
- sprintf (rs->buf, "qAttached:%x", pid);
+ xsnprintf (rs->buf, size, "qAttached:%x", pid);
else
- sprintf (rs->buf, "qAttached");
+ xsnprintf (rs->buf, size, "qAttached");
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
struct remote_state *rs = get_remote_state ();
char *p = rs->buf;
- sprintf (p, "qTSTMat:");
+ xsnprintf (p, get_remote_packet_size (), "qTSTMat:");
p += strlen (p);
p += hexnumstr (p, addr);
putpkt (rs->buf);
{
struct remote_state *rs = get_remote_state ();
- sprintf (rs->buf, "QAllow:"
- "WriteReg:%x;WriteMem:%x;"
- "InsertBreak:%x;InsertTrace:%x;"
- "InsertFastTrace:%x;Stop:%x",
- may_write_registers, may_write_memory,
- may_insert_breakpoints, may_insert_tracepoints,
- may_insert_fast_tracepoints, may_stop);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QAllow:"
+ "WriteReg:%x;WriteMem:%x;"
+ "InsertBreak:%x;InsertTrace:%x;"
+ "InsertFastTrace:%x;Stop:%x",
+ may_write_registers, may_write_memory,
+ may_insert_breakpoints, may_insert_tracepoints,
+ may_insert_fast_tracepoints, may_stop);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
/* Tell the remote target to detach. */
if (remote_multi_process_p (rs))
- sprintf (rs->buf, "D;%x", pid);
+ xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
else
strcpy (rs->buf, "D");
gdb_flush (gdb_stdout);
}
- sprintf (rs->buf, "vAttach;%x", pid);
+ xsnprintf (rs->buf, get_remote_packet_size (), "vAttach;%x", pid);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
struct remote_state *rs = get_remote_state ();
int buf_len;
- sprintf (rs->buf, "g");
+ xsnprintf (rs->buf, get_remote_packet_size (), "g");
remote_send (&rs->buf, &rs->buf_size);
/* We can get out of synch in various cases. If the first character
return -1;
/* Tell the remote target to detach. */
- sprintf (rs->buf, "vKill;%x", pid);
+ xsnprintf (rs->buf, get_remote_packet_size (), "vKill;%x", pid);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
struct remote_state *rs = get_remote_state ();
char *reply;
- sprintf (rs->buf, "QDisableRandomization:%x", val);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QDisableRandomization:%x",
+ val);
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (*reply == '\0')
/* Given a location's target info BP_TGT and the packet buffer BUF, output
the list of conditions (in agent expression bytecode format), if any, the
target needs to evaluate. The output is placed into the packet buffer
- BUF. */
+ started from BUF and ended at BUF_END. */
static int
remote_add_target_side_condition (struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt, char *buf)
+ struct bp_target_info *bp_tgt, char *buf,
+ char *buf_end)
{
struct agent_expr *aexpr = NULL;
int i, ix;
return 0;
buf += strlen (buf);
- sprintf (buf, "%s", ";");
+ xsnprintf (buf, buf_end - buf, "%s", ";");
buf++;
/* Send conditions to the target and free the vector. */
VEC_iterate (agent_expr_p, bp_tgt->conditions, ix, aexpr);
ix++)
{
- sprintf (buf, "X%x,", aexpr->len);
+ xsnprintf (buf, buf_end - buf, "X%x,", aexpr->len);
buf += strlen (buf);
for (i = 0; i < aexpr->len; ++i)
buf = pack_hex_byte (buf, aexpr->buf[i]);
{
CORE_ADDR addr = bp_tgt->placed_address;
struct remote_state *rs;
- char *p;
+ char *p, *endbuf;
int bpsize;
struct condition_list *cond = NULL;
rs = get_remote_state ();
p = rs->buf;
+ endbuf = rs->buf + get_remote_packet_size ();
*(p++) = 'Z';
*(p++) = '0';
*(p++) = ',';
addr = (ULONGEST) remote_address_masked (addr);
p += hexnumstr (p, addr);
- sprintf (p, ",%d", bpsize);
+ xsnprintf (p, endbuf - p, ",%d", bpsize);
if (remote_supports_cond_breakpoints ())
- remote_add_target_side_condition (gdbarch, bp_tgt, p);
+ remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
{
char *p = rs->buf;
+ char *endbuf = rs->buf + get_remote_packet_size ();
*(p++) = 'z';
*(p++) = '0';
addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
p += hexnumstr (p, addr);
- sprintf (p, ",%d", bp_tgt->placed_size);
+ xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
struct expression *cond)
{
struct remote_state *rs = get_remote_state ();
+ char *endbuf = rs->buf + get_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 (rs->buf, "Z%x,", packet);
+ xsnprintf (rs->buf, endbuf - rs->buf, "Z%x,", packet);
p = strchr (rs->buf, '\0');
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
- sprintf (p, ",%x", len);
+ xsnprintf (p, endbuf - p, ",%x", len);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
struct expression *cond)
{
struct remote_state *rs = get_remote_state ();
+ char *endbuf = rs->buf + get_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 (rs->buf, "z%x,", packet);
+ xsnprintf (rs->buf, endbuf - rs->buf, "z%x,", packet);
p = strchr (rs->buf, '\0');
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
- sprintf (p, ",%x", len);
+ xsnprintf (p, endbuf - p, ",%x", len);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
{
CORE_ADDR addr;
struct remote_state *rs;
- char *p;
+ char *p, *endbuf;
/* The length field should be set to the size of a breakpoint
instruction, even though we aren't inserting one ourselves. */
rs = get_remote_state ();
p = rs->buf;
+ endbuf = rs->buf + get_remote_packet_size ();
*(p++) = 'Z';
*(p++) = '1';
addr = remote_address_masked (bp_tgt->placed_address);
p += hexnumstr (p, (ULONGEST) addr);
- sprintf (p, ",%x", bp_tgt->placed_size);
+ xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
if (remote_supports_cond_breakpoints ())
- remote_add_target_side_condition (gdbarch, bp_tgt, p);
+ remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
CORE_ADDR addr;
struct remote_state *rs = get_remote_state ();
char *p = rs->buf;
+ char *endbuf = rs->buf + get_remote_packet_size ();
if (remote_protocol_packets[PACKET_Z1].support == PACKET_DISABLE)
return -1;
addr = remote_address_masked (bp_tgt->placed_address);
p += hexnumstr (p, (ULONGEST) addr);
- sprintf (p, ",%x", bp_tgt->placed_size);
+ xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);
static void
remote_download_tracepoint (struct bp_location *loc)
{
+#define BUF_SIZE 2048
CORE_ADDR tpaddr;
char addrbuf[40];
- char buf[2048];
+ char buf[BUF_SIZE];
char **tdp_actions;
char **stepping_actions;
int ndx;
tpaddr = loc->address;
sprintf_vma (addrbuf, tpaddr);
- sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", b->number,
- addrbuf, /* address */
- (b->enable_state == bp_enabled ? 'E' : 'D'),
- t->step_count, t->pass_count);
+ xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number,
+ addrbuf, /* address */
+ (b->enable_state == bp_enabled ? 'E' : 'D'),
+ t->step_count, t->pass_count);
/* Fast tracepoints are mostly handled by the target, but we can
tell the target how big of an instruction block should be moved
around. */
if (gdbarch_fast_tracepoint_valid_at (target_gdbarch,
tpaddr, &isize, NULL))
- sprintf (buf + strlen (buf), ":F%x", isize);
+ xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
+ isize);
else
/* If it passed validation at definition but fails now,
something is very wrong. */
{
aexpr = gen_eval_for_expr (tpaddr, loc->cond);
aexpr_chain = make_cleanup_free_agent_expr (aexpr);
- sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
+ xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
+ aexpr->len);
pkt = buf + strlen (buf);
for (ndx = 0; ndx < aexpr->len; ++ndx)
pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
for (ndx = 0; tdp_actions[ndx]; ndx++)
{
QUIT; /* Allow user to bail out with ^C. */
- sprintf (buf, "QTDP:-%x:%s:%s%c",
- b->number, addrbuf, /* address */
- tdp_actions[ndx],
- ((tdp_actions[ndx + 1] || stepping_actions)
- ? '-' : 0));
+ xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
+ b->number, addrbuf, /* address */
+ tdp_actions[ndx],
+ ((tdp_actions[ndx + 1] || stepping_actions)
+ ? '-' : 0));
putpkt (buf);
remote_get_noisy_reply (&target_buf,
&target_buf_size);
for (ndx = 0; stepping_actions[ndx]; ndx++)
{
QUIT; /* Allow user to bail out with ^C. */
- sprintf (buf, "QTDP:-%x:%s:%s%s%s",
- b->number, addrbuf, /* address */
- ((ndx == 0) ? "S" : ""),
- stepping_actions[ndx],
- (stepping_actions[ndx + 1] ? "-" : ""));
+ xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
+ b->number, addrbuf, /* address */
+ ((ndx == 0) ? "S" : ""),
+ stepping_actions[ndx],
+ (stepping_actions[ndx + 1] ? "-" : ""));
putpkt (buf);
remote_get_noisy_reply (&target_buf,
&target_buf_size);
struct remote_state *rs = get_remote_state ();
char *p;
- sprintf (rs->buf, "QTDV:%x:%s:%x:",
- tsv->number, phex ((ULONGEST) tsv->initial_value, 8), tsv->builtin);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
+ tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
+ tsv->builtin);
p = rs->buf + strlen (rs->buf);
if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
error (_("Trace state variable name too long for tsv definition packet"));
char addr_buf[40];
sprintf_vma (addr_buf, location->address);
- sprintf (rs->buf, "QTEnable:%x:%s", location->owner->number, addr_buf);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QTEnable:%x:%s",
+ location->owner->number, addr_buf);
putpkt (rs->buf);
remote_get_noisy_reply (&rs->buf, &rs->buf_size);
if (*rs->buf == '\0')
char addr_buf[40];
sprintf_vma (addr_buf, location->address);
- sprintf (rs->buf, "QTDisable:%x:%s", location->owner->number, addr_buf);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QTDisable:%x:%s",
+ location->owner->number, addr_buf);
putpkt (rs->buf);
remote_get_noisy_reply (&rs->buf, &rs->buf_size);
if (*rs->buf == '\0')
Too many sections for read-only sections definition packet."));
break;
}
- sprintf (target_buf + offset, ":%s,%s", tmp1, tmp2);
+ xsnprintf (target_buf + offset, target_buf_size - offset, ":%s,%s",
+ tmp1, tmp2);
offset += sec_length;
}
if (anysecs)
char *reply;
struct bp_location *loc;
struct tracepoint *tp = (struct tracepoint *) bp;
+ size_t size = get_remote_packet_size ();
if (tp)
{
any status. */
if (tp->number_on_target == 0)
continue;
- sprintf (rs->buf, "qTP:%x:%s", tp->number_on_target,
- phex_nz (loc->address, 0));
+ xsnprintf (rs->buf, size, "qTP:%x:%s", tp->number_on_target,
+ phex_nz (loc->address, 0));
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (reply && *reply)
{
utp->hit_count = 0;
utp->traceframe_usage = 0;
- sprintf (rs->buf, "qTP:%x:%s", utp->number, phex_nz (utp->addr, 0));
+ xsnprintf (rs->buf, size, "qTP:%x:%s", utp->number,
+ phex_nz (utp->addr, 0));
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (reply && *reply)
int *tpp)
{
struct remote_state *rs = get_remote_state ();
+ char *endbuf = rs->buf + get_remote_packet_size ();
char *p, *reply;
int target_frameno = -1, target_tracept = -1;
switch (type)
{
case tfind_number:
- sprintf (p, "%x", num);
+ xsnprintf (p, endbuf - p, "%x", num);
break;
case tfind_pc:
- sprintf (p, "pc:%s", phex_nz (addr1, 0));
+ xsnprintf (p, endbuf - p, "pc:%s", phex_nz (addr1, 0));
break;
case tfind_tp:
- sprintf (p, "tdp:%x", num);
+ xsnprintf (p, endbuf - p, "tdp:%x", num);
break;
case tfind_range:
- sprintf (p, "range:%s:%s", phex_nz (addr1, 0), phex_nz (addr2, 0));
+ xsnprintf (p, endbuf - p, "range:%s:%s", phex_nz (addr1, 0),
+ phex_nz (addr2, 0));
break;
case tfind_outside:
- sprintf (p, "outside:%s:%s", phex_nz (addr1, 0), phex_nz (addr2, 0));
+ xsnprintf (p, endbuf - p, "outside:%s:%s", phex_nz (addr1, 0),
+ phex_nz (addr2, 0));
break;
default:
error (_("Unknown trace find type %d"), type);
set_remote_traceframe ();
- sprintf (rs->buf, "qTV:%x", tsvnum);
+ xsnprintf (rs->buf, get_remote_packet_size (), "qTV:%x", tsvnum);
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (reply && *reply)
{
char *reply;
- sprintf (rs->buf, "QTDisconnected:%x", val);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QTDisconnected:%x", val);
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (*reply == '\0')
struct remote_state *rs = get_remote_state ();
char *reply;
- sprintf (rs->buf, "QTBuffer:circular:%x", val);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QTBuffer:circular:%x", val);
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (*reply == '\0')
/* Make sure the remote is pointing at the right process. */
set_general_process ();
- sprintf (rs->buf, "qTMinFTPILen");
+ xsnprintf (rs->buf, get_remote_packet_size (), "qTMinFTPILen");
putpkt (rs->buf);
reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
if (*reply == '\0')
struct remote_state *rs = get_remote_state ();
/* If the stub supports QAgent. */
- sprintf (rs->buf, "QAgent:%d", use);
+ xsnprintf (rs->buf, get_remote_packet_size (), "QAgent:%d", use);
putpkt (rs->buf);
getpkt (&rs->buf, &rs->buf_size, 0);