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

Greg Clayton gclayton at apple.com
Mon Apr 6 13:37:37 PDT 2015


We had some race conditions in the past where you would type:

(lldb) continue

And you might get a "(lldb) " prompt that came out before and intermingled with the process STDIO. To fix this we sync with the process IOHandler using: Process::SyncIOHandler(2000) in a two places: "process continue" and all "thread step ..." commands. The problem is Process::SyncIOHandler() does the following:

bool
Process::SyncIOHandler (uint64_t timeout_msec)
{
    bool timed_out = false;

    // don't sync (potentially context switch) in case where there is no process IO
    if (m_process_input_reader)
    {
        TimeValue timeout = TimeValue::Now();
        timeout.OffsetWithMicroSeconds(timeout_msec*1000);
        m_iohandler_sync.WaitForValueEqualTo(true, &timeout, &timed_out);
        m_iohandler_sync.SetValue(false, eBroadcastNever);
    }
    return !timed_out;
}


And then in a background thread that handles the internal process events, we modify m_iohandler_sync:


void
Process::HandlePrivateEvent()
{
    ...
    if (StateIsRunningState (new_state))
    {
        if (!GetTarget().GetDebugger().IsForwardingEvents() && new_state != eStateLaunching)
            PushProcessIOHandler ();
        m_iohandler_sync.SetValue(true, eBroadcastAlways);
    }
    else if (StateIsStoppedState(new_state, false))
    {
        m_iohandler_sync.SetValue(false, eBroadcastNever);
    ...

    }
    ...
}

        

The problem is that if the background thread is able to handle the running state followed by a stopped state, it might set the value to true and then back to false again before the main thread calls Process::SyncIOHandler() and then the main thread waits for 2 seconds.

The solution seems simple: remove the m_iohandler_sync.SetValue(false, eBroadcastNever); from the StateIsStoppedState else clause in Process::HandlePrivateEvent() since the Process::SyncIOHandler() always sets it to false. Can everyone try and apply the following patch and run your test suite and also use LLDB for a while?

% svn diff
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp	(revision 234201)
+++ source/Target/Process.cpp	(working copy)
@@ -4439,7 +4439,7 @@
         }
         else if (StateIsStoppedState(new_state, false))
         {
-            m_iohandler_sync.SetValue(false, eBroadcastNever);
+            //m_iohandler_sync.SetValue(false, eBroadcastNever);
             if (!Process::ProcessEventData::GetRestartedFromEvent(event_sp.get()))
             {
                 // If the lldb_private::Debugger is handling the events, we don't



This can tell us if this will work for folks and not slow down the test suite when it runs "continue" from through self.runCmd(). You can see how much slower the test suite can run by running the benchmark:

cd lldb/test
./dotest.py +b -t -v benchmarks/continue/


Then search for "lldbutil:" and you will see each self.runCmd("continue") takes 2 seconds. This could really speed up our test suite if we can get this fix in.







More information about the lldb-dev mailing list