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/Log.h"
20 #include "lldb/Utility/Stream.h"
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 
25 // ThreadPlanBase: This one always stops, and never has anything particular to
26 // do.
27 // FIXME: The "signal handling" policies should probably go here.
28 
29 ThreadPlanBase::ThreadPlanBase(Thread &thread)
30  : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
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 1
35 
36 #ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
37  ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(thread));
38 #else
39  ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
40 #endif
41  new_tracer_sp->EnableTracing(thread.GetTraceEnabledState());
42  SetThreadPlanTracer(new_tracer_sp);
43  SetIsMasterPlan(true);
44 }
45 
47 
49  s->Printf("Base thread plan.");
50 }
51 
52 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
53 
55  // The base plan should defer to its tracer, since by default it always
56  // handles the stop.
57  return !TracerExplainsStop();
58 }
59 
61  StopInfoSP stop_info_sp = GetThread().GetStopInfo();
62  if (stop_info_sp) {
63  bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
64  if (should_notify)
65  return eVoteYes;
66  else
67  return eVoteNoOpinion;
68  } else
69  return eVoteNoOpinion;
70 }
71 
75 
77 
78  StopInfoSP stop_info_sp = GetPrivateStopInfo();
79  if (stop_info_sp) {
80  StopReason reason = stop_info_sp->GetStopReason();
81  switch (reason) {
82  case eStopReasonInvalid:
83  case eStopReasonNone:
84  // This
87  return false;
88 
91  if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
92  // If we are going to stop for a breakpoint, then unship the other
93  // plans at this point. Don't force the discard, however, so Master
94  // plans can stay in place if they want to.
95  LLDB_LOGF(
96  log,
97  "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
98  " (breakpoint hit.)",
99  m_tid);
100  GetThread().DiscardThreadPlans(false);
101  return 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 we
105  // will post the stopped & running, but the stopped event will get marked
106  // with "restarted" so the UI will know to wait and expect the consequent
107  // "running".
108  if (stop_info_sp->ShouldNotify(event_ptr)) {
111  } else {
114  }
115  return false;
116 
117  // TODO: the break below was missing, was this intentional??? If so
118  // please mention it
119  break;
120 
122  // If we crashed, discard thread plans and stop. Don't force the
123  // discard, however, since on rerun the target may clean up this
124  // exception and continue normally from there.
125  LLDB_LOGF(
126  log,
127  "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
128  " (exception: %s)",
129  m_tid, stop_info_sp->GetDescription());
130  GetThread().DiscardThreadPlans(false);
131  return true;
132 
133  case eStopReasonExec:
134  // If we crashed, discard thread plans and stop. Don't force the
135  // discard, however, since on rerun the target may clean up this
136  // exception and continue normally from there.
137  LLDB_LOGF(
138  log,
139  "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
140  " (exec.)",
141  m_tid);
142  GetThread().DiscardThreadPlans(false);
143  return true;
144 
146  case eStopReasonSignal:
147  if (stop_info_sp->ShouldStop(event_ptr)) {
148  LLDB_LOGF(
149  log,
150  "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
151  " (signal: %s)",
152  m_tid, stop_info_sp->GetDescription());
153  GetThread().DiscardThreadPlans(false);
154  return true;
155  } else {
156  // We're not going to stop, but while we are here, let's figure out
157  // whether to report this.
158  if (stop_info_sp->ShouldNotify(event_ptr))
160  else
162  }
163  return false;
164 
165  default:
166  return true;
167  }
168 
169  } else {
172  }
173 
174  // If there's no explicit reason to stop, then we will continue.
175  return false;
176 }
177 
178 bool ThreadPlanBase::StopOthers() { return false; }
179 
181 
182 bool ThreadPlanBase::WillStop() { return true; }
183 
185  bool current_plan) {
186  // Reset these to the default values so we don't set them wrong, then not get
187  // asked for a while, then return the wrong answer.
190  return true;
191 }
192 
193 // The base plan is never done.
195  // The base plan is never done.
196  return false;
197 }
lldb_private::Thread::DiscardThreadPlans
void DiscardThreadPlans(bool force)
Discards the plans queued on the plan stack of the current thread.
Definition: Thread.cpp:1204
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:48
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:41
lldb_private::ThreadPlanBase::DoPlanExplainsStop
bool DoPlanExplainsStop(Event *event_ptr) override
Definition: ThreadPlanBase.cpp:54
lldb_private::ThreadProperties::GetTraceEnabledState
bool GetTraceEnabledState() const
Definition: Thread.cpp:124
lldb_private::Event
Definition: Event.h:180
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:526
lldb_private::ThreadPlanBase::WillStop
bool WillStop() override
Definition: ThreadPlanBase.cpp:182
lldb::eStopReasonThreadExiting
@ eStopReasonThreadExiting
Definition: lldb-enumerations.h:249
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
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:184
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::SetIsMasterPlan
bool SetIsMasterPlan(bool value)
Definition: ThreadPlan.h:391
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ThreadPlanBase::MischiefManaged
bool MischiefManaged() override
Definition: ThreadPlanBase.cpp:194
lldb_private::ThreadPlan
Definition: ThreadPlan.h:282
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:60
lldb::eStopReasonNone
@ eStopReasonNone
Definition: lldb-enumerations.h:241
lldb_private::ThreadPlanAssemblyTracer
Definition: ThreadPlanTracer.h:71
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb::eStopReasonSignal
@ eStopReasonSignal
Definition: lldb-enumerations.h:245
lldb_private::Thread::GetStopInfo
lldb::StopInfoSP GetStopInfo()
Definition: Thread.cpp:332
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:52
lldb_private::ThreadPlanBase::ShouldStop
bool ShouldStop(Event *event_ptr) override
Definition: ThreadPlanBase.cpp:72
StopInfo.h
lldb_private::ThreadPlan::m_report_stop_vote
Vote m_report_stop_vote
Definition: ThreadPlan.h:525
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:60
lldb_private::ThreadPlan::SetThreadPlanTracer
void SetThreadPlanTracer(lldb::ThreadPlanTracerSP new_tracer_sp)
Definition: ThreadPlan.h:432
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:178
Breakpoint.h
LIBLLDB_LOG_STEP
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
lldb_private::ThreadPlan::m_tid
lldb::tid_t m_tid
Definition: ThreadPlan.h:524
BreakpointSite.h
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
Stream.h
lldb_private::Log
Definition: Log.h:49
lldb_private::ThreadPlanBase::GetPlanRunState
lldb::StateType GetPlanRunState() override
Definition: ThreadPlanBase.cpp:180
lldb_private::ThreadPlan::GetPrivateStopInfo
lldb::StopInfoSP GetPrivateStopInfo()
Definition: ThreadPlan.h:510
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
lldb_private::ThreadPlan::TracerExplainsStop
bool TracerExplainsStop()
Definition: ThreadPlan.h:351
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:539