The IOHandlerProcessSTDIO is the _only_ IOHandler that gets pushed and popped from...
authorGreg Clayton <gclayton@apple.com>
Fri, 26 Feb 2016 17:36:44 +0000 (17:36 +0000)
committerGreg Clayton <gclayton@apple.com>
Fri, 26 Feb 2016 17:36:44 +0000 (17:36 +0000)
commit860582f78e3a59cfa939e53ec7886b63952eb751
treea24ca3376cf2f09841db11d481b0132b74ef43f7
parent9691d71674bdd49a90ffe490ee9617506162856d
The IOHandlerProcessSTDIO is the _only_ IOHandler that gets pushed and popped from functions that are run due to something that is NOT input from the user. All other IOHandler objects result from input from the user. An issue rose up where if a command caused the process to resume and stop and process state changed, where state changed Event objects were broadcast, it would cause the IOHandlerProcessSTDIO to have its IOHandlerProcessSTDIO::Cancel() function called. This used to always write a byte to the control pipe (IOHandlerProcessSTDIO::m_pipe) even if the IOHandlerProcessSTDIO::Run() was never called. What would happen is:

(lldb) command_that_steps_process_thousands_of_times

As the "command_that_steps_process_thousands_of_times" could be a python command that resumed the process thousands of times and in doing so the IOHandlerProcessSTDIO would get pushed when the process resumed, and popped when it stoppped, causing the call to IOHandlerProcessSTDIO::Cancel(). Since the IOHandler thread is currently in IOHandlerEditline::Run() for the command interpreter handling the "command_that_steps_process_thousands_of_times" command, IOHandlerProcessSTDIO::Run() would never get called, even though the IOHandlerProcessSTDIO is on the top of the stack. This caused the command pipe to keep getting 1 bytes written each time the IOHandlerProcessSTDIO::Cancel() was called and eventually we will deadlock since the write buffer is full.

The fix here is to make sure we are in IOHandlerProcessSTDIO::Run() before we write anything to the command pipe, and just call SetIsDone(true) if we are not.

<rdar://problem/22361364>

llvm-svn: 262040
lldb/source/Target/Process.cpp