[Lldb-commits] [PATCH] D75004: Fix a race between lldb's packet timeout and killing the profile thread

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 21 17:06:42 PST 2020


jingham created this revision.
jingham added a reviewer: clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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.

Note, you have to get fairly unlucky because when lldb times out a packet it
then sends a qEcho, and tries to get back in sync.  That adds some extra delay
which might give the detach a chance to succeed.  I've had occasional mysterious 
reports of Detach failing like this - only under Xcode which is currently the only client
I know of of the profiling info for years, but didn't get to chasing it down till now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75004

Files:
  lldb/test/API/macosx/profile_vrs_detach/Makefile
  lldb/test/API/macosx/profile_vrs_detach/TestDetachVrsProfile.py
  lldb/test/API/macosx/profile_vrs_detach/main.c
  lldb/tools/debugserver/source/MacOSX/MachProcess.h
  lldb/tools/debugserver/source/MacOSX/MachProcess.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75004.246045.patch
Type: text/x-patch
Size: 8145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200222/2ccac6b6/attachment-0001.bin>


More information about the lldb-commits mailing list