show_memory_packet_size (&memory_write_packet_config);
}
+/* Show the number of hardware watchpoints that can be used. */
+
+static void
+show_hardware_watchpoint_limit (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ fprintf_filtered (file, _("The maximum number of target hardware "
+ "watchpoints is %s.\n"), value);
+}
+
+/* Show the length limit (in bytes) for hardware watchpoints. */
+
+static void
+show_hardware_watchpoint_length_limit (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ fprintf_filtered (file, _("The maximum length (in bytes) of a target "
+ "hardware watchpoint is %s.\n"), value);
+}
+
+/* Show the number of hardware breakpoints that can be used. */
+
+static void
+show_hardware_breakpoint_limit (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ fprintf_filtered (file, _("The maximum number of target hardware "
+ "breakpoints is %s.\n"), value);
+}
+
long
remote_target::get_memory_write_packet_size ()
{
return;
}
- if (ptid_equal (magic_null_ptid, inferior_ptid))
+ if (magic_null_ptid == inferior_ptid)
{
/* inferior_ptid is not set yet. This can happen with the
vRun -> remote_wait,"TAAthread:" path if the stub
char *buf = rs->buf;
char *endbuf = rs->buf + get_remote_packet_size ();
- if (ptid_equal (state, ptid))
+ if (state == ptid)
return;
*buf++ = 'H';
*buf++ = gen ? 'g' : 'c';
- if (ptid_equal (ptid, magic_null_ptid))
+ if (ptid == magic_null_ptid)
xsnprintf (buf, endbuf - buf, "0");
- else if (ptid_equal (ptid, any_thread_ptid))
+ else if (ptid == any_thread_ptid)
xsnprintf (buf, endbuf - buf, "0");
- else if (ptid_equal (ptid, minus_one_ptid))
+ else if (ptid == minus_one_ptid)
xsnprintf (buf, endbuf - buf, "-1");
else
write_ptid (buf, endbuf, ptid);
static int
remote_thread_always_alive (ptid_t ptid)
{
- if (ptid_equal (ptid, magic_null_ptid))
+ if (ptid == magic_null_ptid)
/* The main thread is always alive. */
return 1;
what's in inferior_ptid, unless it's null at this point. If so,
then since there's no way to know the pid of the reported
threads, use the magic number. */
- if (ptid_equal (inferior_ptid, null_ptid))
+ if (inferior_ptid == null_ptid)
pid = magic_null_ptid.pid ();
else
pid = inferior_ptid.pid ();
internal_error (__FILE__, __LINE__,
_("remote_threads_extra_info"));
- if (ptid_equal (tp->ptid, magic_null_ptid)
+ if (tp->ptid == magic_null_ptid
|| (tp->ptid.pid () != 0 && tp->ptid.lwp () == 0))
/* This is the main thread which was added by GDB. The remote
server doesn't know about it. */
this point. */
if (wait_status != NULL)
ptid = stop_reply_extract_thread (wait_status);
- if (ptid_equal (ptid, null_ptid))
+ if (ptid == null_ptid)
ptid = remote_current_thread (inferior_ptid);
return ptid;
multi-threaded program, this will ideally be the thread
that last reported an event before GDB disconnected. */
inferior_ptid = get_current_thread (wait_status);
- if (ptid_equal (inferior_ptid, null_ptid))
+ if (inferior_ptid == null_ptid)
{
/* Odd... The target was able to list threads, but not
tell us which thread was current (no "thread"
{
struct remote_state *rs = get_remote_state ();
+ /* This should not be necessary, but the handling for D;PID in
+ GDBserver versions prior to 8.2 incorrectly assumes that the
+ selected process points to the same process we're detaching,
+ leading to misbehavior (and possibly GDBserver crashing) when it
+ does not. Since it's easy and cheap, work around it by forcing
+ GDBserver to select GDB's current process. */
+ set_general_process ();
+
if (remote_multi_process_p (rs))
xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
else
{
struct thread_info *tp;
- if (ptid_equal (ptid, minus_one_ptid))
+ if (ptid == minus_one_ptid)
{
/* If we don't know about the target thread's tid, then
we're resuming magic_null_ptid (see caller). */
p += xsnprintf (p, endp - p, ":");
p = write_ptid (p, endp, nptid);
}
- else if (!ptid_equal (ptid, minus_one_ptid))
+ else if (ptid != minus_one_ptid)
{
p += xsnprintf (p, endp - p, ":");
p = write_ptid (p, endp, ptid);
struct thread_info *thread;
ALL_NON_EXITED_THREADS (thread)
- if (ptid_match (thread->ptid, ptid)
- && !ptid_equal (inferior_ptid, thread->ptid)
+ if (thread->ptid.matches (ptid)
+ && inferior_ptid != thread->ptid
&& thread->suspend.stop_signal != GDB_SIGNAL_0)
{
p = append_resumption (p, endp, thread->ptid,
/* The c/s/C/S resume packets use Hc, so set the continue
thread. */
- if (ptid_equal (ptid, minus_one_ptid))
+ if (ptid == minus_one_ptid)
set_continue_thread (any_thread_ptid);
else
set_continue_thread (ptid);
p += xsnprintf (p, endp - p, "vCont");
- if (ptid_equal (ptid, magic_null_ptid))
+ if (ptid == magic_null_ptid)
{
/* MAGIC_NULL_PTID means that we don't have any active threads,
so we don't have any TID numbers the inferior will
a TID. */
append_resumption (p, endp, minus_one_ptid, step, siggnal);
}
- else if (ptid_equal (ptid, minus_one_ptid) || ptid.is_pid ())
+ else if (ptid == minus_one_ptid || ptid.is_pid ())
{
/* Resume all threads (of all processes, or of a single
process), with preference for INFERIOR_PTID. This assumes
{
remote_thread_info *remote_thr;
- if (ptid_equal (minus_one_ptid, ptid) || ptid.is_pid ())
+ if (minus_one_ptid == ptid || ptid.is_pid ())
remote_thr = get_remote_thread_info (inferior_ptid);
else
remote_thr = get_remote_thread_info (ptid);
if (!rs->supports_vCont.t)
error (_("Remote server does not support stopping threads"));
- if (ptid_equal (ptid, minus_one_ptid)
+ if (ptid == minus_one_ptid
|| (!remote_multi_process_p (rs) && ptid.is_pid ()))
p += xsnprintf (p, endp - p, "vCont;t");
else
break;
}
- if (target_is_non_stop_p () && ptid_equal (event->ptid, null_ptid))
+ if (target_is_non_stop_p () && event->ptid == null_ptid)
error (_("No process or thread specified in stop reply: %s"), buf);
}
/* If no thread/process was reported by the stub, assume the current
inferior. */
- if (ptid_equal (ptid, null_ptid))
+ if (ptid == null_ptid)
ptid = inferior_ptid;
if (status->kind != TARGET_WAITKIND_EXITED
else if (status->kind != TARGET_WAITKIND_EXITED
&& status->kind != TARGET_WAITKIND_SIGNALLED)
{
- if (!ptid_equal (event_ptid, null_ptid))
+ if (event_ptid != null_ptid)
record_currthread (rs, event_ptid);
else
event_ptid = inferior_ptid;
if (remote_exec_file[0])
error (_("Remote target does not support \"set remote exec-file\""));
if (!args.empty ())
- error (_("Remote target does not support \"set args\" or run <ARGS>"));
+ error (_("Remote target does not support \"set args\" or run ARGS"));
/* Fall back to "R". */
extended_remote_restart ();
static char buf[64];
struct remote_state *rs = get_remote_state ();
- if (ptid_equal (ptid, null_ptid))
+ if (ptid == null_ptid)
return normal_pid_to_str (ptid);
else if (ptid.is_pid ())
{
}
else
{
- if (ptid_equal (magic_null_ptid, ptid))
+ if (magic_null_ptid == ptid)
xsnprintf (buf, sizeof buf, "Thread <main>");
else if (remote_multi_process_p (rs))
if (ptid.lwp () == 0)
/* Do not try this during initial connection, when we do not know
whether there is a running but stopped thread. */
- if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
+ if (!target_has_execution || inferior_ptid == null_ptid)
return beneath ()->read_description ();
if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
void
remote_target::download_tracepoint (struct bp_location *loc)
{
-#define BUF_SIZE 2048
-
CORE_ADDR tpaddr;
char addrbuf[40];
- char buf[BUF_SIZE];
std::vector<std::string> tdp_actions;
std::vector<std::string> stepping_actions;
char *pkt;
struct breakpoint *b = loc->owner;
struct tracepoint *t = (struct tracepoint *) b;
struct remote_state *rs = get_remote_state ();
+ int ret;
+ const char *err_msg = _("Tracepoint packet too large for target.");
+ size_t size_left;
+
+ /* We use a buffer other than rs->buf because we'll build strings
+ across multiple statements, and other statements in between could
+ modify rs->buf. */
+ gdb::char_vector buf (get_remote_packet_size ());
encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
tpaddr = loc->address;
sprintf_vma (addrbuf, tpaddr);
- 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);
+ ret = snprintf (buf.data (), 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);
+
+ if (ret < 0 || ret >= buf.size ())
+ error ("%s", err_msg);
+
/* 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 (loc->gdbarch, tpaddr,
NULL))
- xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
- gdb_insn_length (loc->gdbarch, tpaddr));
+ {
+ size_left = buf.size () - strlen (buf.data ());
+ ret = snprintf (buf.data () + strlen (buf.data ()),
+ size_left, ":F%x",
+ gdb_insn_length (loc->gdbarch, tpaddr));
+
+ if (ret < 0 || ret >= size_left)
+ error ("%s", err_msg);
+ }
else
/* If it passed validation at definition but fails now,
something is very wrong. */
struct static_tracepoint_marker marker;
if (target_static_tracepoint_marker_at (tpaddr, &marker))
- strcat (buf, ":S");
+ {
+ size_left = buf.size () - strlen (buf.data ());
+ ret = snprintf (buf.data () + strlen (buf.data ()),
+ size_left, ":S");
+
+ if (ret < 0 || ret >= size_left)
+ error ("%s", err_msg);
+ }
else
error (_("Static tracepoint not valid during download"));
}
capabilities at definition time. */
if (remote_supports_cond_tracepoints ())
{
- agent_expr_up aexpr = gen_eval_for_expr (tpaddr, loc->cond.get ());
- xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
- aexpr->len);
- pkt = buf + strlen (buf);
+ agent_expr_up aexpr = gen_eval_for_expr (tpaddr,
+ loc->cond.get ());
+
+ size_left = buf.size () - strlen (buf.data ());
+
+ ret = snprintf (buf.data () + strlen (buf.data ()),
+ size_left, ":X%x,", aexpr->len);
+
+ if (ret < 0 || ret >= size_left)
+ error ("%s", err_msg);
+
+ size_left = buf.size () - strlen (buf.data ());
+
+ /* Two bytes to encode each aexpr byte, plus the terminating
+ null byte. */
+ if (aexpr->len * 2 + 1 > size_left)
+ error ("%s", err_msg);
+
+ pkt = buf.data () + strlen (buf.data ());
+
for (int ndx = 0; ndx < aexpr->len; ++ndx)
pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
*pkt = '\0';
}
if (b->commands || *default_collect)
- strcat (buf, "-");
- putpkt (buf);
+ {
+ size_left = buf.size () - strlen (buf.data ());
+
+ ret = snprintf (buf.data () + strlen (buf.data ()),
+ size_left, "-");
+
+ if (ret < 0 || ret >= size_left)
+ error ("%s", err_msg);
+ }
+
+ putpkt (buf.data ());
remote_get_noisy_reply ();
if (strcmp (rs->buf, "OK"))
error (_("Target does not support tracepoints."));
{
QUIT; /* Allow user to bail out with ^C. */
- bool has_more = (action_it != tdp_actions.end ()
+ bool has_more = ((action_it + 1) != tdp_actions.end ()
|| !stepping_actions.empty ());
- xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
- b->number, addrbuf, /* address */
- action_it->c_str (),
- has_more ? '-' : 0);
- putpkt (buf);
+ ret = snprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%c",
+ b->number, addrbuf, /* address */
+ action_it->c_str (),
+ has_more ? '-' : 0);
+
+ if (ret < 0 || ret >= buf.size ())
+ error ("%s", err_msg);
+
+ putpkt (buf.data ());
remote_get_noisy_reply ();
if (strcmp (rs->buf, "OK"))
error (_("Error on target while setting tracepoints."));
}
- for (auto action_it = stepping_actions.begin ();
- action_it != stepping_actions.end (); action_it++)
- {
- QUIT; /* Allow user to bail out with ^C. */
-
- bool is_first = action_it == stepping_actions.begin ();
- bool has_more = action_it != stepping_actions.end ();
-
- xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
- b->number, addrbuf, /* address */
- is_first ? "S" : "",
- action_it->c_str (),
- has_more ? "-" : "");
- putpkt (buf);
- remote_get_noisy_reply ();
- if (strcmp (rs->buf, "OK"))
- error (_("Error on target while setting tracepoints."));
- }
+ for (auto action_it = stepping_actions.begin ();
+ action_it != stepping_actions.end (); action_it++)
+ {
+ QUIT; /* Allow user to bail out with ^C. */
+
+ bool is_first = action_it == stepping_actions.begin ();
+ bool has_more = (action_it + 1) != stepping_actions.end ();
+
+ ret = snprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%s%s",
+ b->number, addrbuf, /* address */
+ is_first ? "S" : "",
+ action_it->c_str (),
+ has_more ? "-" : "");
+
+ if (ret < 0 || ret >= buf.size ())
+ error ("%s", err_msg);
+
+ putpkt (buf.data ());
+ remote_get_noisy_reply ();
+ if (strcmp (rs->buf, "OK"))
+ error (_("Error on target while setting tracepoints."));
+ }
if (packet_support (PACKET_TracepointSource) == PACKET_ENABLE)
{
if (b->location != NULL)
{
- strcpy (buf, "QTDPsrc:");
+ ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
+
+ if (ret < 0 || ret >= buf.size ())
+ error ("%s", err_msg);
+
encode_source_string (b->number, loc->address, "at",
event_location_to_string (b->location.get ()),
- buf + strlen (buf), 2048 - strlen (buf));
- putpkt (buf);
+ buf.data () + strlen (buf.data ()),
+ buf.size () - strlen (buf.data ()));
+ putpkt (buf.data ());
remote_get_noisy_reply ();
if (strcmp (rs->buf, "OK"))
warning (_("Target does not support source download."));
}
if (b->cond_string)
{
- strcpy (buf, "QTDPsrc:");
+ ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
+
+ if (ret < 0 || ret >= buf.size ())
+ error ("%s", err_msg);
+
encode_source_string (b->number, loc->address,
- "cond", b->cond_string, buf + strlen (buf),
- 2048 - strlen (buf));
- putpkt (buf);
+ "cond", b->cond_string,
+ buf.data () + strlen (buf.data ()),
+ buf.size () - strlen (buf.data ()));
+ putpkt (buf.data ());
remote_get_noisy_reply ();
if (strcmp (rs->buf, "OK"))
warning (_("Target does not support source download."));
struct remote_state *rs = get_remote_state ();
struct thread_info *tp;
int btrace_target_pushed = 0;
+#if !defined (HAVE_LIBIPT)
int warned = 0;
+#endif
scoped_restore_current_thread restore_thread;
_("Show the maximum number of bytes per memory-read packet."),
&remote_show_cmdlist);
- add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class,
+ add_setshow_zuinteger_unlimited_cmd ("hardware-watchpoint-limit", no_class,
&remote_hw_watchpoint_limit, _("\
Set the maximum number of target hardware watchpoints."), _("\
Show the maximum number of target hardware watchpoints."), _("\
-Specify a negative limit for unlimited."),
- NULL, NULL, /* FIXME: i18n: The maximum
- number of target hardware
- watchpoints is %s. */
- &remote_set_cmdlist, &remote_show_cmdlist);
- add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class,
+Specify \"unlimited\" for unlimited hardware watchpoints."),
+ NULL, show_hardware_watchpoint_limit,
+ &remote_set_cmdlist,
+ &remote_show_cmdlist);
+ add_setshow_zuinteger_unlimited_cmd ("hardware-watchpoint-length-limit",
+ no_class,
&remote_hw_watchpoint_length_limit, _("\
Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
-Specify a negative limit for unlimited."),
- NULL, NULL, /* FIXME: i18n: The maximum
- length (in bytes) of a target
- hardware watchpoint is %s. */
+Specify \"unlimited\" to allow watchpoints of unlimited size."),
+ NULL, show_hardware_watchpoint_length_limit,
&remote_set_cmdlist, &remote_show_cmdlist);
- add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
+ add_setshow_zuinteger_unlimited_cmd ("hardware-breakpoint-limit", no_class,
&remote_hw_breakpoint_limit, _("\
Set the maximum number of target hardware breakpoints."), _("\
Show the maximum number of target hardware breakpoints."), _("\
-Specify a negative limit for unlimited."),
- NULL, NULL, /* FIXME: i18n: The maximum
- number of target hardware
- breakpoints is %s. */
+Specify \"unlimited\" for unlimited hardware breakpoints."),
+ NULL, show_hardware_breakpoint_limit,
&remote_set_cmdlist, &remote_show_cmdlist);
add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure,