2010-06-09 00:52:24 +08:00
|
|
|
//===-- ThreadPlan.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/ThreadPlan.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/State.h"
|
2010-09-04 01:10:42 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ThreadPlan constructor
|
|
|
|
//----------------------------------------------------------------------
|
2010-06-19 12:45:32 +08:00
|
|
|
ThreadPlan::ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote stop_vote, Vote run_vote) :
|
2010-07-16 20:32:33 +08:00
|
|
|
m_thread (thread),
|
|
|
|
m_stop_vote (stop_vote),
|
|
|
|
m_run_vote (run_vote),
|
2010-06-19 12:45:32 +08:00
|
|
|
m_kind (kind),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_name (name),
|
|
|
|
m_plan_complete_mutex (Mutex::eMutexTypeRecursive),
|
2010-07-16 20:32:33 +08:00
|
|
|
m_plan_complete (false),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_plan_private (false),
|
|
|
|
m_okay_to_discard (false)
|
|
|
|
{
|
|
|
|
SetID (GetNextID());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ThreadPlan::~ThreadPlan()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ThreadPlan::GetName () const
|
|
|
|
{
|
|
|
|
return m_name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread &
|
|
|
|
ThreadPlan::GetThread()
|
|
|
|
{
|
|
|
|
return m_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Thread &
|
|
|
|
ThreadPlan::GetThread() const
|
|
|
|
{
|
|
|
|
return m_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlan::IsPlanComplete ()
|
|
|
|
{
|
2010-07-14 08:18:15 +08:00
|
|
|
Mutex::Locker locker(m_plan_complete_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_plan_complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlan::SetPlanComplete ()
|
|
|
|
{
|
2010-07-14 08:18:15 +08:00
|
|
|
Mutex::Locker locker(m_plan_complete_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_plan_complete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlan::MischiefManaged ()
|
|
|
|
{
|
2010-07-14 08:18:15 +08:00
|
|
|
Mutex::Locker locker(m_plan_complete_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_plan_complete = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vote
|
|
|
|
ThreadPlan::ShouldReportStop (Event *event_ptr)
|
|
|
|
{
|
2010-09-04 01:10:42 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_stop_vote == eVoteNoOpinion)
|
|
|
|
{
|
|
|
|
ThreadPlan *prev_plan = GetPreviousPlan ();
|
|
|
|
if (prev_plan)
|
2010-09-04 01:10:42 +08:00
|
|
|
{
|
|
|
|
Vote prev_vote = prev_plan->ShouldReportStop (event_ptr);
|
|
|
|
if (log)
|
2010-09-04 06:45:01 +08:00
|
|
|
log->Printf ("ThreadPlan::ShouldReportStop() returning previous thread plan vote: %s", GetVoteAsCString (prev_vote));
|
2010-09-04 01:10:42 +08:00
|
|
|
return prev_vote;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-09-04 01:10:42 +08:00
|
|
|
if (log)
|
2010-09-04 06:45:01 +08:00
|
|
|
log->Printf ("ThreadPlan::ShouldReportStop() returning vote: %s", GetVoteAsCString (m_stop_vote));
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_stop_vote;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vote
|
|
|
|
ThreadPlan::ShouldReportRun (Event *event_ptr)
|
|
|
|
{
|
|
|
|
if (m_run_vote == eVoteNoOpinion)
|
|
|
|
{
|
|
|
|
ThreadPlan *prev_plan = GetPreviousPlan ();
|
|
|
|
if (prev_plan)
|
|
|
|
return prev_plan->ShouldReportRun (event_ptr);
|
|
|
|
}
|
|
|
|
return m_run_vote;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlan::StopOthers ()
|
|
|
|
{
|
|
|
|
ThreadPlan *prev_plan;
|
|
|
|
prev_plan = GetPreviousPlan ();
|
|
|
|
if (prev_plan == NULL)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return prev_plan->StopOthers();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlan::WillResume (StateType resume_state, bool current_plan)
|
|
|
|
{
|
|
|
|
if (current_plan)
|
|
|
|
{
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
|
|
|
|
|
|
|
|
if (log)
|
2010-09-04 01:10:42 +08:00
|
|
|
{
|
|
|
|
RegisterContext *reg_ctx = m_thread.GetRegisterContext();
|
|
|
|
addr_t pc = reg_ctx->GetPC();
|
|
|
|
addr_t sp = reg_ctx->GetSP();
|
|
|
|
addr_t fp = reg_ctx->GetFP();
|
2010-09-04 06:45:01 +08:00
|
|
|
log->Printf("%s Thread #%u: tid = 0x%4.4x, pc = 0x%8.8llx, sp = 0x%8.8llx, fp = 0x%8.8llx, plan = '%s', state = %s, stop others = %d",
|
|
|
|
__FUNCTION__,
|
2010-09-04 01:10:42 +08:00
|
|
|
m_thread.GetIndexID(),
|
|
|
|
m_thread.GetID(),
|
|
|
|
(uint64_t)pc,
|
|
|
|
(uint64_t)sp,
|
|
|
|
(uint64_t)fp,
|
|
|
|
m_name.c_str(),
|
|
|
|
StateAsCString(resume_state),
|
|
|
|
StopOthers());
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::user_id_t
|
|
|
|
ThreadPlan::GetNextID()
|
|
|
|
{
|
|
|
|
static uint32_t g_nextPlanID = 0;
|
|
|
|
return ++g_nextPlanID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlan::DidPush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlan::WillPop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlan::PushPlan (ThreadPlanSP &thread_plan_sp)
|
|
|
|
{
|
|
|
|
m_thread.PushPlan (thread_plan_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlan *
|
|
|
|
ThreadPlan::GetPreviousPlan ()
|
|
|
|
{
|
|
|
|
return m_thread.GetPreviousPlan (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlan::SetPrivate (bool input)
|
|
|
|
{
|
|
|
|
m_plan_private = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlan::GetPrivate (void)
|
|
|
|
{
|
|
|
|
return m_plan_private;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlan::OkayToDiscard()
|
|
|
|
{
|
|
|
|
if (!IsMasterPlan())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return m_okay_to_discard;
|
|
|
|
}
|
|
|
|
|