#include "lldb/Target/ThreadPlanBase.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/BreakpointSite.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
using namespace lldb_private;
ThreadPlanBase::ThreadPlanBase(Thread &thread)
: ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
eVoteNoOpinion) {
#define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
#ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(thread));
#else
ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
#endif
new_tracer_sp->EnableTracing(thread.GetTraceEnabledState());
SetThreadPlanTracer(new_tracer_sp);
SetIsControllingPlan(true);
}
ThreadPlanBase::~ThreadPlanBase() = default;
void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) {
s->Printf("Base thread plan.");
}
bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) {
return !TracerExplainsStop();
}
Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) {
StopInfoSP stop_info_sp = GetThread().GetStopInfo();
if (stop_info_sp) {
bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
if (should_notify)
return eVoteYes;
else
return eVoteNoOpinion;
} else
return eVoteNoOpinion;
}
bool ThreadPlanBase::ShouldStop(Event *event_ptr) {
m_report_stop_vote = eVoteYes;
m_report_run_vote = eVoteYes;
Log *log = GetLog(LLDBLog::Step);
StopInfoSP stop_info_sp = GetPrivateStopInfo();
if (stop_info_sp) {
StopReason reason = stop_info_sp->GetStopReason();
switch (reason) {
case eStopReasonInvalid:
case eStopReasonNone:
m_report_run_vote = eVoteNoOpinion;
m_report_stop_vote = eVoteNo;
return false;
#ifdef MS_DEBUGGER
case eStopReasonDeviceBreakpoint:
#endif
case eStopReasonBreakpoint:
case eStopReasonWatchpoint:
if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
LLDB_LOGF(
log,
"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
" (breakpoint hit.)",
m_tid);
GetThread().DiscardThreadPlans(false);
return true;
}
if (stop_info_sp->ShouldNotify(event_ptr)) {
m_report_stop_vote = eVoteYes;
m_report_run_vote = eVoteYes;
} else {
m_report_stop_vote = eVoteNo;
m_report_run_vote = eVoteNo;
}
return false;
break;
case eStopReasonException:
LLDB_LOGF(
log,
"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
" (exception: %s)",
m_tid, stop_info_sp->GetDescription());
GetThread().DiscardThreadPlans(false);
return true;
case eStopReasonExec:
LLDB_LOGF(
log,
"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
" (exec.)",
m_tid);
GetThread().DiscardThreadPlans(false);
return true;
case eStopReasonThreadExiting:
case eStopReasonSignal:
if (stop_info_sp->ShouldStop(event_ptr)) {
LLDB_LOGF(
log,
"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
" (signal: %s)",
m_tid, stop_info_sp->GetDescription());
GetThread().DiscardThreadPlans(false);
return true;
} else {
if (stop_info_sp->ShouldNotify(event_ptr))
m_report_stop_vote = eVoteYes;
else
m_report_stop_vote = eVoteNo;
}
return false;
#ifdef MS_DEBUGGER
case eStopReasonTrace:
if (!stop_info_sp->ShouldStop(event_ptr)) {
LLDB_LOGF(
log,
"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
" (trace: %s)",
m_tid, stop_info_sp->GetDescription());
return false;
}
return true;
#endif
default:
return true;
}
} else {
m_report_run_vote = eVoteNoOpinion;
m_report_stop_vote = eVoteNo;
}
return false;
}
bool ThreadPlanBase::StopOthers() { return false; }
StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; }
bool ThreadPlanBase::WillStop() { return true; }
bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state,
bool current_plan) {
m_report_run_vote = eVoteNoOpinion;
m_report_stop_vote = eVoteNo;
return true;
}
bool ThreadPlanBase::MischiefManaged() {
return false;
}