This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix data race in Process
ClosedPublic

Authored by augusto2112 on Aug 10 2023, 1:20 PM.

Details

Summary

Thread sanitizer reports a data race in Process.cpp in the usage of
m_process_input_reader. Fix this data race by introducing a mutex
guarding the access to this variable.

Diff Detail

Event Timeline

augusto2112 created this revision.Aug 10 2023, 1:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2023, 1:20 PM
augusto2112 requested review of this revision.Aug 10 2023, 1:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2023, 1:20 PM
bulbazord accepted this revision.Aug 10 2023, 2:08 PM
This revision is now accepted and ready to land.Aug 10 2023, 2:08 PM

Is the reported race specifically about the shared pointer being accessed concurrently or operations on the IOHandler?

Is the reported race specifically about the shared pointer being accessed concurrently or operations on the IOHandler?

I believe it's the shared pointer being accessed. Here's an example of what's being reported:

WARNING: ThreadSanitizer: data race (pid=52249)
  Read of size 8 at 0x00010731ce38 by thread T3:
    #0 lldb_private::Process::PopProcessIOHandler() Process.cpp:4559 (liblldb.18.0.0git.dylib:arm64+0x53a5a4) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #1 lldb_private::Process::HandlePrivateEvent(std::__1::shared_ptr<lldb_private::Event>&) Process.cpp:3775 (liblldb.18.0.0git.dylib:arm64+0x54204c) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #2 lldb_private::Process::RunPrivateStateThread(bool) Process.cpp:3904 (liblldb.18.0.0git.dylib:arm64+0x54874c) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #3 std::__1::__function::__func<lldb_private::Process::StartPrivateStateThread(bool)::$_5, std::__1::allocator<lldb_private::Process::StartPrivateStateThread(bool)::$_5>, void* ()>::operator()() function.h:356 (liblldb.18.0.0git.dylib:arm64+0x555de4) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #4 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) HostNativeThreadBase.cpp:62 (liblldb.18.0.0git.dylib:arm64+0x3e83fc) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #5 lldb_private::HostThreadMacOSX::ThreadCreateTrampoline(void*) HostThreadMacOSX.mm:18 (liblldb.18.0.0git.dylib:arm64+0x175056c) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)

  Previous write of size 8 at 0x00010731ce38 by main thread (mutexes: write M0):
    #0 lldb_private::Process::SetSTDIOFileDescriptor(int) Process.cpp:4528 (liblldb.18.0.0git.dylib:arm64+0x54aa5c) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #1 lldb_private::Platform::DebugProcess(lldb_private::ProcessLaunchInfo&, lldb_private::Debugger&, lldb_private::Target&, lldb_private::Status&) Platform.cpp:1120 (liblldb.18.0.0git.dylib:arm64+0x52bc54) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #2 lldb_private::PlatformDarwin::DebugProcess(lldb_private::ProcessLaunchInfo&, lldb_private::Debugger&, lldb_private::Target&, lldb_private::Status&) PlatformDarwin.cpp:711 (liblldb.18.0.0git.dylib:arm64+0x872cc8) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)
    #3 lldb_private::Target::Launch(lldb_private::ProcessLaunchInfo&, lldb_private::Stream*) Target.cpp:3235 (liblldb.18.0.0git.dylib:arm64+0x5b118c) (BuildId: 6e77321523b936d2955d63d4d25df7cd32000000200000000100000000000e00)

Line 4559 is

IOHandlerSP io_handler_sp(m_process_input_reader);

Line 4528 is

m_process_input_reader =
    std::make_shared<IOHandlerProcessSTDIO>(this, fd);

@JDevlieghere do you have any opinions on this?

This revision was automatically updated to reflect the committed changes.