LLDB mainline
ThreadPlanBase.cpp
Go to the documentation of this file.
1//===-- ThreadPlanBase.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11//
16#include "lldb/Target/Process.h"
20#include "lldb/Utility/Log.h"
21#include "lldb/Utility/Stream.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26// ThreadPlanBase: This one always stops, and never has anything particular to
27// do.
28// FIXME: The "signal handling" policies should probably go here.
29
31 : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
33// Set the tracer to a default tracer.
34// FIXME: need to add a thread settings variable to pix various tracers...
35#define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
36
37#ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
38 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(thread));
39#else
41#endif
42 new_tracer_sp->EnableTracing(thread.GetTraceEnabledState());
43 SetThreadPlanTracer(new_tracer_sp);
45}
46
48
50 s->Printf("Base thread plan.");
51}
52
54
56 // The base plan should defer to its tracer, since by default it always
57 // handles the stop.
58 return !TracerExplainsStop();
59}
60
62 StopInfoSP stop_info_sp = GetThread().GetStopInfo();
63 if (stop_info_sp) {
64 bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
65 if (should_notify)
66 return eVoteYes;
67 else
68 return eVoteNoOpinion;
69 } else
70 return eVoteNoOpinion;
71}
72
76
77 Log *log = GetLog(LLDBLog::Step);
78
79 StopInfoSP stop_info_sp = GetPrivateStopInfo();
80 if (stop_info_sp) {
81 StopReason reason = stop_info_sp->GetStopReason();
82 switch (reason) {
84 case eStopReasonNone:
85 // This
88 return false;
89
92 if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
93 // If we are going to stop for a breakpoint, then unship the other
94 // plans at this point. Don't force the discard, however, so
95 // Controlling plans can stay in place if they want to.
97 log,
98 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
99 " (breakpoint hit.)",
100 m_tid);
102 return true;
103 }
104 // If we aren't going to stop at this breakpoint, and it is internal,
105 // don't report this stop or the subsequent running event. Otherwise we
106 // will post the stopped & running, but the stopped event will get marked
107 // with "restarted" so the UI will know to wait and expect the consequent
108 // "running".
109 if (stop_info_sp->ShouldNotify(event_ptr)) {
112 } else {
115 }
116 return false;
117
118 // TODO: the break below was missing, was this intentional??? If so
119 // please mention it
120 break;
121
123 // If we crashed, discard thread plans and stop. Don't force the
124 // discard, however, since on rerun the target may clean up this
125 // exception and continue normally from there.
126 LLDB_LOGF(
127 log,
128 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
129 " (exception: %s)",
130 m_tid, stop_info_sp->GetDescription());
132 return true;
133
134 case eStopReasonExec:
135 // If we crashed, discard thread plans and stop. Don't force the
136 // discard, however, since on rerun the target may clean up this
137 // exception and continue normally from there.
138 LLDB_LOGF(
139 log,
140 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
141 " (exec.)",
142 m_tid);
144 return true;
145
148 if (stop_info_sp->ShouldStop(event_ptr)) {
149 LLDB_LOGF(
150 log,
151 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
152 " (signal: %s)",
153 m_tid, stop_info_sp->GetDescription());
155 return true;
156 } else {
157 // We're not going to stop, but while we are here, let's figure out
158 // whether to report this.
159 if (stop_info_sp->ShouldNotify(event_ptr))
161 else
163 }
164 return false;
165
166 default:
167 return true;
168 }
169
170 } else {
173 }
174
175 // If there's no explicit reason to stop, then we will continue.
176 return false;
177}
178
179bool ThreadPlanBase::StopOthers() { return false; }
180
182
183bool ThreadPlanBase::WillStop() { return true; }
184
186 bool current_plan) {
187 // Reset these to the default values so we don't set them wrong, then not get
188 // asked for a while, then return the wrong answer.
191 return true;
192}
193
194// The base plan is never done.
196 // The base plan is never done.
197 return false;
198}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:349
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
bool ShouldStop(Event *event_ptr) override
bool DoPlanExplainsStop(Event *event_ptr) override
lldb::StateType GetPlanRunState() override
Vote ShouldReportStop(Event *event_ptr) override
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:42
void SetThreadPlanTracer(lldb::ThreadPlanTracerSP new_tracer_sp)
Definition: ThreadPlan.h:439
bool SetIsControllingPlan(bool value)
Definition: ThreadPlan.h:398
lldb::StopInfoSP GetPrivateStopInfo()
Definition: ThreadPlan.h:517
bool GetTraceEnabledState() const
Definition: Thread.cpp:122
void DiscardThreadPlans(bool force)
Discards the plans queued on the plan stack of the current thread.
Definition: Thread.cpp:1211
lldb::StopInfoSP GetStopInfo()
Definition: Thread.cpp:341
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
StateType
Process and Thread States.
@ eStateRunning
Process or thread is running and can't be examined.
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
Definition: lldb-forward.h:419
StopReason
Thread stop reasons.
@ eStopReasonBreakpoint
@ eStopReasonExec
Program was re-exec'ed.
@ eStopReasonThreadExiting
@ eStopReasonException
@ eStopReasonInvalid
@ eStopReasonWatchpoint
@ eStopReasonSignal
std::shared_ptr< lldb_private::ThreadPlanTracer > ThreadPlanTracerSP
Definition: lldb-forward.h:445