+2016-10-26 Pedro Alves <palves@redhat.com>
+
+ * linux-low.c (handle_extended_wait): Link parent/child fork
+ threads.
+ (linux_wait_1): Unlink them.
+ (linux_set_resume_request): Ignore resume requests for
+ already-resumed and unhandled fork child threads.
+ * linux-low.h (struct lwp_info) <fork_relative>: New field.
+ * server.c (in_queued_stop_replies_ptid, in_queued_stop_replies):
+ New functions.
+ (handle_v_requests) <vCont>: Don't call require_running.
+ * server.h (in_queued_stop_replies): New declaration.
+
2016-10-24 Yao Qi <yao.qi@linaro.org>
PR server/20733
event_lwp->status_pending_p = 1;
event_lwp->status_pending = wstat;
+ /* Link the threads until the parent event is passed on to
+ higher layers. */
+ event_lwp->fork_relative = child_lwp;
+ child_lwp->fork_relative = event_lwp;
+
/* If the parent thread is doing step-over with single-step
breakpoints, the list of single-step breakpoints are cloned
from the parent's. Remove them from the child process.
{
/* If the reported event is an exit, fork, vfork or exec, let
GDB know. */
+
+ /* Break the unreported fork relationship chain. */
+ if (event_child->waitstatus.kind == TARGET_WAITKIND_FORKED
+ || event_child->waitstatus.kind == TARGET_WAITKIND_VFORKED)
+ {
+ event_child->fork_relative->fork_relative = NULL;
+ event_child->fork_relative = NULL;
+ }
+
*ourstatus = event_child->waitstatus;
/* Clear the event lwp's waitstatus since we handled it already. */
event_child->waitstatus.kind = TARGET_WAITKIND_IGNORE;
continue;
}
+ /* Ignore (wildcard) resume requests for already-resumed
+ threads. */
+ if (r->resume[ndx].kind != resume_stop
+ && thread->last_resume_kind != resume_stop)
+ {
+ if (debug_threads)
+ debug_printf ("already %s LWP %ld at GDB's request\n",
+ (thread->last_resume_kind
+ == resume_step)
+ ? "stepping"
+ : "continuing",
+ lwpid_of (thread));
+ continue;
+ }
+
+ /* Don't let wildcard resumes resume fork children that GDB
+ does not yet know are new fork children. */
+ if (lwp->fork_relative != NULL)
+ {
+ struct inferior_list_entry *inf, *tmp;
+ struct lwp_info *rel = lwp->fork_relative;
+
+ if (rel->status_pending_p
+ && (rel->waitstatus.kind == TARGET_WAITKIND_FORKED
+ || rel->waitstatus.kind == TARGET_WAITKIND_VFORKED))
+ {
+ if (debug_threads)
+ debug_printf ("not resuming LWP %ld: has queued stop reply\n",
+ lwpid_of (thread));
+ continue;
+ }
+ }
+
+ /* If the thread has a pending event that has already been
+ reported to GDBserver core, but GDB has not pulled the
+ event out of the vStopped queue yet, likewise, ignore the
+ (wildcard) resume request. */
+ if (in_queued_stop_replies (entry->id))
+ {
+ if (debug_threads)
+ debug_printf ("not resuming LWP %ld: has queued stop reply\n",
+ lwpid_of (thread));
+ continue;
+ }
+
lwp->resume = &r->resume[ndx];
thread->last_resume_kind = lwp->resume->kind;
information or exit status until it can be reported to GDB. */
struct target_waitstatus waitstatus;
+ /* A pointer to the fork child/parent relative. Valid only while
+ the parent fork event is not reported to higher layers. Used to
+ avoid wildcard vCont actions resuming a fork child before GDB is
+ notified about the parent's fork event. */
+ struct lwp_info *fork_relative;
+
/* When stopped is set, this is where the lwp last stopped, with
decr_pc_after_break already accounted for. If the LWP is
running, this is the address at which the lwp was resumed. */
prepare_resume_reply (own_buf, vstop->ptid, &vstop->status);
}
+/* QUEUE_iterate callback helper for in_queued_stop_replies. */
+
+static int
+in_queued_stop_replies_ptid (QUEUE (notif_event_p) *q,
+ QUEUE_ITER (notif_event_p) *iter,
+ struct notif_event *event,
+ void *data)
+{
+ ptid_t filter_ptid = *(ptid_t *) data;
+ struct vstop_notif *vstop_event = (struct vstop_notif *) event;
+
+ if (ptid_match (vstop_event->ptid, filter_ptid))
+ return 0;
+
+ /* Don't resume fork children that GDB does not know about yet. */
+ if ((vstop_event->status.kind == TARGET_WAITKIND_FORKED
+ || vstop_event->status.kind == TARGET_WAITKIND_VFORKED)
+ && ptid_match (vstop_event->status.value.related_pid, filter_ptid))
+ return 0;
+
+ return 1;
+}
+
+/* See server.h. */
+
+int
+in_queued_stop_replies (ptid_t ptid)
+{
+ return !QUEUE_iterate (notif_event_p, notif_stop.queue,
+ in_queued_stop_replies_ptid, &ptid);
+}
+
struct notif_server notif_stop =
{
"vStopped", "Stop", NULL, vstop_notif_reply,
if (startswith (own_buf, "vCont;"))
{
- require_running (own_buf);
handle_v_cont (own_buf);
return;
}
/* Get rid of the currently pending stop replies that match PTID. */
extern void discard_queued_stop_replies (ptid_t ptid);
+/* Returns true if there's a pending stop reply that matches PTID in
+ the vStopped notifications queue. */
+extern int in_queued_stop_replies (ptid_t ptid);
+
#include "remote-utils.h"
#include "utils.h"