John Baldwin e012fe34cb Discard the correct thread event reported for a ptrace stop.
When multiple threads wish to report a tracing event to a debugger,
both threads call ptracestop() and one thread will win the race to be
the reporting thread (p->p_xthread).  The debugger uses PT_LWPINFO
with the process ID to determine which thread / LWP is reporting an
event and the details of that event.  This event is cleared as a side
effect of the subsequent ptrace event that resumed the process
(PT_CONTINUE, PT_STEP, etc.).  However, ptrace() was clearing the
event identified by the LWP ID passed to the resume request even if
that wasn't the 'p_xthread'.  This could result in clearing an event
that had not yet been observed by the debugger and leaving the
existing event for 'p_thread' pending so that it was reported a second
time.

Specifically, if the debugger stopped due to a software breakpoint in
one thread, but then switched to another thread that was used to
resume (e.g. if the user switched to a different thread and issued a
step), the resume request (PT_STEP) cleared a pending event (if any)
for the thread being stepped.  However, the process immediately
stopped and the first thread reported it's breakpoint event a second
time.  The debugger decremented the PC for "both" breakpoint events
which resulted in the PC now pointing into the middle of an
instruction (on x86) and a SIGILL fault when the process was resumed a
second time.

To fix, always clear the pending event for 'p_xthread' when resuming a
process.  ptrace() still honors the requested LWP ID when enabling
single-stepping (PT_STEP) or setting a different PC (PT_CONTINUE).

Reported by:	GDB testsuite (gdb.threads/continue-pending-status.exp)
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D12794
2017-10-27 03:16:19 +00:00
..
2017-10-12 15:48:37 +00:00
2017-05-23 09:29:05 +00:00
2016-11-08 23:59:41 +00:00
2017-05-18 18:24:11 +00:00
2017-08-15 02:21:02 +00:00
2017-02-12 09:49:44 +00:00
2017-01-25 20:22:32 +00:00
2017-05-23 16:59:24 +00:00
2017-02-14 13:54:05 +00:00
2017-03-19 00:51:12 +00:00
2017-08-07 14:09:57 +00:00
2016-11-08 23:59:41 +00:00
2017-10-22 13:42:56 +00:00
2017-02-07 16:01:07 +00:00
2017-07-12 07:30:14 +00:00
2017-05-16 23:31:52 +00:00
2017-06-17 00:58:19 +00:00
2017-06-17 00:58:19 +00:00
2017-05-23 09:29:05 +00:00
2017-05-23 09:29:05 +00:00
2017-06-08 21:30:34 +00:00
2017-06-15 04:49:12 +00:00
2017-10-16 21:46:11 +00:00
2017-09-14 18:05:54 +00:00
2017-10-26 19:45:15 +00:00
2017-10-06 09:02:36 +00:00