Path: blob/main/contrib/llvm-project/lldb/source/Target/ThreadPlanBase.cpp
39587 views
//===-- ThreadPlanBase.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Target/ThreadPlanBase.h"910//11#include "lldb/Breakpoint/Breakpoint.h"12#include "lldb/Breakpoint/BreakpointLocation.h"13#include "lldb/Breakpoint/BreakpointSite.h"14#include "lldb/Breakpoint/StoppointCallbackContext.h"15#include "lldb/Target/Process.h"16#include "lldb/Target/RegisterContext.h"17#include "lldb/Target/StopInfo.h"18#include "lldb/Utility/LLDBLog.h"19#include "lldb/Utility/Log.h"20#include "lldb/Utility/Stream.h"2122using namespace lldb;23using namespace lldb_private;2425// ThreadPlanBase: This one always stops, and never has anything particular to26// do.27// FIXME: The "signal handling" policies should probably go here.2829ThreadPlanBase::ThreadPlanBase(Thread &thread)30: ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,31eVoteNoOpinion) {32// Set the tracer to a default tracer.33// FIXME: need to add a thread settings variable to pix various tracers...34#define THREAD_PLAN_USE_ASSEMBLY_TRACER 13536#ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER37ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(thread));38#else39ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));40#endif41new_tracer_sp->EnableTracing(thread.GetTraceEnabledState());42SetThreadPlanTracer(new_tracer_sp);43SetIsControllingPlan(true);44}4546ThreadPlanBase::~ThreadPlanBase() = default;4748void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) {49s->Printf("Base thread plan.");50}5152bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }5354bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) {55// The base plan should defer to its tracer, since by default it always56// handles the stop.57return !TracerExplainsStop();58}5960Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) {61StopInfoSP stop_info_sp = GetThread().GetStopInfo();62if (stop_info_sp) {63bool should_notify = stop_info_sp->ShouldNotify(event_ptr);64if (should_notify)65return eVoteYes;66else67return eVoteNoOpinion;68} else69return eVoteNoOpinion;70}7172bool ThreadPlanBase::ShouldStop(Event *event_ptr) {73m_report_stop_vote = eVoteYes;74m_report_run_vote = eVoteYes;7576Log *log = GetLog(LLDBLog::Step);7778StopInfoSP stop_info_sp = GetPrivateStopInfo();79if (stop_info_sp) {80StopReason reason = stop_info_sp->GetStopReason();81switch (reason) {82case eStopReasonInvalid:83case eStopReasonNone:84// This85m_report_run_vote = eVoteNoOpinion;86m_report_stop_vote = eVoteNo;87return false;8889case eStopReasonBreakpoint:90case eStopReasonWatchpoint:91if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {92// If we are going to stop for a breakpoint, then unship the other93// plans at this point. Don't force the discard, however, so94// Controlling plans can stay in place if they want to.95LLDB_LOGF(96log,97"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx6498" (breakpoint hit.)",99m_tid);100GetThread().DiscardThreadPlans(false);101return true;102}103// If we aren't going to stop at this breakpoint, and it is internal,104// don't report this stop or the subsequent running event. Otherwise we105// will post the stopped & running, but the stopped event will get marked106// with "restarted" so the UI will know to wait and expect the consequent107// "running".108if (stop_info_sp->ShouldNotify(event_ptr)) {109m_report_stop_vote = eVoteYes;110m_report_run_vote = eVoteYes;111} else {112m_report_stop_vote = eVoteNo;113m_report_run_vote = eVoteNo;114}115return false;116117// TODO: the break below was missing, was this intentional??? If so118// please mention it119break;120121case eStopReasonException:122// If we crashed, discard thread plans and stop. Don't force the123// discard, however, since on rerun the target may clean up this124// exception and continue normally from there.125LLDB_LOGF(126log,127"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64128" (exception: %s)",129m_tid, stop_info_sp->GetDescription());130GetThread().DiscardThreadPlans(false);131return true;132133case eStopReasonExec:134// If we crashed, discard thread plans and stop. Don't force the135// discard, however, since on rerun the target may clean up this136// exception and continue normally from there.137LLDB_LOGF(138log,139"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64140" (exec.)",141m_tid);142GetThread().DiscardThreadPlans(false);143return true;144145case eStopReasonThreadExiting:146case eStopReasonSignal:147if (stop_info_sp->ShouldStop(event_ptr)) {148LLDB_LOGF(149log,150"Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64151" (signal: %s)",152m_tid, stop_info_sp->GetDescription());153GetThread().DiscardThreadPlans(false);154return true;155} else {156// We're not going to stop, but while we are here, let's figure out157// whether to report this.158if (stop_info_sp->ShouldNotify(event_ptr))159m_report_stop_vote = eVoteYes;160else161m_report_stop_vote = eVoteNo;162}163return false;164165default:166return true;167}168169} else {170m_report_run_vote = eVoteNoOpinion;171m_report_stop_vote = eVoteNo;172}173174// If there's no explicit reason to stop, then we will continue.175return false;176}177178bool ThreadPlanBase::StopOthers() { return false; }179180StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; }181182bool ThreadPlanBase::WillStop() { return true; }183184bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state,185bool current_plan) {186// Reset these to the default values so we don't set them wrong, then not get187// asked for a while, then return the wrong answer.188m_report_run_vote = eVoteNoOpinion;189m_report_stop_vote = eVoteNo;190return true;191}192193// The base plan is never done.194bool ThreadPlanBase::MischiefManaged() {195// The base plan is never done.196return false;197}198199200