Fix a race between lldb's packet timeout and the profile thread's usleep.
authorJim Ingham <jingham@apple.com>
Sat, 22 Feb 2020 00:45:29 +0000 (16:45 -0800)
committerJim Ingham <jingham@apple.com>
Tue, 25 Feb 2020 19:17:08 +0000 (11:17 -0800)
commit3cd13c4624b5900c884b691b72d0ca053433f6fe
tree3db2d214e4e6e047baf1d1af55e9811ab5081729
parent481b1c83802f730df5876d01ede2054a738ee37e
Fix a race between lldb's packet timeout and the profile thread's usleep.

The debugserver profile thread used to suspend itself between samples with
a usleep.  When you detach or kill, MachProcess::Clear would delay replying
to the incoming packet until pthread_join of the profile thread returned.
If you are unlucky or the suspend delay is long, it could take longer than
the packet timeout for pthread_join to return.  Then you would get an error
about detach not succeeding from lldb - even though in fact the detach was
successful...

I replaced the usleep with PThreadEvents entity.  Then we just call a timed
WaitForEventBits, and when debugserver wants to stop the profile thread, it
can set the event bit, and the sleep will exit immediately.

Differential Revision: https://reviews.llvm.org/D75004
lldb/test/API/macosx/profile_vrs_detach/Makefile [new file with mode: 0644]
lldb/test/API/macosx/profile_vrs_detach/TestDetachVrsProfile.py [new file with mode: 0644]
lldb/test/API/macosx/profile_vrs_detach/main.c [new file with mode: 0644]
lldb/tools/debugserver/source/MacOSX/MachProcess.h
lldb/tools/debugserver/source/MacOSX/MachProcess.mm