[Lldb-commits] [lldb] r219412 - thread state coordinator: fixed bug in thread running state book-keeping.

Todd Fiala todd.fiala at gmail.com
Thu Oct 9 10:00:55 PDT 2014


Author: tfiala
Date: Thu Oct  9 12:00:55 2014
New Revision: 219412

URL: http://llvm.org/viewvc/llvm-project?rev=219412&view=rev
Log:
thread state coordinator: fixed bug in thread running state book-keeping.

Adds a test to verify that a thread resume request marks the thread as running
after doing the resume callback.  This test fails without the corresponding
ThreadStateCoordinator.cpp change.

Fixes the code where that state was not maintained.

Modified:
    lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
    lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp

Modified: lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp?rev=219412&r1=219411&r2=219412&view=diff
==============================================================================
--- lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp (original)
+++ lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp Thu Oct  9 12:00:55 2014
@@ -611,6 +611,47 @@ TEST_F (ThreadStateCoordinatorTest, Requ
     ASSERT_EQ (NEW_THREAD_TID, resumed_tid);
 }
 
+TEST_F (ThreadStateCoordinatorTest, RequestThreadResumeSkipsCallbackOnSecondResumeAttempt)
+{
+    // Initialize thread to be in stopped state.
+    SetupKnownStoppedThread (NEW_THREAD_TID);
+
+    // Request a resume.
+    lldb::tid_t resumed_tid = 0;
+    int resume_call_count = 0;
+
+    m_coordinator.RequestThreadResume (NEW_THREAD_TID,
+                                       [&](lldb::tid_t tid)
+                                       {
+                                           ++resume_call_count;
+                                           resumed_tid = tid;
+                                       },
+                                       GetErrorFunction ());
+    // Shouldn't be called yet.
+    ASSERT_EQ (0, resume_call_count);
+
+    // Process next event.  After that, the resume request call should have fired.
+    ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS ();
+    ASSERT_EQ (1, resume_call_count);
+    ASSERT_EQ (NEW_THREAD_TID, resumed_tid);
+
+    // Make a second resume request.
+    const int initial_resume_call_count = resume_call_count;
+    m_coordinator.RequestThreadResume (NEW_THREAD_TID,
+                                       [&](lldb::tid_t tid)
+                                       {
+                                           ++resume_call_count;
+                                           resumed_tid = tid;
+                                       },
+                                       GetErrorFunction ());
+
+    // Process next event.  This should fail since the thread should already be running.
+    ASSERT_PROCESS_NEXT_EVENT_FAILS ();
+
+    // And the resume count should not have increased.
+    ASSERT_EQ (initial_resume_call_count, resume_call_count);
+}
+
 TEST_F (ThreadStateCoordinatorTest, RequestThreadResumeSignalsErrorOnAlreadyRunningThread)
 {
     const lldb::tid_t TEST_TID = 1234;

Modified: lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp?rev=219412&r1=219411&r2=219412&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp Thu Oct  9 12:00:55 2014
@@ -444,6 +444,9 @@ public:
         // to reflect it is running after this completes.
         m_request_thread_resume_function (m_tid);
 
+        // Now mark it is running.
+        find_it->second = false;
+
         return eventLoopResultContinue;
     }
 





More information about the lldb-commits mailing list