struct packet_reg;
struct stop_reply;
-typedef struct stop_reply *stop_reply_p;
+static void stop_reply_xfree (struct stop_reply *);
+
+struct stop_reply_deleter
+{
+ void operator() (stop_reply *r) const
+ {
+ stop_reply_xfree (r);
+ }
+};
-DECLARE_QUEUE_P (stop_reply_p);
-DEFINE_QUEUE_P (stop_reply_p);
+typedef std::unique_ptr<stop_reply, stop_reply_deleter> stop_reply_up;
/* Generic configuration support for packets the stub optionally
supports. Allows the user to specify the use of the packet as well
should be queued first, and be consumed by remote_wait_{ns,as}
one per time. Other notifications can consume their events
immediately, so queue is not needed for them. */
- QUEUE (stop_reply_p) *stop_reply_queue;
+ std::vector<stop_reply_up> stop_reply_queue;
/* Asynchronous signal handle registered as event loop source for
when we have pending events ready to be passed to the core. */
ptid_t ptid);
static void open_1 (const char *name, int from_tty, int extended_p);
void start_remote (int from_tty, int extended_p);
- void remote_detach_1 (int from_tty, struct inferior *inf);
+ void remote_detach_1 (struct inferior *inf, int from_tty);
char *append_resumption (char *p, char *endp,
ptid_t ptid, int step, gdb_signal siggnal);
void process_initial_stop_replies (int from_tty);
- void remote_add_thread (ptid_t ptid, bool running, bool executing);
+ thread_info *remote_add_thread (ptid_t ptid, bool running, bool executing);
void btrace_sync_conf (const btrace_config *conf);
static ptid_t read_ptid (const char *buf, const char **obuf);
-struct stop_reply;
-static void stop_reply_xfree (struct stop_reply *);
-
static void remote_async_inferior_event_handler (gdb_client_data);
static int remote_read_description_p (struct target_ops *target);
whenever a larger buffer is needed. */
this->buf_size = 400;
this->buf = (char *) xmalloc (this->buf_size);
-
- this->stop_reply_queue = QUEUE_alloc (stop_reply_p, stop_reply_xfree);
}
remote_state::~remote_state ()
xfree (this->buf);
xfree (this->finished_object);
xfree (this->finished_annex);
- QUEUE_free (stop_reply_p, this->stop_reply_queue);
}
/* Utility: generate error from an incoming stub packet. */
}
static remote_thread_info *get_remote_thread_info (thread_info *thread);
+static remote_thread_info *get_remote_thread_info (ptid_t ptid);
/* Add thread PTID to GDB's thread list. Tag it as executing/running
according to RUNNING. */
-void
+thread_info *
remote_target::remote_add_thread (ptid_t ptid, bool running, bool executing)
{
struct remote_state *rs = get_remote_state ();
get_remote_thread_info (thread)->vcont_resumed = executing;
set_executing (ptid, executing);
set_running (ptid, running);
+
+ return thread;
}
/* Come here when we learn about a thread id from the remote target.
/* If this is a new thread, add it to GDB's thread list.
If we leave it up to WFI to do this, bad things will happen. */
- if (in_thread_list (currthread) && is_exited (currthread))
+ thread_info *tp = find_thread_ptid (currthread);
+ if (tp != NULL && tp->state == THREAD_EXITED)
{
/* We're seeing an event on a thread id we knew had exited.
This has to be a new thread reusing the old id. Add it. */
if (!in_thread_list (currthread))
{
struct inferior *inf = NULL;
- int pid = ptid_get_pid (currthread);
+ int pid = currthread.pid ();
if (ptid_is_pid (inferior_ptid)
- && pid == ptid_get_pid (inferior_ptid))
+ && pid == inferior_ptid.pid ())
{
/* inferior_ptid has no thread member yet. This can happen
with the vAttach -> remote_wait,"TAAthread:" path if the
stub doesn't support qC. This is the first stop reported
after an attach, so this is the main thread. Update the
ptid in the thread list. */
- if (in_thread_list (pid_to_ptid (pid)))
+ if (in_thread_list (ptid_t (pid)))
thread_change_ptid (inferior_ptid, currthread);
else
{
extended-remote which already was debugging an inferior, we
may not know about it yet. Add it before adding its child
thread, so notifications are emitted in a sensible order. */
- if (!in_inferior_list (ptid_get_pid (currthread)))
+ if (find_inferior_pid (currthread.pid ()) == NULL)
{
struct remote_state *rs = get_remote_state ();
int fake_pid_p = !remote_multi_process_p (rs);
inf = remote_add_inferior (fake_pid_p,
- ptid_get_pid (currthread), -1, 1);
+ currthread.pid (), -1, 1);
}
/* This is really a new thread. Add it. */
- remote_add_thread (currthread, running, executing);
+ thread_info *new_thr
+ = remote_add_thread (currthread, running, executing);
/* If we found a new inferior, let the common code do whatever
it needs to with it (e.g., read shared libraries, insert
struct remote_state *rs = get_remote_state ();
if (!rs->starting_up)
- notice_new_inferior (currthread, executing, 0);
+ notice_new_inferior (new_thr, executing, 0);
}
}
}
return static_cast<remote_thread_info *> (thread->priv.get ());
}
-/* Return PTID's private thread data, creating it if necessary. */
-
static remote_thread_info *
get_remote_thread_info (ptid_t ptid)
{
- struct thread_info *info = find_thread_ptid (ptid);
-
- return get_remote_thread_info (info);
+ thread_info *thr = find_thread_ptid (ptid);
+ return get_remote_thread_info (thr);
}
/* Call this function as a result of
/* We only need to change the remote current thread if it's pointing
at some other process. */
- if (ptid_get_pid (rs->general_thread) != ptid_get_pid (inferior_ptid))
+ if (rs->general_thread.pid () != inferior_ptid.pid ())
set_general_thread (inferior_ptid);
}
/* The main thread is always alive. */
return 1;
- if (ptid_get_pid (ptid) != 0 && ptid_get_lwp (ptid) == 0)
+ if (ptid.pid () != 0 && ptid_get_lwp (ptid) == 0)
/* The main thread is always alive. This can happen after a
vAttach, if the remote side doesn't support
multi-threading. */
if (remote_multi_process_p (rs))
{
- pid = ptid_get_pid (ptid);
+ pid = ptid.pid ();
if (pid < 0)
buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
else
pp = unpack_varlen_hex (p + 1, &tid);
if (obuf)
*obuf = pp;
- return ptid_build (pid, tid, 0);
+ return ptid_t (pid, tid, 0);
}
/* No multi-process. Just a tid. */
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))
- pid = ptid_get_pid (magic_null_ptid);
+ pid = magic_null_ptid.pid ();
else
- pid = ptid_get_pid (inferior_ptid);
+ pid = inferior_ptid.pid ();
if (obuf)
*obuf = pp;
- return ptid_build (pid, tid, 0);
+ return ptid_t (pid, tid, 0);
}
static int
if (!context.contains_thread (tp->ptid))
{
/* Not found. */
- delete_thread (tp->ptid);
+ delete_thread (tp);
}
}
remote_notice_new_inferior (item.ptid, executing);
- remote_thread_info *info = get_remote_thread_info (item.ptid);
+ thread_info *tp = find_thread_ptid (item.ptid);
+ remote_thread_info *info = get_remote_thread_info (tp);
info->core = item.core;
info->extra = std::move (item.extra);
info->name = std::move (item.name);
remote_target::extra_thread_info (thread_info *tp)
{
struct remote_state *rs = get_remote_state ();
- int result;
int set;
threadref id;
struct gdb_ext_thread_info threadinfo;
- static char display_buf[100]; /* arbitrary... */
- int n = 0; /* position in display_buf */
if (rs->remote_desc == 0) /* paranoia */
internal_error (__FILE__, __LINE__,
_("remote_threads_extra_info"));
if (ptid_equal (tp->ptid, magic_null_ptid)
- || (ptid_get_pid (tp->ptid) != 0 && ptid_get_lwp (tp->ptid) == 0))
+ || (tp->ptid.pid () != 0 && ptid_get_lwp (tp->ptid) == 0))
/* This is the main thread which was added by GDB. The remote
server doesn't know about it. */
return NULL;
+ std::string &extra = get_remote_thread_info (tp)->extra;
+
+ /* If already have cached info, use it. */
+ if (!extra.empty ())
+ return extra.c_str ();
+
if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
{
- struct thread_info *info = find_thread_ptid (tp->ptid);
-
- if (info != NULL && info->priv != NULL)
- {
- const std::string &extra = get_remote_thread_info (info)->extra;
- return !extra.empty () ? extra.c_str () : NULL;
- }
- else
- return NULL;
+ /* If we're using qXfer:threads:read, then the extra info is
+ included in the XML. So if we didn't have anything cached,
+ it's because there's really no extra info. */
+ return NULL;
}
if (rs->use_threadextra_query)
getpkt (&rs->buf, &rs->buf_size, 0);
if (rs->buf[0] != 0)
{
- n = std::min (strlen (rs->buf) / 2, sizeof (display_buf));
- result = hex2bin (rs->buf, (gdb_byte *) display_buf, n);
- display_buf [result] = '\0';
- return display_buf;
+ extra.resize (strlen (rs->buf) / 2);
+ hex2bin (rs->buf, (gdb_byte *) &extra[0], extra.size ());
+ return extra.c_str ();
}
}
if (threadinfo.active)
{
if (*threadinfo.shortname)
- n += xsnprintf (&display_buf[0], sizeof (display_buf) - n,
- " Name: %s,", threadinfo.shortname);
+ string_appendf (extra, " Name: %s", threadinfo.shortname);
if (*threadinfo.display)
- n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
- " State: %s,", threadinfo.display);
+ {
+ if (!extra.empty ())
+ extra += ',';
+ string_appendf (extra, " State: %s", threadinfo.display);
+ }
if (*threadinfo.more_display)
- n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
- " Priority: %s", threadinfo.more_display);
-
- if (n > 0)
{
- /* For purely cosmetic reasons, clear up trailing commas. */
- if (',' == display_buf[n-1])
- display_buf[n-1] = ' ';
- return display_buf;
+ if (!extra.empty ())
+ extra += ',';
+ string_appendf (extra, " Priority: %s", threadinfo.more_display);
}
+ return extra.c_str ();
}
return NULL;
}
ptid_t
remote_target::get_ada_task_ptid (long lwp, long thread)
{
- return ptid_build (ptid_get_pid (inferior_ptid), lwp, 0);
+ return ptid_t (inferior_ptid.pid (), lwp, 0);
}
\f
fake_pid_p = 1;
}
- remote_add_inferior (fake_pid_p, ptid_get_pid (curr_ptid), -1, 1);
+ remote_add_inferior (fake_pid_p, curr_ptid.pid (), -1, 1);
/* Add the main thread and switch to it. Don't try reading
registers yet, since we haven't fetched the target description
{
struct target_waitstatus *ws = &thread->suspend.waitstatus;
- switch_to_thread (thread->ptid);
- stop_pc = get_frame_pc (get_current_frame ());
+ switch_to_thread (thread);
+ thread->suspend.stop_pc = get_frame_pc (get_current_frame ());
set_current_sal_from_frame (get_current_frame ());
thread->suspend.waitstatus_pending_p = 0;
if (non_stop)
{
- thread = any_live_thread_of_process (inf->pid);
- notice_new_inferior (thread->ptid,
- thread->state == THREAD_RUNNING,
+ thread = any_live_thread_of_inferior (inf);
+ notice_new_inferior (thread, thread->state == THREAD_RUNNING,
from_tty);
}
}
if (inf->needs_setup)
{
- thread = any_live_thread_of_process (inf->pid);
+ thread = any_live_thread_of_inferior (inf);
switch_to_thread_no_regs (thread);
setup_inferior (0);
}
first = thread;
if (!non_stop)
- set_running (thread->ptid, 0);
+ thread->set_running (false);
else if (thread->state != THREAD_STOPPED)
continue;
one. */
void
-remote_target::remote_detach_1 (int from_tty, inferior *inf)
+remote_target::remote_detach_1 (inferior *inf, int from_tty)
{
- int pid = ptid_get_pid (inferior_ptid);
+ int pid = inferior_ptid.pid ();
struct remote_state *rs = get_remote_state ();
- struct thread_info *tp = find_thread_ptid (inferior_ptid);
int is_fork_parent;
if (!target_has_execution)
if (from_tty && !rs->extended && number_of_live_inferiors () == 1)
puts_filtered (_("Ending remote debugging.\n"));
+ struct thread_info *tp = find_thread_ptid (inferior_ptid);
+
/* Check to see if we are detaching a fork parent. Note that if we
are detaching a fork child, tp == NULL. */
is_fork_parent = (tp != NULL
{
/* Save the pid as a string before mourning, since that will
unpush the remote target, and we need the string after. */
- std::string infpid = target_pid_to_str (pid_to_ptid (pid));
+ std::string infpid = target_pid_to_str (ptid_t (pid));
target_mourn_inferior (inferior_ptid);
if (print_inferior_events)
else
{
inferior_ptid = null_ptid;
- detach_inferior (pid);
+ detach_inferior (current_inferior ());
}
}
void
remote_target::detach (inferior *inf, int from_tty)
{
- remote_detach_1 (from_tty, inf);
+ remote_detach_1 (inf, from_tty);
}
void
extended_remote_target::detach (inferior *inf, int from_tty)
{
- remote_detach_1 (from_tty, inf);
+ remote_detach_1 (inf, from_tty);
}
/* Target follow-fork function for remote targets. On entry, and
pid_t child_pid;
child_ptid = inferior_thread ()->pending_follow.value.related_pid;
- child_pid = ptid_get_pid (child_ptid);
+ child_pid = child_ptid.pid ();
remote_detach_pid (child_pid);
}
if (exec_file)
printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
- target_pid_to_str (pid_to_ptid (pid)));
+ target_pid_to_str (ptid_t (pid)));
else
printf_unfiltered (_("Attaching to %s\n"),
- target_pid_to_str (pid_to_ptid (pid)));
+ target_pid_to_str (ptid_t (pid)));
gdb_flush (gdb_stdout);
}
}
else if (strcmp (rs->buf, "OK") != 0)
error (_("Attaching to %s failed with: %s"),
- target_pid_to_str (pid_to_ptid (pid)),
+ target_pid_to_str (ptid_t (pid)),
rs->buf);
break;
case PACKET_UNKNOWN:
error (_("This target does not support attaching to a process"));
default:
error (_("Attaching to %s failed"),
- target_pid_to_str (pid_to_ptid (pid)));
+ target_pid_to_str (ptid_t (pid)));
}
set_current_inferior (remote_add_inferior (0, pid, 1, 0));
- inferior_ptid = pid_to_ptid (pid);
+ inferior_ptid = ptid_t (pid);
if (target_is_non_stop_p ())
{
/* Get list of threads. */
update_thread_list ();
- thread = first_thread_of_process (pid);
+ thread = first_thread_of_inferior (current_inferior ());
if (thread)
inferior_ptid = thread->ptid;
else
- inferior_ptid = pid_to_ptid (pid);
+ inferior_ptid = ptid_t (pid);
/* Invalidate our notion of the remote current thread. */
record_currthread (rs, minus_one_ptid);
ptid_t nptid;
/* All (-1) threads of process. */
- nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
+ nptid = ptid_t (ptid.pid (), -1, 0);
p += xsnprintf (p, endp - p, ":");
p = write_ptid (p, endp, nptid);
{
if (get_remote_inferior (inf)->may_wildcard_vcont)
{
- vcont_builder.push_action (pid_to_ptid (inf->pid),
+ vcont_builder.push_action (ptid_t (inf->pid),
false, GDB_SIGNAL_0);
}
}
if (ptid_is_pid (ptid))
/* All (-1) threads of process. */
- nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
+ nptid = ptid_t (ptid.pid (), -1, 0);
else
{
/* Small optimization: if we already have a stop reply for
remote_target::stop_reply_queue_length ()
{
remote_state *rs = get_remote_state ();
- return QUEUE_length (stop_reply_p, rs->stop_reply_queue);
+ return rs->stop_reply_queue.size ();
}
void
REMOTE_NOTIF_STOP,
};
-/* A parameter to pass data in and out. */
-
-struct queue_iter_param
-{
- remote_target *remote;
- void *input;
- struct stop_reply *output;
-};
-
/* Determine if THREAD_PTID is a pending fork parent thread. ARG contains
the pid of the process that owns the threads we want to check, or
-1 if we want to check all threads. */
if (ws->kind == TARGET_WAITKIND_FORKED
|| ws->kind == TARGET_WAITKIND_VFORKED)
{
- if (event_pid == -1 || event_pid == ptid_get_pid (thread_ptid))
+ if (event_pid == -1 || event_pid == thread_ptid.pid ())
return 1;
}
return is_pending_fork_parent (ws, pid, thread->ptid);
}
-/* Check whether EVENT is a fork event, and if it is, remove the
- fork child from the context list passed in DATA. */
-
-static int
-remove_child_of_pending_fork (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
-{
- struct queue_iter_param *param = (struct queue_iter_param *) data;
- struct threads_listing_context *context
- = (struct threads_listing_context *) param->input;
-
- if (event->ws.kind == TARGET_WAITKIND_FORKED
- || event->ws.kind == TARGET_WAITKIND_VFORKED
- || event->ws.kind == TARGET_WAITKIND_THREAD_EXITED)
- context->remove_thread (event->ws.value.related_pid);
-
- return 1;
-}
-
/* If CONTEXT contains any fork child threads that have not been
reported yet, remove them from the CONTEXT list. If such a
thread exists it is because we are stopped at a fork catchpoint
struct thread_info * thread;
int pid = -1;
struct notif_client *notif = ¬if_client_stop;
- struct queue_iter_param param;
/* For any threads stopped at a fork event, remove the corresponding
fork child threads from the CONTEXT list. */
in process PID and remove those fork child threads from the
CONTEXT list as well. */
remote_notif_get_pending_events (notif);
- param.remote = this;
- param.input = context;
- param.output = NULL;
- QUEUE_iterate (stop_reply_p, get_remote_state ()->stop_reply_queue,
- remove_child_of_pending_fork, ¶m);
-}
-
-/* Callback data for
- check_pending_event_prevents_wildcard_vcont_callback. */
-struct check_pending_event_prevents_wildcard_vcont_callback_data
-{
- /* The remote target. */
- remote_target *remote;
-
- /* Whether we can do a global wildcard (vCont;c) */
- int *may_global_wildcard_vcont;
-};
-
-/* Check whether EVENT would prevent a global or process wildcard
- vCont action. */
-
-static int
-check_pending_event_prevents_wildcard_vcont_callback
- (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
-{
- struct inferior *inf;
- auto *cb_data = (check_pending_event_prevents_wildcard_vcont_callback_data *) data;
-
- if (event->ws.kind == TARGET_WAITKIND_NO_RESUMED
- || event->ws.kind == TARGET_WAITKIND_NO_HISTORY)
- return 1;
-
- if (event->ws.kind == TARGET_WAITKIND_FORKED
- || event->ws.kind == TARGET_WAITKIND_VFORKED)
- *cb_data->may_global_wildcard_vcont = 0;
-
- inf = find_inferior_ptid (event->ptid);
-
- /* This may be the first time we heard about this process.
- Regardless, we must not do a global wildcard resume, otherwise
- we'd resume this process too. */
- *cb_data->may_global_wildcard_vcont = 0;
- if (inf != NULL)
- get_remote_inferior (inf)->may_wildcard_vcont = false;
-
- return 1;
+ for (auto &event : get_remote_state ()->stop_reply_queue)
+ if (event->ws.kind == TARGET_WAITKIND_FORKED
+ || event->ws.kind == TARGET_WAITKIND_VFORKED
+ || event->ws.kind == TARGET_WAITKIND_THREAD_EXITED)
+ context->remove_thread (event->ws.value.related_pid);
}
/* Check whether any event pending in the vStopped queue would prevent
(int *may_global_wildcard)
{
struct notif_client *notif = ¬if_client_stop;
- check_pending_event_prevents_wildcard_vcont_callback_data cb_data
- {this, may_global_wildcard};
remote_notif_get_pending_events (notif);
- QUEUE_iterate (stop_reply_p, get_remote_state ()->stop_reply_queue,
- check_pending_event_prevents_wildcard_vcont_callback,
- &cb_data);
-}
+ for (auto &event : get_remote_state ()->stop_reply_queue)
+ {
+ if (event->ws.kind == TARGET_WAITKIND_NO_RESUMED
+ || event->ws.kind == TARGET_WAITKIND_NO_HISTORY)
+ continue;
-/* Remove stop replies in the queue if its pid is equal to the given
- inferior's pid. */
+ if (event->ws.kind == TARGET_WAITKIND_FORKED
+ || event->ws.kind == TARGET_WAITKIND_VFORKED)
+ *may_global_wildcard = 0;
-static int
-remove_stop_reply_for_inferior (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
-{
- struct queue_iter_param *param = (struct queue_iter_param *) data;
- struct inferior *inf = (struct inferior *) param->input;
+ struct inferior *inf = find_inferior_ptid (event->ptid);
- if (ptid_get_pid (event->ptid) == inf->pid)
- {
- stop_reply_xfree (event);
- QUEUE_remove_elem (stop_reply_p, q, iter);
+ /* This may be the first time we heard about this process.
+ Regardless, we must not do a global wildcard resume, otherwise
+ we'd resume this process too. */
+ *may_global_wildcard = 0;
+ if (inf != NULL)
+ get_remote_inferior (inf)->may_wildcard_vcont = false;
}
-
- return 1;
}
/* Discard all pending stop replies of inferior INF. */
void
remote_target::discard_pending_stop_replies (struct inferior *inf)
{
- struct queue_iter_param param;
struct stop_reply *reply;
struct remote_state *rs = get_remote_state ();
struct remote_notif_state *rns = rs->notif_state;
reply = (struct stop_reply *) rns->pending_event[notif_client_stop.id];
/* Discard the in-flight notification. */
- if (reply != NULL && ptid_get_pid (reply->ptid) == inf->pid)
+ if (reply != NULL && reply->ptid.pid () == inf->pid)
{
stop_reply_xfree (reply);
rns->pending_event[notif_client_stop.id] = NULL;
}
- param.remote = this;
- param.input = inf;
- param.output = NULL;
/* Discard the stop replies we have already pulled with
vStopped. */
- QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
- remove_stop_reply_for_inferior, ¶m);
-}
-
-/* If its remote state is equal to the given remote state,
- remove EVENT from the stop reply queue. */
-
-static int
-remove_stop_reply_of_remote_state (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
-{
- struct queue_iter_param *param = (struct queue_iter_param *) data;
- struct remote_state *rs = (struct remote_state *) param->input;
-
- if (event->rs == rs)
- {
- stop_reply_xfree (event);
- QUEUE_remove_elem (stop_reply_p, q, iter);
- }
-
- return 1;
+ auto iter = std::remove_if (rs->stop_reply_queue.begin (),
+ rs->stop_reply_queue.end (),
+ [=] (const stop_reply_up &event)
+ {
+ return event->ptid.pid () == inf->pid;
+ });
+ rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ());
}
/* Discard the stop replies for RS in stop_reply_queue. */
remote_target::discard_pending_stop_replies_in_queue ()
{
remote_state *rs = get_remote_state ();
- struct queue_iter_param param;
- param.remote = this;
- param.input = rs;
- param.output = NULL;
/* Discard the stop replies we have already pulled with
vStopped. */
- QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
- remove_stop_reply_of_remote_state, ¶m);
-}
-
-/* A parameter to pass data in and out. */
-
-static int
-remote_notif_remove_once_on_match (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
-{
- struct queue_iter_param *param = (struct queue_iter_param *) data;
- ptid_t *ptid = (ptid_t *) param->input;
-
- if (ptid_match (event->ptid, *ptid))
- {
- param->output = event;
- QUEUE_remove_elem (stop_reply_p, q, iter);
- return 0;
- }
-
- return 1;
+ auto iter = std::remove_if (rs->stop_reply_queue.begin (),
+ rs->stop_reply_queue.end (),
+ [=] (const stop_reply_up &event)
+ {
+ return event->rs == rs;
+ });
+ rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ());
}
/* Remove the first reply in 'stop_reply_queue' which matches
struct stop_reply *
remote_target::remote_notif_remove_queued_reply (ptid_t ptid)
{
- struct queue_iter_param param;
+ remote_state *rs = get_remote_state ();
- param.remote = this;
- param.input = &ptid;
- param.output = NULL;
+ auto iter = std::find_if (rs->stop_reply_queue.begin (),
+ rs->stop_reply_queue.end (),
+ [=] (const stop_reply_up &event)
+ {
+ return event->ptid.matches (ptid);
+ });
+ struct stop_reply *result;
+ if (iter == rs->stop_reply_queue.end ())
+ result = nullptr;
+ else
+ {
+ result = iter->release ();
+ rs->stop_reply_queue.erase (iter);
+ }
- QUEUE_iterate (stop_reply_p, get_remote_state ()->stop_reply_queue,
- remote_notif_remove_once_on_match, ¶m);
if (notif_debug)
fprintf_unfiltered (gdb_stdlog,
"notif: discard queued event: 'Stop' in %s\n",
target_pid_to_str (ptid));
- return param.output;
+ return result;
}
/* Look for a queued stop reply belonging to PTID. If one is found,
struct stop_reply *
remote_target::queued_stop_reply (ptid_t ptid)
{
+ remote_state *rs = get_remote_state ();
struct stop_reply *r = remote_notif_remove_queued_reply (ptid);
- if (!QUEUE_is_empty (stop_reply_p, get_remote_state ()->stop_reply_queue))
+ if (!rs->stop_reply_queue.empty ())
{
- remote_state *rs = get_remote_state ();
/* There's still at least an event left. */
mark_async_event_handler (rs->remote_async_inferior_event_token);
}
remote_target::push_stop_reply (struct stop_reply *new_event)
{
remote_state *rs = get_remote_state ();
- QUEUE_enque (stop_reply_p, rs->stop_reply_queue, new_event);
+ rs->stop_reply_queue.push_back (stop_reply_up (new_event));
if (notif_debug)
fprintf_unfiltered (gdb_stdlog,
"notif: push 'Stop' %s to queue %d\n",
target_pid_to_str (new_event->ptid),
- QUEUE_length (stop_reply_p,
- rs->stop_reply_queue));
+ int (rs->stop_reply_queue.size ()));
mark_async_event_handler (rs->remote_async_inferior_event_token);
}
-static int
-stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- struct stop_reply *event,
- void *data)
-{
- ptid_t *ptid = (ptid_t *) data;
-
- return !(ptid_equal (*ptid, event->ptid)
- && event->ws.kind == TARGET_WAITKIND_STOPPED);
-}
-
/* Returns true if we have a stop reply for PTID. */
int
remote_target::peek_stop_reply (ptid_t ptid)
{
remote_state *rs = get_remote_state ();
- return !QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
- stop_reply_match_ptid_and_ws, &ptid);
+ for (auto &event : rs->stop_reply_queue)
+ if (ptid == event->ptid
+ && event->ws.kind == TARGET_WAITKIND_STOPPED)
+ return 1;
+ return 0;
}
/* Helper for remote_parse_stop_reply. Return nonzero if the substring
}
/* If no process is specified, assume inferior_ptid. */
- pid = ptid_get_pid (inferior_ptid);
+ pid = inferior_ptid.pid ();
if (*p == '\0')
;
else if (*p == ';')
}
else
error (_("unknown stop reply packet: %s"), buf);
- event->ptid = pid_to_ptid (pid);
+ event->ptid = ptid_t (pid);
}
break;
case 'N':
/* If there are are events left in the queue tell the event loop
to return here. */
- if (!QUEUE_is_empty (stop_reply_p, rs->stop_reply_queue))
+ if (!rs->stop_reply_queue.empty ())
mark_async_event_handler (rs->remote_async_inferior_event_token);
}
is_notif);
}
-/* Check whether EVENT is a fork event for the process specified
- by the pid passed in DATA, and if it is, kill the fork child. */
-
-int
-remote_kill_child_of_pending_fork (QUEUE (stop_reply_p) *q,
- QUEUE_ITER (stop_reply_p) *iter,
- stop_reply_p event,
- void *data)
-{
- struct queue_iter_param *param = (struct queue_iter_param *) data;
- int parent_pid = *(int *) param->input;
-
- if (is_pending_fork_parent (&event->ws, parent_pid, event->ptid))
- {
- remote_target *remote = param->remote;
- int child_pid = ptid_get_pid (event->ws.value.related_pid);
- int res;
-
- res = remote->remote_vkill (child_pid);
- if (res != 0)
- error (_("Can't kill fork child process %d"), child_pid);
- }
-
- return 1;
-}
-
/* Kill any new fork children of process PID that haven't been
processed by follow_fork. */
remote_state *rs = get_remote_state ();
struct thread_info *thread;
struct notif_client *notif = ¬if_client_stop;
- struct queue_iter_param param;
/* Kill the fork child threads of any threads in process PID
that are stopped at a fork event. */
if (is_pending_fork_parent (ws, pid, thread->ptid))
{
- int child_pid = ptid_get_pid (ws->value.related_pid);
+ int child_pid = ws->value.related_pid.pid ();
int res;
res = remote_vkill (child_pid);
/* Check for any pending fork events (not reported or processed yet)
in process PID and kill those fork child threads as well. */
remote_notif_get_pending_events (notif);
- param.remote = this;
- param.input = &pid;
- param.output = NULL;
- QUEUE_iterate (stop_reply_p, rs->stop_reply_queue,
- remote_kill_child_of_pending_fork, ¶m);
+ for (auto &event : rs->stop_reply_queue)
+ if (is_pending_fork_parent (&event->ws, pid, event->ptid))
+ {
+ int child_pid = event->ws.value.related_pid.pid ();
+ int res;
+
+ res = remote_vkill (child_pid);
+ if (res != 0)
+ error (_("Can't kill fork child process %d"), child_pid);
+ }
}
\f
remote_target::kill ()
{
int res = -1;
- int pid = ptid_get_pid (inferior_ptid);
+ int pid = inferior_ptid.pid ();
struct remote_state *rs = get_remote_state ();
if (packet_support (PACKET_vKill) != PACKET_DISABLE)
threadalive_test (const char *cmd, int tty)
{
int sample_thread = SAMPLE_THREAD;
- int pid = ptid_get_pid (inferior_ptid);
- ptid_t ptid = ptid_build (pid, sample_thread, 0);
+ int pid = inferior_ptid.pid ();
+ ptid_t ptid = ptid_t (pid, sample_thread, 0);
if (remote_thread_alive (ptid))
printf_filtered ("PASS: Thread alive test\n");
return normal_pid_to_str (ptid);
else
xsnprintf (buf, sizeof buf, "Thread %d.%ld",
- ptid_get_pid (ptid), ptid_get_lwp (ptid));
+ ptid.pid (), ptid_get_lwp (ptid));
else
xsnprintf (buf, sizeof buf, "Thread %ld",
ptid_get_lwp (ptid));
/* If there are pending events in the stop reply queue tell the
event loop to process them. */
- if (!QUEUE_is_empty (stop_reply_p, rs->stop_reply_queue))
+ if (!rs->stop_reply_queue.empty ())
mark_async_event_handler (rs->remote_async_inferior_event_token);
/* For simplicity, below we clear the pending events token
without remembering whether it is marked, so here we always
/* Take advantage of the fact that the TID field is not used, to tag
special ptids with it set to != 0. */
- magic_null_ptid = ptid_build (42000, -1, 1);
- not_sent_ptid = ptid_build (42000, -2, 1);
- any_thread_ptid = ptid_build (42000, 0, 1);
+ magic_null_ptid = ptid_t (42000, -1, 1);
+ not_sent_ptid = ptid_t (42000, -2, 1);
+ any_thread_ptid = ptid_t (42000, 0, 1);
}