[lldb-dev] Process::SyncIOHandler(), everyone please try out the following patch

Ryan Brown ribrdb at google.com
Wed May 20 15:04:01 PDT 2015


I just noticed a couple tsan warning when using your patch in an
interactive session. It's not obvious to me if these are real issues or not:

==================
WARNING: ThreadSanitizer: data race (pid=42951)
  Write of size 1 at 0x7d44000046b0 by thread T6:
    #0 lldb_private::IOHandler::SetIsDone(bool)
../tools/lldb/include/lldb/Core/IOHandler.h:95
(liblldb.so.3.7+0x0000019d0861)
    #1 lldb_private::Process::PushProcessIOHandler()
../tools/lldb/source/Target/Process.cpp:5258 (liblldb.so.3.7+0x000001c1848c)
    #2
lldb_private::Process::HandlePrivateEvent(std::shared_ptr<lldb_private::Event>&)
../tools/lldb/source/Target/Process.cpp:4432 (liblldb.so.3.7+0x000001c15421)
    #3 lldb_private::Process::RunPrivateStateThread()
../tools/lldb/source/Target/Process.cpp:4573 (liblldb.so.3.7+0x000001c1875d)
    #4 lldb_private::Process::PrivateStateThread(void*)
../tools/lldb/source/Target/Process.cpp:4496 (liblldb.so.3.7+0x000001c180e1)
    #5 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*)
../tools/lldb/source/Host/common/HostNativeThreadBase.cpp:86
(liblldb.so.3.7+0x0000019855e9)

  Previous write of size 1 at 0x7d44000046b0 by main thread:
    #0 lldb_private::IOHandler::SetIsDone(bool)
../tools/lldb/include/lldb/Core/IOHandler.h:95
(liblldb.so.3.7+0x0000019d0861)
    #1 IOHandlerProcessSTDIO::Run()
../tools/lldb/source/Target/Process.cpp:5088 (liblldb.so.3.7+0x000001c292c7)
    #2 lldb_private::Debugger::ExecuteIOHandlers()
../tools/lldb/source/Core/Debugger.cpp:901 (liblldb.so.3.7+0x0000019a6bcc)
    #3 lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool,
lldb_private::CommandInterpreterRunOptions&)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3234
(liblldb.so.3.7+0x000001b0481f)
    #4 lldb::SBDebugger::RunCommandInterpreter(bool, bool)
../tools/lldb/source/API/SBDebugger.cpp:980 (liblldb.so.3.7+0x000000be61fb)
    #5 Driver::MainLoop() ../tools/lldb/tools/driver/Driver.cpp:1152
(lldb-3.7.0+0x0000000bd9d2)
    #6 main ../tools/lldb/tools/driver/Driver.cpp:1252
(lldb-3.7.0+0x0000000bdfae)

  Location is heap block of size 304 at 0x7d4400004600 allocated by main
thread:
    #0 operator new(unsigned long) <null>:0 (lldb-3.7.0+0x00000005459d)
    #1 lldb_private::Process::SetSTDIOFileDescriptor(int)
../tools/lldb/source/Target/Process.cpp:5235 (liblldb.so.3.7+0x000001c19957)
    #2
lldb_private::platform_linux::PlatformLinux::DebugProcess(lldb_private::ProcessLaunchInfo&,
lldb_private::Debugger&, lldb_private::Target*, lldb_private::Error&)
../tools/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp:831
(liblldb.so.3.7+0x000001d94710)
    #3 lldb_private::Target::Launch(lldb_private::ProcessLaunchInfo&,
lldb_private::Stream*) ../tools/lldb/source/Target/Target.cpp:2602
(liblldb.so.3.7+0x000001c53197)
    #4 CommandObjectProcessLaunch::DoExecute(lldb_private::Args&,
lldb_private::CommandReturnObject&)
../tools/lldb/source/Commands/CommandObjectProcess.cpp:263
(liblldb.so.3.7+0x000001eb1b69)
    #5 lldb_private::CommandObjectParsed::Execute(char const*,
lldb_private::CommandReturnObject&)
../tools/lldb/source/Interpreter/CommandObject.cpp:1075
(liblldb.so.3.7+0x000001b0ef76)
    #6 lldb_private::CommandInterpreter::HandleCommand(char const*,
lldb_private::LazyBool, lldb_private::CommandReturnObject&,
lldb_private::ExecutionContext*, bool, bool)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:1812
(liblldb.so.3.7+0x000001b00e4a)
    #7
lldb_private::CommandInterpreter::IOHandlerInputComplete(lldb_private::IOHandler&,
std::string&) ../tools/lldb/source/Interpreter/CommandInterpreter.cpp:2997
(liblldb.so.3.7+0x000001b03e5b)
    #8 non-virtual thunk to
lldb_private::CommandInterpreter::IOHandlerInputComplete(lldb_private::IOHandler&,
std::string&) ../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3076
(liblldb.so.3.7+0x000001b04230)
    #9 lldb_private::IOHandlerEditline::Run()
../tools/lldb/source/Core/IOHandler.cpp:740 (liblldb.so.3.7+0x0000019cac7c)
    #10 lldb_private::Debugger::ExecuteIOHandlers()
../tools/lldb/source/Core/Debugger.cpp:901 (liblldb.so.3.7+0x0000019a6bcc)
    #11 lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool,
lldb_private::CommandInterpreterRunOptions&)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3234
(liblldb.so.3.7+0x000001b0481f)
    #12 lldb::SBDebugger::RunCommandInterpreter(bool, bool)
../tools/lldb/source/API/SBDebugger.cpp:980 (liblldb.so.3.7+0x000000be61fb)
    #13 Driver::MainLoop() ../tools/lldb/tools/driver/Driver.cpp:1152
(lldb-3.7.0+0x0000000bd9d2)
    #14 main ../tools/lldb/tools/driver/Driver.cpp:1252
(lldb-3.7.0+0x0000000bdfae)

  Thread T6 'intern-state' (tid=42969, running) created by main thread at:
    #0 pthread_create <null>:0 (lldb-3.7.0+0x0000000578a1)
    #1 lldb_private::ThreadLauncher::LaunchThread(llvm::StringRef, void*
(*)(void*), void*, lldb_private::Error*, unsigned long)
../tools/lldb/source/Host/common/ThreadLauncher.cpp:71
(liblldb.so.3.7+0x00000197ab14)
    #2 lldb_private::Process::StartPrivateStateThread(bool)
../tools/lldb/source/Target/Process.cpp:4266 (liblldb.so.3.7+0x000001c15cb3)
    #3 lldb_private::Process::Launch(lldb_private::ProcessLaunchInfo&)
../tools/lldb/source/Target/Process.cpp:3182 (liblldb.so.3.7+0x000001c15a48)
    #4
lldb_private::platform_linux::PlatformLinux::DebugProcess(lldb_private::ProcessLaunchInfo&,
lldb_private::Debugger&, lldb_private::Target*, lldb_private::Error&)
../tools/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp:805
(liblldb.so.3.7+0x000001d943bb)
    #5 lldb_private::Target::Launch(lldb_private::ProcessLaunchInfo&,
lldb_private::Stream*) ../tools/lldb/source/Target/Target.cpp:2602
(liblldb.so.3.7+0x000001c53197)
    #6 CommandObjectProcessLaunch::DoExecute(lldb_private::Args&,
lldb_private::CommandReturnObject&)
../tools/lldb/source/Commands/CommandObjectProcess.cpp:263
(liblldb.so.3.7+0x000001eb1b69)
    #7 lldb_private::CommandObjectParsed::Execute(char const*,
lldb_private::CommandReturnObject&)
../tools/lldb/source/Interpreter/CommandObject.cpp:1075
(liblldb.so.3.7+0x000001b0ef76)
    #8 lldb_private::CommandInterpreter::HandleCommand(char const*,
lldb_private::LazyBool, lldb_private::CommandReturnObject&,
lldb_private::ExecutionContext*, bool, bool)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:1812
(liblldb.so.3.7+0x000001b00e4a)
    #9
lldb_private::CommandInterpreter::IOHandlerInputComplete(lldb_private::IOHandler&,
std::string&) ../tools/lldb/source/Interpreter/CommandInterpreter.cpp:2997
(liblldb.so.3.7+0x000001b03e5b)
    #10 non-virtual thunk to
lldb_private::CommandInterpreter::IOHandlerInputComplete(lldb_private::IOHandler&,
std::string&) ../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3076
(liblldb.so.3.7+0x000001b04230)
    #11 lldb_private::IOHandlerEditline::Run()
../tools/lldb/source/Core/IOHandler.cpp:740 (liblldb.so.3.7+0x0000019cac7c)
    #12 lldb_private::Debugger::ExecuteIOHandlers()
../tools/lldb/source/Core/Debugger.cpp:901 (liblldb.so.3.7+0x0000019a6bcc)
    #13 lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool,
lldb_private::CommandInterpreterRunOptions&)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3234
(liblldb.so.3.7+0x000001b0481f)
    #14 lldb::SBDebugger::RunCommandInterpreter(bool, bool)
../tools/lldb/source/API/SBDebugger.cpp:980 (liblldb.so.3.7+0x000000be61fb)
    #15 Driver::MainLoop() ../tools/lldb/tools/driver/Driver.cpp:1152
(lldb-3.7.0+0x0000000bd9d2)
    #16 main ../tools/lldb/tools/driver/Driver.cpp:1252
(lldb-3.7.0+0x0000000bdfae)

SUMMARY: ThreadSanitizer: data race
../tools/lldb/include/lldb/Core/IOHandler.h:95
lldb_private::IOHandler::SetIsDone(bool)
==================
Process 42968 stopped
* thread #1: tid = 42968, 0x00007ffff81db89a helloserver`main.main + 26 at
helloserver.go:26, name = 'helloserver', stop reason = breakpoint 1.1
    frame #0: 0x00007ffff81db89a helloserver`main.main + 26 at
helloserver.go:26
==================
WARNING: ThreadSanitizer: data race (pid=42951)
  Read of size 8 at 0x7da0000080c0 by thread T2 (mutexes: write M171):
    #0 write <null>:0 (lldb-3.7.0+0x0000000649c0)
    #1 operator() ../tools/lldb/source/Host/posix/PipePosix.cpp:416
(liblldb.so.3.7+0x000001982201)
    #2 std::_Function_handler<lldb_private::Error (bool&),
lldb_private::PipePosix::Write(void const*, unsigned long, unsigned
long&)::$_1>::_M_invoke(std::_Any_data const&, bool&)
/usr/include/c++/4.8/functional:2056 (liblldb.so.3.7+0x000001981f9c)
    #3 std::function<lldb_private::Error (bool&)>::operator()(bool&) const
/usr/include/c++/4.8/functional:2464 (liblldb.so.3.7+0x000001983329)
    #4 (anonymous namespace)::SelectIO(int, bool,
std::function<lldb_private::Error (bool&)> const&,
std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)
../tools/lldb/source/Host/posix/PipePosix.cpp:118
(liblldb.so.3.7+0x000001981c47)
    #5 lldb_private::PipePosix::Write(void const*, unsigned long, unsigned
long&) ../tools/lldb/source/Host/posix/PipePosix.cpp:411
(liblldb.so.3.7+0x000001981e43)
    #6 IOHandlerProcessSTDIO::Cancel()
../tools/lldb/source/Target/Process.cpp:5167 (liblldb.so.3.7+0x000001c297da)
    #7
lldb_private::Debugger::PopIOHandler(std::shared_ptr<lldb_private::IOHandler>
const&) ../tools/lldb/source/Core/Debugger.cpp:1071
(liblldb.so.3.7+0x0000019a6add)
    #8 lldb_private::Process::PopProcessIOHandler()
../tools/lldb/source/Target/Process.cpp:5270 (liblldb.so.3.7+0x000001c106f9)
    #9
lldb_private::Debugger::HandleProcessEvent(std::shared_ptr<lldb_private::Event>
const&) ../tools/lldb/source/Core/Debugger.cpp:1517
(liblldb.so.3.7+0x0000019a8303)
    #10 lldb_private::Debugger::DefaultEventHandler()
../tools/lldb/source/Core/Debugger.cpp:1604 (liblldb.so.3.7+0x0000019a869e)
    #11 lldb_private::Debugger::EventHandlerThread(void*)
../tools/lldb/source/Core/Debugger.cpp:1662 (liblldb.so.3.7+0x0000019a88c9)
    #12 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*)
../tools/lldb/source/Host/common/HostNativeThreadBase.cpp:86
(liblldb.so.3.7+0x0000019855e9)

  Previous write of size 8 at 0x7da0000080c0 by main thread:
    #0 pipe2 <null>:0 (lldb-3.7.0+0x00000005f6c0)
    #1 lldb_private::PipePosix::CreateNew(bool)
../tools/lldb/source/Host/posix/PipePosix.cpp:168
(liblldb.so.3.7+0x000001980cc4)
    #2 IOHandlerProcessSTDIO::OpenPipes()
../tools/lldb/source/Target/Process.cpp:5070 (liblldb.so.3.7+0x000001c2994b)
    #3 IOHandlerProcessSTDIO::Run()
../tools/lldb/source/Target/Process.cpp:5089 (liblldb.so.3.7+0x000001c292cf)
    #4 lldb_private::Debugger::ExecuteIOHandlers()
../tools/lldb/source/Core/Debugger.cpp:901 (liblldb.so.3.7+0x0000019a6bcc)
    #5 lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool,
lldb_private::CommandInterpreterRunOptions&)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3234
(liblldb.so.3.7+0x000001b0481f)
    #6 lldb::SBDebugger::RunCommandInterpreter(bool, bool)
../tools/lldb/source/API/SBDebugger.cpp:980 (liblldb.so.3.7+0x000000be61fb)
    #7 Driver::MainLoop() ../tools/lldb/tools/driver/Driver.cpp:1152
(lldb-3.7.0+0x0000000bd9d2)
    #8 main ../tools/lldb/tools/driver/Driver.cpp:1252
(lldb-3.7.0+0x0000000bdfae)

  Location is file descriptor 12 created by main thread at:
    #0 pipe2 <null>:0 (lldb-3.7.0+0x00000005f6c0)
    #1 lldb_private::PipePosix::CreateNew(bool)
../tools/lldb/source/Host/posix/PipePosix.cpp:168
(liblldb.so.3.7+0x000001980cc4)
    #2 IOHandlerProcessSTDIO::OpenPipes()
../tools/lldb/source/Target/Process.cpp:5070 (liblldb.so.3.7+0x000001c2994b)
    #3 IOHandlerProcessSTDIO::Run()
../tools/lldb/source/Target/Process.cpp:5089 (liblldb.so.3.7+0x000001c292cf)
    #4 lldb_private::Debugger::ExecuteIOHandlers()
../tools/lldb/source/Core/Debugger.cpp:901 (liblldb.so.3.7+0x0000019a6bcc)
    #5 lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool,
lldb_private::CommandInterpreterRunOptions&)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3234
(liblldb.so.3.7+0x000001b0481f)
    #6 lldb::SBDebugger::RunCommandInterpreter(bool, bool)
../tools/lldb/source/API/SBDebugger.cpp:980 (liblldb.so.3.7+0x000000be61fb)
    #7 Driver::MainLoop() ../tools/lldb/tools/driver/Driver.cpp:1152
(lldb-3.7.0+0x0000000bd9d2)
    #8 main ../tools/lldb/tools/driver/Driver.cpp:1252
(lldb-3.7.0+0x0000000bdfae)

  Mutex M171 (0x7d680001cbc8) created at:
    #0 pthread_mutex_init <null>:0 (lldb-3.7.0+0x000000058cb0)
    #1 Mutex ../tools/lldb/source/Host/common/Mutex.cpp:237
(liblldb.so.3.7+0x000001977f1a)
    #2 IOHandlerStack ../tools/lldb/include/lldb/Core/IOHandler.h:716
(liblldb.so.3.7+0x0000019a97d7)
    #3 Debugger ../tools/lldb/source/Core/Debugger.cpp:670
(liblldb.so.3.7+0x0000019a5bf4)
    #4 lldb_private::Debugger::CreateInstance(void (*)(char const*, void*),
void*) ../tools/lldb/source/Core/Debugger.cpp:557
(liblldb.so.3.7+0x0000019a52cb)
    #5 lldb::SBDebugger::Create(bool, void (*)(char const*, void*), void*)
../tools/lldb/source/API/SBDebugger.cpp:177 (liblldb.so.3.7+0x000000be3f37)
    #6 lldb::SBDebugger::Create(bool)
../tools/lldb/source/API/SBDebugger.cpp:158 (liblldb.so.3.7+0x000000be4085)
    #7 Driver ../tools/lldb/tools/driver/Driver.cpp:142
(lldb-3.7.0+0x0000000bb369)
    #8 main ../tools/lldb/tools/driver/Driver.cpp:1240
(lldb-3.7.0+0x0000000bdf05)

  Thread T2 'event-handler' (tid=42957, running) created by main thread at:
    #0 pthread_create <null>:0 (lldb-3.7.0+0x0000000578a1)
    #1 lldb_private::ThreadLauncher::LaunchThread(llvm::StringRef, void*
(*)(void*), void*, lldb_private::Error*, unsigned long)
../tools/lldb/source/Host/common/ThreadLauncher.cpp:71
(liblldb.so.3.7+0x00000197ab87)
    #2 lldb_private::Debugger::StartEventHandlerThread()
../tools/lldb/source/Core/Debugger.cpp:1679 (liblldb.so.3.7+0x0000019a899e)
    #3 lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool,
lldb_private::CommandInterpreterRunOptions&)
../tools/lldb/source/Interpreter/CommandInterpreter.cpp:3226
(liblldb.so.3.7+0x000001b04800)
    #4 lldb::SBDebugger::RunCommandInterpreter(bool, bool)
../tools/lldb/source/API/SBDebugger.cpp:980 (liblldb.so.3.7+0x000000be61fb)
    #5 Driver::MainLoop() ../tools/lldb/tools/driver/Driver.cpp:1152
(lldb-3.7.0+0x0000000bd9d2)
    #6 main ../tools/lldb/tools/driver/Driver.cpp:1252
(lldb-3.7.0+0x0000000bdfae)

SUMMARY: ThreadSanitizer: data race ??:0 write
==================

-- Ryan Brown

On Mon, May 18, 2015 at 6:22 AM, Pavel Labath <labath at google.com> wrote:

> BTW, the patch I mention is here <http://reviews.llvm.org/D9823>.
>
> On 18 May 2015 at 13:29, Pavel Labath <labath at google.com> wrote:
> > Hello everyone,
> >
> > I have made a new patch to attempt to solve this issue. It is
> > basically a combination of two of the approaches posted here by Greg:
> > fix SyncIOHandler so it doesn't hang and pipe all asynchronous output
> > through the current IOHandler. I have added some synchronization there
> > to avoid some of the races I have found. Could you please test it
> > again and see if it works for you.
> >
> > regards,
> > pl
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20150520/f298015f/attachment.html>


More information about the lldb-dev mailing list