static void remote_async_inferior_event_handler (gdb_client_data);
-static int remote_read_description_p (struct target_ops *target);
+static bool remote_read_description_p (struct target_ops *target);
static void remote_console_output (char *msg);
|| remote_get_threads_with_qthreadinfo (&context)
|| remote_get_threads_with_ql (&context))
{
- struct thread_info *tp, *tmp;
-
got_list = 1;
if (context.items.empty ()
/* CONTEXT now holds the current thread list on the remote
target end. Delete GDB-side threads no longer found on the
target. */
- ALL_THREADS_SAFE (tp, tmp)
+ for (thread_info *tp : all_threads_safe ())
{
if (!context.contains_thread (tp->ptid))
{
remote_target::process_initial_stop_replies (int from_tty)
{
int pending_stop_replies = stop_reply_queue_length ();
- struct inferior *inf;
- struct thread_info *thread;
struct thread_info *selected = NULL;
struct thread_info *lowest_stopped = NULL;
struct thread_info *first = NULL;
ptid_t event_ptid;
struct target_waitstatus ws;
int ignore_event = 0;
- struct thread_info *thread;
memset (&ws, 0, sizeof (ws));
event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
if (ignore_event)
continue;
- thread = find_thread_ptid (event_ptid);
+ struct thread_info *evthread = find_thread_ptid (event_ptid);
if (ws.kind == TARGET_WAITKIND_STOPPED)
{
instead of signal 0. Suppress it. */
if (sig == GDB_SIGNAL_TRAP)
sig = GDB_SIGNAL_0;
- thread->suspend.stop_signal = sig;
+ evthread->suspend.stop_signal = sig;
ws.value.sig = sig;
}
- thread->suspend.waitstatus = ws;
+ evthread->suspend.waitstatus = ws;
if (ws.kind != TARGET_WAITKIND_STOPPED
|| ws.value.sig != GDB_SIGNAL_0)
- thread->suspend.waitstatus_pending_p = 1;
+ evthread->suspend.waitstatus_pending_p = 1;
set_executing (event_ptid, 0);
set_running (event_ptid, 0);
- get_remote_thread_info (thread)->vcont_resumed = 0;
+ get_remote_thread_info (evthread)->vcont_resumed = 0;
}
/* "Notice" the new inferiors before anything related to
registers/memory. */
- ALL_INFERIORS (inf)
+ for (inferior *inf : all_non_exited_inferiors ())
{
- if (inf->pid == 0)
- continue;
-
inf->needs_setup = 1;
if (non_stop)
{
- thread = any_live_thread_of_inferior (inf);
+ thread_info *thread = any_live_thread_of_inferior (inf);
notice_new_inferior (thread, thread->state == THREAD_RUNNING,
from_tty);
}
/* If all threads of an inferior were already stopped, we
haven't setup the inferior yet. */
- ALL_INFERIORS (inf)
+ for (inferior *inf : all_non_exited_inferiors ())
{
- if (inf->pid == 0)
- continue;
-
if (inf->needs_setup)
{
- thread = any_live_thread_of_inferior (inf);
+ thread_info *thread = any_live_thread_of_inferior (inf);
switch_to_thread_no_regs (thread);
setup_inferior (0);
}
/* Now go over all threads that are stopped, and print their current
frame. If all-stop, then if there's a signalled thread, pick
that as current. */
- ALL_NON_EXITED_THREADS (thread)
+ for (thread_info *thread : all_non_exited_threads ())
{
if (first == NULL)
first = thread;
others with their status pending. */
if (!non_stop)
{
- thread = selected;
+ thread_info *thread = selected;
if (thread == NULL)
thread = lowest_stopped;
if (thread == NULL)
}
/* For "info program". */
- thread = inferior_thread ();
+ thread_info *thread = inferior_thread ();
if (thread->state == THREAD_STOPPED)
set_last_target_status (inferior_ptid, thread->suspend.waitstatus);
}
"warning: couldn't determine remote "
"current thread; picking first in list.\n");
- inferior_ptid = thread_list->ptid;
+ inferior_ptid = inferior_list->thread_list->ptid;
}
}
/* First delete any symbols previously loaded from shared libraries. */
no_shared_libraries (NULL, 0);
- /* Start afresh. */
- init_thread_list ();
-
/* Start the remote connection. If error() or QUIT, discard this
target (we'd otherwise be in an inconsistent state) and then
propogate the error on up the exception chain. This ensures that
{
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
remote_target::append_pending_thread_resumptions (char *p, char *endp,
ptid_t ptid)
{
- struct thread_info *thread;
-
- ALL_NON_EXITED_THREADS (thread)
- if (thread->ptid.matches (ptid)
- && inferior_ptid != thread->ptid
+ for (thread_info *thread : all_non_exited_threads (ptid))
+ if (inferior_ptid != thread->ptid
&& thread->suspend.stop_signal != GDB_SIGNAL_0)
{
p = append_resumption (p, endp, thread->ptid,
gdb_signal siggnal)
{
struct remote_state *rs = get_remote_state ();
- struct thread_info *thread;
char *buf;
rs->last_sent_signal = siggnal;
else
set_continue_thread (ptid);
- ALL_NON_EXITED_THREADS (thread)
+ for (thread_info *thread : all_non_exited_threads ())
resume_clear_thread_private_info (thread);
buf = rs->buf;
void
remote_target::commit_resume ()
{
- struct inferior *inf;
- struct thread_info *tp;
int any_process_wildcard;
int may_global_wildcard_vcont;
may_global_wildcard_vcont = 1;
/* And assume every process is individually wildcard-able too. */
- ALL_NON_EXITED_INFERIORS (inf)
+ for (inferior *inf : all_non_exited_inferiors ())
{
remote_inferior *priv = get_remote_inferior (inf);
disable process and global wildcard resumes appropriately. */
check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont);
- ALL_NON_EXITED_THREADS (tp)
+ for (thread_info *tp : all_non_exited_threads ())
{
/* If a thread of a process is not meant to be resumed, then we
can't wildcard that process. */
struct vcont_builder vcont_builder (this);
/* Threads first. */
- ALL_NON_EXITED_THREADS (tp)
+ for (thread_info *tp : all_non_exited_threads ())
{
remote_thread_info *remote_thr = get_remote_thread_info (tp);
supposed to be resumed. */
any_process_wildcard = 0;
- ALL_NON_EXITED_INFERIORS (inf)
+ for (inferior *inf : all_non_exited_inferiors ())
{
if (get_remote_inferior (inf)->may_wildcard_vcont)
{
}
else
{
- ALL_NON_EXITED_INFERIORS (inf)
+ for (inferior *inf : all_non_exited_inferiors ())
{
if (get_remote_inferior (inf)->may_wildcard_vcont)
{
void
remote_target::remove_new_fork_children (threads_listing_context *context)
{
- struct thread_info * thread;
int pid = -1;
struct notif_client *notif = ¬if_client_stop;
/* For any threads stopped at a fork event, remove the corresponding
fork child threads from the CONTEXT list. */
- ALL_NON_EXITED_THREADS (thread)
+ for (thread_info *thread : all_non_exited_threads ())
{
struct target_waitstatus *ws = thread_pending_fork_status (thread);
break;
case 'w': /* Thread exited. */
{
- const char *p;
ULONGEST value;
event->ws.kind = TARGET_WAITKIND_THREAD_EXITED;
case 'W': /* Target exited. */
case 'X':
{
- const char *p;
int pid;
ULONGEST value;
break;
case 'N': case 'T': case 'S': case 'X': case 'W':
{
- struct stop_reply *stop_reply;
-
/* There is a stop reply to handle. */
rs->waiting_for_stop_reply = 0;
va_start (ap, format);
rs->buf[0] = '\0';
- if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
+ int size = vsnprintf (rs->buf, max_size, format, ap);
+
+ va_end (ap);
+
+ if (size >= max_size)
internal_error (__FILE__, __LINE__, _("Too long remote packet."));
if (putpkt (rs->buf) < 0)
remote_target::kill_new_fork_children (int pid)
{
remote_state *rs = get_remote_state ();
- struct thread_info *thread;
struct notif_client *notif = ¬if_client_stop;
/* Kill the fork child threads of any threads in process PID
that are stopped at a fork event. */
- ALL_NON_EXITED_THREADS (thread)
+ for (thread_info *thread : all_non_exited_threads ())
{
struct target_waitstatus *ws = &thread->pending_follow;
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 ();
}
- if (!have_inferiors ())
- {
- /* Clean up from the last time we ran, before we mark the target
- running again. This will mark breakpoints uninserted, and
- get_offsets may insert breakpoints. */
- init_thread_list ();
- init_wait_for_inferior ();
- }
-
/* vRun's success return is a stop reply. */
stop_reply = run_worked ? rs->buf : NULL;
add_current_inferior_and_thread (stop_reply);
&remote_protocol_packets[PACKET_qGetTLSAddr]);
if (result == PACKET_OK)
{
- ULONGEST result;
+ ULONGEST addr;
- unpack_varlen_hex (rs->buf, &result);
- return result;
+ unpack_varlen_hex (rs->buf, &addr);
+ return addr;
}
else if (result == PACKET_UNKNOWN)
throw_error (TLS_GENERIC_ERROR,
&remote_protocol_packets[PACKET_qGetTIBAddr]);
if (result == PACKET_OK)
{
- ULONGEST result;
-
- unpack_varlen_hex (rs->buf, &result);
+ ULONGEST val;
+ unpack_varlen_hex (rs->buf, &val);
if (addr)
- *addr = (CORE_ADDR) result;
+ *addr = (CORE_ADDR) val;
return true;
}
else if (result == PACKET_UNKNOWN)
struct remote_g_packet_guess
{
+ remote_g_packet_guess (int bytes_, const struct target_desc *tdesc_)
+ : bytes (bytes_),
+ tdesc (tdesc_)
+ {
+ }
+
int bytes;
const struct target_desc *tdesc;
};
-typedef struct remote_g_packet_guess remote_g_packet_guess_s;
-DEF_VEC_O(remote_g_packet_guess_s);
-struct remote_g_packet_data
+struct remote_g_packet_data : public allocate_on_obstack
{
- VEC(remote_g_packet_guess_s) *guesses;
+ std::vector<remote_g_packet_guess> guesses;
};
static struct gdbarch_data *remote_g_packet_data_handle;
static void *
remote_g_packet_data_init (struct obstack *obstack)
{
- return OBSTACK_ZALLOC (obstack, struct remote_g_packet_data);
+ return new (obstack) remote_g_packet_data;
}
void
struct remote_g_packet_data *data
= ((struct remote_g_packet_data *)
gdbarch_data (gdbarch, remote_g_packet_data_handle));
- struct remote_g_packet_guess new_guess, *guess;
- int ix;
gdb_assert (tdesc != NULL);
- for (ix = 0;
- VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
- ix++)
- if (guess->bytes == bytes)
+ for (const remote_g_packet_guess &guess : data->guesses)
+ if (guess.bytes == bytes)
internal_error (__FILE__, __LINE__,
_("Duplicate g packet description added for size %d"),
bytes);
- new_guess.bytes = bytes;
- new_guess.tdesc = tdesc;
- VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
+ data->guesses.emplace_back (bytes, tdesc);
}
-/* Return 1 if remote_read_description would do anything on this target
- and architecture, 0 otherwise. */
+/* Return true if remote_read_description would do anything on this target
+ and architecture, false otherwise. */
-static int
+static bool
remote_read_description_p (struct target_ops *target)
{
struct remote_g_packet_data *data
= ((struct remote_g_packet_data *)
gdbarch_data (target_gdbarch (), remote_g_packet_data_handle));
- if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
- return 1;
-
- return 0;
+ return !data->guesses.empty ();
}
const struct target_desc *
if (!target_has_execution || inferior_ptid == null_ptid)
return beneath ()->read_description ();
- if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
+ if (!data->guesses.empty ())
{
- struct remote_g_packet_guess *guess;
- int ix;
int bytes = send_g_packet ();
- for (ix = 0;
- VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
- ix++)
- if (guess->bytes == bytes)
- return guess->tdesc;
+ for (const remote_g_packet_guess &guess : data->guesses)
+ if (guess.bytes == bytes)
+ return guess.tdesc;
/* We discard the g packet. A minor optimization would be to
hold on to it, and fill the register cache once we have selected
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."));
remote_target::remote_btrace_maybe_reopen ()
{
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;
- ALL_NON_EXITED_THREADS (tp)
+ for (thread_info *tp : all_non_exited_threads ())
{
set_general_thread (tp->ptid);
int handle_len,
inferior *inf)
{
- struct thread_info *tp;
-
- ALL_NON_EXITED_THREADS (tp)
+ for (thread_info *tp : all_non_exited_threads ())
{
remote_thread_info *priv = get_remote_thread_info (tp);