This is an archive of the discontinued LLVM Phabricator instance.

[LLGS] Get rid of the stdio forwarding thread
ClosedPublic

Authored by labath on Jul 17 2015, 7:18 AM.

Details

Summary

This commit removes the stdio forwarding thread in lldb-server in favor of a MainLoop callback.
As in some situations we need to forcibly flush the stream ( => Read() is called from multiple
places) and we still have multiple threads, I have had to additionally protect the communication
instance with a mutex.

Diff Detail

Repository
rL LLVM

Event Timeline

labath updated this revision to Diff 30001.Jul 17 2015, 7:18 AM
labath retitled this revision from to [LLGS] Get rid of the stdio forwarding thread.
labath updated this object.
labath added reviewers: ovyalov, tberghammer.
labath added a subscriber: lldb-commits.
ovyalov edited edge metadata.Jul 19 2015, 3:05 PM

Please see my comments.

source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
940 ↗(On Diff #30001)

m_stdio_communication.Disconnect() ?

967 ↗(On Diff #30001)

If SendProcessOutput is called from ProcessStateChanged within Monitor thread context we may have a race here:

  • simultaneous access to m_stdio_handle_up from main & monitor threads.
  • MainLoop will be accessed from multiple threads because UnregisterReadObject is called from monitor.
labath added inline comments.Jul 20 2015, 9:53 AM
source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
940 ↗(On Diff #30001)

Added. Note that this will probably send a SIGHUP to the inferior. However, at this point, I don't think we care about that.

967 ↗(On Diff #30001)

Nice catch. For the first problem, I propose to extend the scope of the m_stdio_communication_mutex to cover m_stdio_handle_up as well (most of the uses are covered by it already). For the second issue, I will prepare a separate change to make MainLoop thread-safe.

labath updated this revision to Diff 30166.Jul 20 2015, 9:53 AM
labath edited edge metadata.
  • Address review comments.
ovyalov accepted this revision.Jul 20 2015, 10:16 AM
ovyalov edited edge metadata.
ovyalov added inline comments.
source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
970 ↗(On Diff #30166)

If eventually lldb-server will be fully single-threaded then then it's ok to keep MainLoop as-is - since anyway monitor will be part of main thread.

1065 ↗(On Diff #30166)

You may wrap it up into a separate function since there are 2 usages of such code.

This revision is now accepted and ready to land.Jul 20 2015, 10:16 AM
This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.Jul 21 2015, 6:23 AM
labath added inline comments.
source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
970 ↗(On Diff #30166)

I have committed this with the (previously reverted) commit which removes NativeProcessLinux monitor thread. This makes lldb-server single threaded.