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"
18 #include "lldb/Target/StopInfo.h"
19 #include "lldb/Utility/LLDBLog.h"
20 #include "lldb/Utility/Log.h"
21 #include "lldb/Utility/Stream.h"
22 
23 using namespace lldb;
24 using 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 
30 ThreadPlanBase::ThreadPlanBase(Thread &thread)
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
40  ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
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 
53 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
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) {
83  case eStopReasonInvalid:
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.
96  LLDB_LOGF(
97  log,
98  "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
99  " (breakpoint hit.)",
100  m_tid);
101  GetThread().DiscardThreadPlans(false);
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());
131  GetThread().DiscardThreadPlans(false);
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);
143  GetThread().DiscardThreadPlans(false);
144  return true;
145 
147  case eStopReasonSignal:
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());
154  GetThread().DiscardThreadPlans(false);
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 
179 bool ThreadPlanBase::StopOthers() { return false; }
180 
182 
183 bool 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 }
lldb_private::Thread::DiscardThreadPlans
void DiscardThreadPlans(bool force)
Discards the plans queued on the plan stack of the current thread.
Definition: Thread.cpp:1226
lldb_private::ThreadPlanBase::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Definition: ThreadPlanBase.cpp:49
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:42
lldb_private::ThreadPlanBase::DoPlanExplainsStop
bool DoPlanExplainsStop(Event *event_ptr) override
Definition: ThreadPlanBase.cpp:55
lldb_private::ThreadProperties::GetTraceEnabledState
bool GetTraceEnabledState() const
Definition: Thread.cpp:126
lldb_private::Event
Definition: Event.h:182
lldb_private::eVoteYes
@ eVoteYes
Definition: lldb-private-enumerations.h:59
lldb_private::ThreadPlan::m_report_run_vote
Vote m_report_run_vote
Definition: ThreadPlan.h:533
lldb_private::ThreadPlanBase::WillStop
bool WillStop() override
Definition: ThreadPlanBase.cpp:183
lldb::eStopReasonThreadExiting
@ eStopReasonThreadExiting
Definition: lldb-enumerations.h:249
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:344
BreakpointLocation.h
lldb::eStopReasonInvalid
@ eStopReasonInvalid
Definition: lldb-enumerations.h:240
StoppointCallbackContext.h
lldb_private::ThreadPlanTracer
Definition: ThreadPlanTracer.h:20
lldb_private::ThreadPlanBase::DoWillResume
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
Definition: ThreadPlanBase.cpp:185
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
lldb::eStopReasonException
@ eStopReasonException
Definition: lldb-enumerations.h:246
lldb_private::eVoteNoOpinion
@ eVoteNoOpinion
Definition: lldb-private-enumerations.h:59
lldb_private::Stream
Definition: Stream.h:28
Process.h
lldb_private::ThreadPlan::SetIsControllingPlan
bool SetIsControllingPlan(bool value)
Definition: ThreadPlan.h:398
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ThreadPlanBase::MischiefManaged
bool MischiefManaged() override
Definition: ThreadPlanBase.cpp:195
lldb_private::ThreadPlan
Definition: ThreadPlan.h:287
lldb_private::eVoteNo
@ eVoteNo
Definition: lldb-private-enumerations.h:59
Log.h
lldb_private::ThreadPlanBase::~ThreadPlanBase
~ThreadPlanBase() override
lldb::eStopReasonWatchpoint
@ eStopReasonWatchpoint
Definition: lldb-enumerations.h:244
lldb_private::Thread
Definition: Thread.h:61
lldb::eStopReasonNone
@ eStopReasonNone
Definition: lldb-enumerations.h:241
lldb_private::ThreadPlanAssemblyTracer
Definition: ThreadPlanTracer.h:71
lldb_private::LLDBLog::Step
@ Step
lldb::eStopReasonSignal
@ eStopReasonSignal
Definition: lldb-enumerations.h:245
lldb_private::Thread::GetStopInfo
lldb::StopInfoSP GetStopInfo()
Definition: Thread.cpp:335
lldb::eStopReasonExec
@ eStopReasonExec
Program was re-exec'ed.
Definition: lldb-enumerations.h:247
lldb_private::ThreadPlanBase::ValidatePlan
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
Definition: ThreadPlanBase.cpp:53
lldb_private::ThreadPlanBase::ShouldStop
bool ShouldStop(Event *event_ptr) override
Definition: ThreadPlanBase.cpp:73
StopInfo.h
lldb_private::ThreadPlan::m_report_stop_vote
Vote m_report_stop_vote
Definition: ThreadPlan.h:532
lldb::eStopReasonBreakpoint
@ eStopReasonBreakpoint
Definition: lldb-enumerations.h:243
lldb_private::Vote
Vote
Definition: lldb-private-enumerations.h:59
ThreadPlanBase.h
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::ThreadPlanBase::ShouldReportStop
Vote ShouldReportStop(Event *event_ptr) override
Definition: ThreadPlanBase.cpp:61
lldb_private::ThreadPlan::SetThreadPlanTracer
void SetThreadPlanTracer(lldb::ThreadPlanTracerSP new_tracer_sp)
Definition: ThreadPlan.h:439
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ThreadPlanBase::StopOthers
bool StopOthers() override
Definition: ThreadPlanBase.cpp:179
Breakpoint.h
lldb_private::ThreadPlan::m_tid
lldb::tid_t m_tid
Definition: ThreadPlan.h:531
BreakpointSite.h
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
Stream.h
lldb_private::Log
Definition: Log.h:115
lldb_private::ThreadPlanBase::GetPlanRunState
lldb::StateType GetPlanRunState() override
Definition: ThreadPlanBase.cpp:181
lldb_private::ThreadPlan::GetPrivateStopInfo
lldb::StopInfoSP GetPrivateStopInfo()
Definition: ThreadPlan.h:517
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
lldb
Definition: SBAddress.h:15
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
RegisterContext.h
LLDBLog.h
lldb_private::ThreadPlan::TracerExplainsStop
bool TracerExplainsStop()
Definition: ThreadPlan.h:356
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb_private::ThreadPlan::m_thread
Thread * m_thread
Definition: ThreadPlan.h:546