2010-06-09 00:52:24 +08:00
|
|
|
//===-- ThreadPlanBase.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/ThreadPlanBase.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
//
|
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointSite.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
2011-02-08 13:20:59 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/StopInfo.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ThreadPlanBase: This one always stops, and never has anything particular
|
|
|
|
// to do.
|
|
|
|
// FIXME: The "signal handling" policies should probably go here.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
ThreadPlanBase::ThreadPlanBase (Thread &thread) :
|
2010-06-19 12:45:32 +08:00
|
|
|
ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-12 03:26:09 +08:00
|
|
|
// Set the tracer to a default tracer.
|
2010-11-18 10:47:07 +08:00
|
|
|
// FIXME: need to add a thread settings variable to pix various tracers...
|
|
|
|
#define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
|
|
|
|
|
|
|
|
#ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
|
|
|
|
ThreadPlanTracerSP new_tracer_sp (new ThreadPlanAssemblyTracer (m_thread));
|
|
|
|
#else
|
2010-11-12 03:26:09 +08:00
|
|
|
ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread));
|
2010-11-18 10:47:07 +08:00
|
|
|
#endif
|
2010-11-12 03:26:09 +08:00
|
|
|
new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState());
|
|
|
|
SetThreadPlanTracer(new_tracer_sp);
|
2012-04-10 06:37:39 +08:00
|
|
|
SetIsMasterPlan (true);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanBase::~ThreadPlanBase ()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
|
|
|
|
{
|
|
|
|
s->Printf ("Base thread plan.");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanBase::ValidatePlan (Stream *error)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-02-09 09:29:05 +08:00
|
|
|
ThreadPlanBase::PlanExplainsStop (Event *event_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-12 03:26:09 +08:00
|
|
|
// The base plan should defer to its tracer, since by default it
|
|
|
|
// always handles the stop.
|
|
|
|
if (TracerExplainsStop())
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanBase::ShouldStop (Event *event_ptr)
|
|
|
|
{
|
|
|
|
m_stop_vote = eVoteYes;
|
|
|
|
m_run_vote = eVoteYes;
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2011-02-08 13:20:59 +08:00
|
|
|
|
2010-10-20 08:39:53 +08:00
|
|
|
StopInfoSP stop_info_sp = GetPrivateStopReason();
|
|
|
|
if (stop_info_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-20 08:39:53 +08:00
|
|
|
StopReason reason = stop_info_sp->GetStopReason();
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (reason)
|
|
|
|
{
|
2010-08-04 09:40:35 +08:00
|
|
|
case eStopReasonInvalid:
|
|
|
|
case eStopReasonNone:
|
2011-01-24 14:34:17 +08:00
|
|
|
// This
|
|
|
|
m_run_vote = eVoteNoOpinion;
|
2010-08-04 09:40:35 +08:00
|
|
|
m_stop_vote = eVoteNo;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case eStopReasonBreakpoint:
|
2011-09-22 06:47:15 +08:00
|
|
|
case eStopReasonWatchpoint:
|
2013-02-23 05:23:43 +08:00
|
|
|
if (stop_info_sp->ShouldStopSynchronous(event_ptr))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-04 09:40:35 +08:00
|
|
|
// If we are going to stop for a breakpoint, then unship the other plans
|
|
|
|
// at this point. Don't force the discard, however, so Master plans can stay
|
|
|
|
// in place if they want to.
|
2011-02-08 13:20:59 +08:00
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (breakpoint hit.)", m_thread.GetID());
|
2010-08-04 09:40:35 +08:00
|
|
|
m_thread.DiscardThreadPlans(false);
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
// If we aren't going to stop at this breakpoint, and it is internal,
|
|
|
|
// don't report this stop or the subsequent running event.
|
|
|
|
// Otherwise we will post the stopped & running, but the stopped event will get marked
|
|
|
|
// with "restarted" so the UI will know to wait and expect the consequent "running".
|
2010-10-20 08:39:53 +08:00
|
|
|
if (stop_info_sp->ShouldNotify (event_ptr))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-04 09:40:35 +08:00
|
|
|
m_stop_vote = eVoteYes;
|
|
|
|
m_run_vote = eVoteYes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_stop_vote = eVoteNo;
|
|
|
|
m_run_vote = eVoteNo;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO: the break below was missing, was this intentional??? If so
|
|
|
|
// please mention it
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStopReasonException:
|
|
|
|
// If we crashed, discard thread plans and stop. Don't force the discard, however,
|
|
|
|
// since on rerun the target may clean up this exception and continue normally from there.
|
2011-02-08 13:20:59 +08:00
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exception.)", m_thread.GetID());
|
2010-08-04 09:40:35 +08:00
|
|
|
m_thread.DiscardThreadPlans(false);
|
|
|
|
return true;
|
|
|
|
|
2012-12-05 08:16:59 +08:00
|
|
|
case eStopReasonExec:
|
|
|
|
// If we crashed, discard thread plans and stop. Don't force the discard, however,
|
|
|
|
// since on rerun the target may clean up this exception and continue normally from there.
|
|
|
|
if (log)
|
|
|
|
log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (exec.)", m_thread.GetID());
|
|
|
|
m_thread.DiscardThreadPlans(false);
|
|
|
|
return true;
|
2012-12-21 07:08:03 +08:00
|
|
|
|
|
|
|
case eStopReasonThreadExiting:
|
2010-08-04 09:40:35 +08:00
|
|
|
case eStopReasonSignal:
|
2010-10-20 08:39:53 +08:00
|
|
|
if (stop_info_sp->ShouldStop(event_ptr))
|
2010-08-04 09:40:35 +08:00
|
|
|
{
|
2011-02-08 13:20:59 +08:00
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64 " (signal.)", m_thread.GetID());
|
2010-06-09 00:52:24 +08:00
|
|
|
m_thread.DiscardThreadPlans(false);
|
|
|
|
return true;
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-04 09:40:35 +08:00
|
|
|
// We're not going to stop, but while we are here, let's figure out
|
|
|
|
// whether to report this.
|
2010-10-20 08:39:53 +08:00
|
|
|
if (stop_info_sp->ShouldNotify(event_ptr))
|
2010-08-04 09:40:35 +08:00
|
|
|
m_stop_vote = eVoteYes;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-08-04 09:40:35 +08:00
|
|
|
m_stop_vote = eVoteNo;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
else
|
|
|
|
{
|
2011-01-24 14:34:17 +08:00
|
|
|
m_run_vote = eVoteNoOpinion;
|
2010-08-04 09:40:35 +08:00
|
|
|
m_stop_vote = eVoteNo;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// If there's no explicit reason to stop, then we will continue.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanBase::StopOthers ()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StateType
|
2010-11-12 03:26:09 +08:00
|
|
|
ThreadPlanBase::GetPlanRunState ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return eStateRunning;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadPlanBase::WillStop ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-24 14:34:17 +08:00
|
|
|
bool
|
|
|
|
ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan)
|
|
|
|
{
|
|
|
|
// Reset these to the default values so we don't set them wrong, then not get asked
|
|
|
|
// for a while, then return the wrong answer.
|
|
|
|
m_run_vote = eVoteNoOpinion;
|
|
|
|
m_stop_vote = eVoteNo;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// The base plan is never done.
|
|
|
|
bool
|
|
|
|
ThreadPlanBase::MischiefManaged ()
|
|
|
|
{
|
|
|
|
// The base plan is never done.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|