Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 5a04c4c

Browse files
committed
gdbserver: Leave already-vCont-resumed threads as they were
Currently GDB never sends more than one action per vCont packet, when connected in non-stop mode. A follow up patch will change that, and it exposed a gdbserver problem with the vCont handling. For example, this in non-stop mode: => vCont;s:p1.1;c <= OK Should be equivalent to: => vCont;s:p1.1 <= OK => vCont;c <= OK But gdbserver currently doesn't handle this. In the latter case, "vCont;c" makes gdbserver clobber the previous step request. This patch fixes that. Note the server side must ignore resume actions for the thread that has a pending %Stopped notification (and any other threads with events pending), until GDB acks the notification with vStopped. Otherwise, e.g., the following case is mishandled: #1 => g (or any other packet) #2 <= [registers] #3 <= %Stopped T05 thread:p1.2 #4 => vCont s:p1.1;c #5 <= OK Above, the server must not resume thread p1.2 when it processes the vCont. GDB can't know that p1.2 stopped until it acks the %Stopped notification. (Otherwise it wouldn't send a default "c" action.) (The vCont documentation already specifies this.) Finally, special care must also be given to handling fork/vfork events. A (v)fork event actually tells us that two processes stopped -- the parent and the child. Until we follow the fork, we must not resume the child. Therefore, if we have a pending fork follow, we must not send a global wildcard resume action (vCont;c). We can still send process-wide wildcards though. (The comments above will be added as code comments to gdb in a follow up patch.) gdb/gdbserver/ChangeLog: 2016-10-26 Pedro Alves <[email protected]> * 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.
1 parent ca6eff5 commit 5a04c4c

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

gdb/gdbserver/ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2016-10-26 Pedro Alves <[email protected]>
2+
3+
* linux-low.c (handle_extended_wait): Link parent/child fork
4+
threads.
5+
(linux_wait_1): Unlink them.
6+
(linux_set_resume_request): Ignore resume requests for
7+
already-resumed and unhandled fork child threads.
8+
* linux-low.h (struct lwp_info) <fork_relative>: New field.
9+
* server.c (in_queued_stop_replies_ptid, in_queued_stop_replies):
10+
New functions.
11+
(handle_v_requests) <vCont>: Don't call require_running.
12+
* server.h (in_queued_stop_replies): New declaration.
13+
114
2016-10-24 Yao Qi <[email protected]>
215

316
PR server/20733

gdb/gdbserver/linux-low.c

+59
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
589589
event_lwp->status_pending_p = 1;
590590
event_lwp->status_pending = wstat;
591591

592+
/* Link the threads until the parent event is passed on to
593+
higher layers. */
594+
event_lwp->fork_relative = child_lwp;
595+
child_lwp->fork_relative = event_lwp;
596+
592597
/* If the parent thread is doing step-over with single-step
593598
breakpoints, the list of single-step breakpoints are cloned
594599
from the parent's. Remove them from the child process.
@@ -3853,6 +3858,15 @@ linux_wait_1 (ptid_t ptid,
38533858
{
38543859
/* If the reported event is an exit, fork, vfork or exec, let
38553860
GDB know. */
3861+
3862+
/* Break the unreported fork relationship chain. */
3863+
if (event_child->waitstatus.kind == TARGET_WAITKIND_FORKED
3864+
|| event_child->waitstatus.kind == TARGET_WAITKIND_VFORKED)
3865+
{
3866+
event_child->fork_relative->fork_relative = NULL;
3867+
event_child->fork_relative = NULL;
3868+
}
3869+
38563870
*ourstatus = event_child->waitstatus;
38573871
/* Clear the event lwp's waitstatus since we handled it already. */
38583872
event_child->waitstatus.kind = TARGET_WAITKIND_IGNORE;
@@ -4654,6 +4668,51 @@ linux_set_resume_request (struct inferior_list_entry *entry, void *arg)
46544668
continue;
46554669
}
46564670

4671+
/* Ignore (wildcard) resume requests for already-resumed
4672+
threads. */
4673+
if (r->resume[ndx].kind != resume_stop
4674+
&& thread->last_resume_kind != resume_stop)
4675+
{
4676+
if (debug_threads)
4677+
debug_printf ("already %s LWP %ld at GDB's request\n",
4678+
(thread->last_resume_kind
4679+
== resume_step)
4680+
? "stepping"
4681+
: "continuing",
4682+
lwpid_of (thread));
4683+
continue;
4684+
}
4685+
4686+
/* Don't let wildcard resumes resume fork children that GDB
4687+
does not yet know are new fork children. */
4688+
if (lwp->fork_relative != NULL)
4689+
{
4690+
struct inferior_list_entry *inf, *tmp;
4691+
struct lwp_info *rel = lwp->fork_relative;
4692+
4693+
if (rel->status_pending_p
4694+
&& (rel->waitstatus.kind == TARGET_WAITKIND_FORKED
4695+
|| rel->waitstatus.kind == TARGET_WAITKIND_VFORKED))
4696+
{
4697+
if (debug_threads)
4698+
debug_printf ("not resuming LWP %ld: has queued stop reply\n",
4699+
lwpid_of (thread));
4700+
continue;
4701+
}
4702+
}
4703+
4704+
/* If the thread has a pending event that has already been
4705+
reported to GDBserver core, but GDB has not pulled the
4706+
event out of the vStopped queue yet, likewise, ignore the
4707+
(wildcard) resume request. */
4708+
if (in_queued_stop_replies (entry->id))
4709+
{
4710+
if (debug_threads)
4711+
debug_printf ("not resuming LWP %ld: has queued stop reply\n",
4712+
lwpid_of (thread));
4713+
continue;
4714+
}
4715+
46574716
lwp->resume = &r->resume[ndx];
46584717
thread->last_resume_kind = lwp->resume->kind;
46594718

gdb/gdbserver/linux-low.h

+6
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ struct lwp_info
301301
information or exit status until it can be reported to GDB. */
302302
struct target_waitstatus waitstatus;
303303

304+
/* A pointer to the fork child/parent relative. Valid only while
305+
the parent fork event is not reported to higher layers. Used to
306+
avoid wildcard vCont actions resuming a fork child before GDB is
307+
notified about the parent's fork event. */
308+
struct lwp_info *fork_relative;
309+
304310
/* When stopped is set, this is where the lwp last stopped, with
305311
decr_pc_after_break already accounted for. If the LWP is
306312
running, this is the address at which the lwp was resumed. */

gdb/gdbserver/server.c

+32-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,38 @@ vstop_notif_reply (struct notif_event *event, char *own_buf)
193193
prepare_resume_reply (own_buf, vstop->ptid, &vstop->status);
194194
}
195195

196+
/* QUEUE_iterate callback helper for in_queued_stop_replies. */
197+
198+
static int
199+
in_queued_stop_replies_ptid (QUEUE (notif_event_p) *q,
200+
QUEUE_ITER (notif_event_p) *iter,
201+
struct notif_event *event,
202+
void *data)
203+
{
204+
ptid_t filter_ptid = *(ptid_t *) data;
205+
struct vstop_notif *vstop_event = (struct vstop_notif *) event;
206+
207+
if (ptid_match (vstop_event->ptid, filter_ptid))
208+
return 0;
209+
210+
/* Don't resume fork children that GDB does not know about yet. */
211+
if ((vstop_event->status.kind == TARGET_WAITKIND_FORKED
212+
|| vstop_event->status.kind == TARGET_WAITKIND_VFORKED)
213+
&& ptid_match (vstop_event->status.value.related_pid, filter_ptid))
214+
return 0;
215+
216+
return 1;
217+
}
218+
219+
/* See server.h. */
220+
221+
int
222+
in_queued_stop_replies (ptid_t ptid)
223+
{
224+
return !QUEUE_iterate (notif_event_p, notif_stop.queue,
225+
in_queued_stop_replies_ptid, &ptid);
226+
}
227+
196228
struct notif_server notif_stop =
197229
{
198230
"vStopped", "Stop", NULL, vstop_notif_reply,
@@ -2947,7 +2979,6 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
29472979

29482980
if (startswith (own_buf, "vCont;"))
29492981
{
2950-
require_running (own_buf);
29512982
handle_v_cont (own_buf);
29522983
return;
29532984
}

gdb/gdbserver/server.h

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ extern int handle_target_event (int err, gdb_client_data client_data);
123123
/* Get rid of the currently pending stop replies that match PTID. */
124124
extern void discard_queued_stop_replies (ptid_t ptid);
125125

126+
/* Returns true if there's a pending stop reply that matches PTID in
127+
the vStopped notifications queue. */
128+
extern int in_queued_stop_replies (ptid_t ptid);
129+
126130
#include "remote-utils.h"
127131

128132
#include "utils.h"

0 commit comments

Comments
 (0)