forked from OSchip/llvm-project
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. llvm-svn: 218872
This commit is contained in:
parent
4bb603b2aa
commit
404e370892
|
@ -530,6 +530,28 @@ TEST_F (ThreadStateCoordinatorTest, DeferredNotificationRemovedByResetForExec)
|
|||
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, RequestThreadResumeCallsCallbackWhenThreadIs
|
|||
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, RequestThreadResumeIgnoresCallbackWhenThread
|
|||
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue