[PATCH] D47609: [lldb, process] Fix occasional hang when launching a process in LLDB

Stella Stamenova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 31 15:45:38 PDT 2018


stella.stamenova created this revision.
stella.stamenova added reviewers: asmith, labath, zturner.
Herald added a subscriber: llvm-commits.

Occasionally, when launching a process in lldb (especially on windows, but not limited to), lldb will hang before the process is launched and it will never recover. This happens because the timing of the processing of the state changes can be slightly different. The state changes that are issued are:

1. SetPublicState(eStateLaunching)
2. SetPrivateState(eStateLaunching)
3. SetPublicState(eStateStopped)
4. SetPrivateState(eStateStopped)

What we expect to see is:
public state: launching -> launching -> stopped
private state: launching -> stopped

What we see is:
public state: launching -> stopped -> launching
private state: launching -> stopped

The second launching change to the public state is issued when WaitForProcessStopPrivate calls HandlePrivateEvent on the event which was created when the private state was set to launching. HandlePrivateEvent has logic to determine whether to broadcase the event and a launching event is *always* broadcast. At the same time, when the stopped event is processed by WaitForProcessStopPrivate next, the function exists and that event is never broadcast, so the public state remains as launching.

HandlePrivateEvent does two things: determine whether there's a next action as well as determine whether to broadcast the event that was processed. There's only ever a next action set if we are trying to attach to a process, but WaitForProcessStopPrivate is only ever called when we are launching a process or connecting remotely, so the first part of HandlePrivateEvent (handling the next action) is irrelevant for WaitForProcessStopPrivate. As far as broadcasting the event is concerned, since we are handling state changes that already occurred to the public state (and are now duplicated in the private state), I believe the broadcast step is unnecessary also (and in fact, it causes the hang).

This change removes the call to HandlePrivateEvent from inside WaitForProcessStopPrivate.

Incidentally, there was also a bug filed recently that is the same issue: https://bugs.llvm.org/show_bug.cgi?id=37496


Repository:
  rL LLVM

https://reviews.llvm.org/D47609

Files:
  source/Target/Process.cpp


Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -2700,9 +2700,6 @@
     // If state is invalid, then we timed out
     if (state == eStateInvalid)
       break;
-
-    if (event_sp)
-      HandlePrivateEvent(event_sp);
   }
   return state;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47609.149375.patch
Type: text/x-patch
Size: 360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180531/331384b4/attachment.bin>


More information about the llvm-commits mailing list