Skip to content

Commit

Permalink
Fix race condition in process resume
Browse files Browse the repository at this point in the history
Summary:
Gdb-remote's async thread sent out the eBroadcastBitRunPacketSent message *before* actually
sending out the continue packet. Since it's this message the actually triggers the public state
transition, it could happen (and it did happen in TestAttachResume, which does an "process
interrupt" right after a continue) that we attempt to stop the inferior before it was actually
started (which obviously did not end well). This fixes the problem by moving the broadcast after
the packet was actually sent.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D14083

llvm-svn: 251399
  • Loading branch information
labath committed Oct 27, 2015
1 parent 891c097 commit 9e131f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -1049,7 +1049,6 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
Mutex::Locker locker(m_sequence_mutex);
StateType state = eStateRunning;

BroadcastEvent(eBroadcastBitRunPacketSent, NULL);
m_public_is_running.SetValue (true, eBroadcastNever);
// Set the starting continue packet into "continue_packet". This packet
// may change if we are interrupted and we continue after an async packet...
Expand All @@ -1059,6 +1058,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
const auto sigint_signo = process->GetUnixSignals()->GetSignalNumberFromName("SIGINT");

bool got_async_packet = false;
bool broadcast_sent = false;

while (state == eStateRunning)
{
Expand All @@ -1071,6 +1071,12 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
else
m_interrupt_sent = false;

if (! broadcast_sent)
{
BroadcastEvent(eBroadcastBitRunPacketSent, NULL);
broadcast_sent = true;
}

m_private_is_running.SetValue (true, eBroadcastAlways);
}

Expand Down
Expand Up @@ -20,7 +20,6 @@ class AttachResumeTestCase(TestBase):
@skipIfRemote
@expectedFailureFreeBSD('llvm.org/pr19310')
@expectedFailureWindows("llvm.org/pr24778")
@expectedFlakeyLinux('llvm.org/pr19310')
def test_attach_continue_interrupt_detach(self):
"""Test attach/continue/interrupt/detach"""
self.build()
Expand Down

0 comments on commit 9e131f7

Please sign in to comment.