[Lldb-commits] [lldb] r218872 - thread state coordinator: requesting resume now signals error appropriately.
Todd Fiala
todd.fiala at gmail.com
Thu Oct 2 07:41:15 PDT 2014
Author: tfiala
Date: Thu Oct 2 09:41:15 2014
New Revision: 218872
URL: http://llvm.org/viewvc/llvm-project?rev=218872&view=rev
Log:
thread state coordinator: requesting resume now signals error appropriately.
Added tests to verify that the coordinator signals an error if
the given thread to resume is unknown, and if the thread is through to
be running already.
Modified resume handling code to match tests.
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=218872&r1=218871&r2=218872&view=diff
==============================================================================
--- lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp (original)
+++ lldb/trunk/gtest/unittest/Plugins/Process/Linux/ThreadStateCoordinatorTest.cpp Thu Oct 2 09:41:15 2014
@@ -530,6 +530,28 @@ TEST_F (ThreadStateCoordinatorTest, Defe
ASSERT_EQ (false, DidFireDeferredNotification ());
}
+TEST_F (ThreadStateCoordinatorTest, RequestThreadResumeSignalsErrorOnUnknownThread)
+{
+ const lldb::tid_t UNKNOWN_TID = 411;
+
+ // Request a resume.
+ lldb::tid_t resumed_tid = 0;
+ int resume_call_count = 0;
+
+ m_coordinator.RequestThreadResume (UNKNOWN_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_FAILS ();
+ ASSERT_EQ (0, resume_call_count);
+}
TEST_F (ThreadStateCoordinatorTest, RequestThreadResumeCallsCallbackWhenThreadIsStopped)
{
@@ -556,10 +578,10 @@ TEST_F (ThreadStateCoordinatorTest, Requ
ASSERT_EQ (NEW_THREAD_TID, resumed_tid);
}
-TEST_F (ThreadStateCoordinatorTest, RequestThreadResumeIgnoresCallbackWhenThreadIsRunning)
+TEST_F (ThreadStateCoordinatorTest, RequestThreadResumeSignalsErrorOnAlreadyRunningThread)
{
- // This thread will be assumed running (i.e. unknown, assumed running until marked stopped.)
const lldb::tid_t TEST_TID = 1234;
+ SetupKnownRunningThread (NEW_THREAD_TID);
// Request a resume.
lldb::tid_t resumed_tid = 0;
@@ -577,7 +599,7 @@ TEST_F (ThreadStateCoordinatorTest, Requ
ASSERT_EQ (0, resume_call_count);
// Process next event.
- ASSERT_PROCESS_NEXT_EVENT_SUCCEEDS ();
+ ASSERT_PROCESS_NEXT_EVENT_FAILS ();
// The resume request should not have gone off because we think it is already running.
ASSERT_EQ (0, resume_call_count);
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=218872&r1=218871&r2=218872&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ThreadStateCoordinator.cpp Thu Oct 2 09:41:15 2014
@@ -333,18 +333,25 @@ public:
EventLoopResult
ProcessEvent(ThreadStateCoordinator &coordinator) override
{
- // Tell the thread to resume if we don't already think it is running.
+ // Ensure we know about the thread.
auto find_it = coordinator.m_tid_stop_map.find (m_tid);
if (find_it == coordinator.m_tid_stop_map.end ())
{
- // Skip the resume call - we think it is already running because we don't know anything about the thread.
- coordinator.Log ("EventRequestResume::%s skipping resume request because we don't know about tid %" PRIu64 " and we therefore assume it is running.", __FUNCTION__, m_tid);
+ // We don't know about this thread. This is an error condition.
+ std::ostringstream error_message;
+ error_message << "error: tid " << m_tid << " asked to resume but tid is unknown";
+ m_error_function (error_message.str ());
return eventLoopResultContinue;
}
- else if (!find_it->second)
+
+ // Tell the thread to resume if we don't already think it is running.
+ const bool is_stopped = find_it->second;
+ if (!is_stopped)
{
// Skip the resume call - we have tracked it to be running.
- coordinator.Log ("EventRequestResume::%s skipping resume request because tid %" PRIu64 " is already running according to our state tracking.", __FUNCTION__, m_tid);
+ std::ostringstream error_message;
+ error_message << "error: tid " << m_tid << " asked to resume but we think it is already running";
+ m_error_function (error_message.str ());
return eventLoopResultContinue;
}
More information about the lldb-commits
mailing list