LLDB  mainline
StopInfo.h
Go to the documentation of this file.
1 //===-- StopInfo.h ----------------------------------------------*- C++ -*-===//
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 
9 #ifndef LLDB_TARGET_STOPINFO_H
10 #define LLDB_TARGET_STOPINFO_H
11 
12 #include <string>
13 
14 #include "lldb/Target/Process.h"
16 #include "lldb/lldb-public.h"
17 
18 namespace lldb_private {
19 
20 class StopInfo {
22  friend class ThreadPlanBase;
23 
24 public:
25  // Constructors and Destructors
26  StopInfo(Thread &thread, uint64_t value);
27 
28  virtual ~StopInfo() = default;
29 
30  bool IsValid() const;
31 
32  void SetThread(const lldb::ThreadSP &thread_sp) { m_thread_wp = thread_sp; }
33 
34  lldb::ThreadSP GetThread() const { return m_thread_wp.lock(); }
35 
36  // The value of the StopInfo depends on the StopReason.
37  //
38  // StopReason Meaning
39  // ------------------------------------------------
40  // eStopReasonBreakpoint BreakpointSiteID
41  // eStopReasonSignal Signal number
42  // eStopReasonWatchpoint WatchpointLocationID
43  // eStopReasonPlanComplete No significance
44 
45  uint64_t GetValue() const { return m_value; }
46 
47  virtual lldb::StopReason GetStopReason() const = 0;
48 
49  // ShouldStopSynchronous will get called before any thread plans are
50  // consulted, and if it says we should resume the target, then we will just
51  // immediately resume. This should not run any code in or resume the target.
52 
53  virtual bool ShouldStopSynchronous(Event *event_ptr) { return true; }
54 
55  void OverrideShouldNotify(bool override_value) {
57  }
58 
59  // If should stop returns false, check if we should notify of this event
60  virtual bool ShouldNotify(Event *event_ptr) {
62  return DoShouldNotify(event_ptr);
63  else
65  }
66 
67  virtual void WillResume(lldb::StateType resume_state) {
68  // By default, don't do anything
69  }
70 
71  virtual const char *GetDescription() { return m_description.c_str(); }
72 
73  virtual void SetDescription(const char *desc_cstr) {
74  if (desc_cstr && desc_cstr[0])
75  m_description.assign(desc_cstr);
76  else
77  m_description.clear();
78  }
79 
80  virtual bool IsValidForOperatingSystemThread(Thread &thread) { return true; }
81 
82  // Sometimes the thread plan logic will know that it wants a given stop to
83  // stop or not, regardless of what the ordinary logic for that StopInfo would
84  // dictate. The main example of this is the ThreadPlanCallFunction, which
85  // for instance knows - based on how that particular expression was executed
86  // - whether it wants all breakpoints to auto-continue or not. Use
87  // OverrideShouldStop on the StopInfo to implement this.
88 
89  void OverrideShouldStop(bool override_value) {
90  m_override_should_stop = override_value ? eLazyBoolYes : eLazyBoolNo;
91  }
92 
95  }
96 
99  }
100 
102 
103  static lldb::StopInfoSP
105  lldb::break_id_t break_id);
106 
107  // This creates a StopInfo for the thread where the should_stop is already
108  // set, and won't be recalculated.
109  static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(
110  Thread &thread, lldb::break_id_t break_id, bool should_stop);
111 
112  static lldb::StopInfoSP CreateStopReasonWithWatchpointID(
113  Thread &thread, lldb::break_id_t watch_id,
114  lldb::addr_t watch_hit_addr = LLDB_INVALID_ADDRESS);
115 
116  static lldb::StopInfoSP
117  CreateStopReasonWithSignal(Thread &thread, int signo,
118  const char *description = nullptr);
119 
120  static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread);
121 
122  static lldb::StopInfoSP
123  CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan,
124  lldb::ValueObjectSP return_valobj_sp,
125  lldb::ExpressionVariableSP expression_variable_sp);
126 
127  static lldb::StopInfoSP
128  CreateStopReasonWithException(Thread &thread, const char *description);
129 
130  static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread);
131 
132  static lldb::StopInfoSP
133  CreateStopReasonProcessorTrace(Thread &thread, const char *description);
134 
135  static lldb::StopInfoSP CreateStopReasonFork(Thread &thread,
136  lldb::pid_t child_pid,
137  lldb::tid_t child_tid);
138 
139  static lldb::StopInfoSP CreateStopReasonVFork(Thread &thread,
140  lldb::pid_t child_pid,
141  lldb::tid_t child_tid);
142 
143  static lldb::StopInfoSP CreateStopReasonVForkDone(Thread &thread);
144 
145  static lldb::ValueObjectSP
146  GetReturnValueObject(lldb::StopInfoSP &stop_info_sp);
147 
148  static lldb::ExpressionVariableSP
149  GetExpressionVariable(lldb::StopInfoSP &stop_info_sp);
150 
151  static lldb::ValueObjectSP
152  GetCrashingDereference(lldb::StopInfoSP &stop_info_sp,
153  lldb::addr_t *crashing_address = nullptr);
154 
155 protected:
156  // Perform any action that is associated with this stop. This is done as the
157  // Event is removed from the event queue. ProcessEventData::DoOnRemoval does
158  // the job.
159 
160  virtual void PerformAction(Event *event_ptr) {}
161 
162  virtual bool DoShouldNotify(Event *event_ptr) { return false; }
163 
164  // Stop the thread by default. Subclasses can override this to allow the
165  // thread to continue if desired. The ShouldStop method should not do
166  // anything that might run code. If you need to run code when deciding
167  // whether to stop at this StopInfo, that must be done in the PerformAction.
168  // The PerformAction will always get called before the ShouldStop. This is
169  // done by the ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs
170  // to consult this later on.
171  virtual bool ShouldStop(Event *event_ptr) { return true; }
172 
173  // Classes that inherit from StackID can see and modify these
174  lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason.
175  uint32_t m_stop_id; // The process stop ID for which this stop info is valid
176  uint32_t m_resume_id; // This is the resume ID when we made this stop ID.
177  uint64_t m_value; // A generic value that can be used for things pertaining to
178  // this stop info
179  std::string m_description; // A textual description describing this stop.
182 
184  m_extended_info; // The extended info for this stop info
185 
186  // This determines whether the target has run since this stop info. N.B.
187  // running to evaluate a user expression does not count.
188  bool HasTargetRunSinceMe();
189 
190  // MakeStopInfoValid is necessary to allow saved stop infos to resurrect
191  // themselves as valid. It should only be used by
192  // Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
193  // needed for before-the-fact watchpoints does not prevent us from stopping
194  void MakeStopInfoValid();
195 
196 private:
197  friend class Thread;
198 
199  StopInfo(const StopInfo &) = delete;
200  const StopInfo &operator=(const StopInfo &) = delete;
201 };
202 
203 } // namespace lldb_private
204 
205 #endif // LLDB_TARGET_STOPINFO_H
lldb_private::StopInfo::m_override_should_notify
LazyBool m_override_should_notify
Definition: StopInfo.h:180
lldb_private::StopInfo::SetThread
void SetThread(const lldb::ThreadSP &thread_sp)
Definition: StopInfo.h:32
lldb_private::StopInfo::operator=
const StopInfo & operator=(const StopInfo &)=delete
lldb-public.h
lldb_private::Event
Definition: Event.h:180
lldb_private::StopInfo::m_stop_id
uint32_t m_stop_id
Definition: StopInfo.h:175
StructuredData.h
lldb_private::StopInfo::GetExtendedInfo
StructuredData::ObjectSP GetExtendedInfo()
Definition: StopInfo.h:101
lldb_private::StopInfo::StopInfo
StopInfo(Thread &thread, uint64_t value)
Definition: StopInfo.cpp:30
lldb_private::eLazyBoolYes
@ eLazyBoolYes
Definition: lldb-private-enumerations.h:115
lldb_private::StopInfo::CreateStopReasonWithSignal
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr)
Definition: StopInfo.cpp:1273
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
lldb_private::StopInfo::ShouldStop
virtual bool ShouldStop(Event *event_ptr)
Definition: StopInfo.h:171
lldb_private::StopInfo::CreateStopReasonToTrace
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
Definition: StopInfo.cpp:1279
lldb_private::StopInfo::~StopInfo
virtual ~StopInfo()=default
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::LazyBool
LazyBool
Definition: lldb-private-enumerations.h:115
lldb_private::StopInfo::GetValue
uint64_t GetValue() const
Definition: StopInfo.h:45
Process.h
lldb_private::StopInfo::m_resume_id
uint32_t m_resume_id
Definition: StopInfo.h:176
lldb_private::StopInfo::m_value
uint64_t m_value
Definition: StopInfo.h:177
lldb_private::StopInfo::GetThread
lldb::ThreadSP GetThread() const
Definition: StopInfo.h:34
lldb_private::StopInfo::CreateStopReasonFork
static lldb::StopInfoSP CreateStopReasonFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1304
lldb_private::Thread
Definition: Thread.h:60
lldb_private::StopInfo::m_thread_wp
lldb::ThreadWP m_thread_wp
Definition: StopInfo.h:174
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::Process::ProcessEventData
Definition: Process.h:403
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb_private::StopInfo::OverrideShouldStop
void OverrideShouldStop(bool override_value)
Definition: StopInfo.h:89
lldb_private::StopInfo::CreateStopReasonWithWatchpointID
static lldb::StopInfoSP CreateStopReasonWithWatchpointID(Thread &thread, lldb::break_id_t watch_id, lldb::addr_t watch_hit_addr=LLDB_INVALID_ADDRESS)
Definition: StopInfo.cpp:1268
lldb_private::ThreadPlanBase
Definition: ThreadPlanBase.h:23
lldb_private::StopInfo::DoShouldNotify
virtual bool DoShouldNotify(Event *event_ptr)
Definition: StopInfo.h:162
lldb_private::StopInfo::CreateStopReasonWithPlan
static lldb::StopInfoSP CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp, lldb::ExpressionVariableSP expression_variable_sp)
Definition: StopInfo.cpp:1283
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::StopInfo::HasTargetRunSinceMe
bool HasTargetRunSinceMe()
Definition: StopInfo.cpp:52
lldb_private::StopInfo::IsValidForOperatingSystemThread
virtual bool IsValidForOperatingSystemThread(Thread &thread)
Definition: StopInfo.h:80
lldb_private::StopInfo::GetDescription
virtual const char * GetDescription()
Definition: StopInfo.h:71
lldb_private::StopInfo::GetOverriddenShouldStopValue
bool GetOverriddenShouldStopValue()
Definition: StopInfo.h:97
lldb_private::StopInfo::m_override_should_stop
LazyBool m_override_should_stop
Definition: StopInfo.h:181
lldb_private::StopInfo::GetStopReason
virtual lldb::StopReason GetStopReason() const =0
lldb_private::StopInfo::WillResume
virtual void WillResume(lldb::StateType resume_state)
Definition: StopInfo.h:67
lldb_private::StopInfo::CreateStopReasonWithExec
static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread)
Definition: StopInfo.cpp:1300
uint32_t
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
lldb_private::StopInfo::IsValid
bool IsValid() const
Definition: StopInfo.cpp:37
lldb_private::StopInfo::CreateStopReasonProcessorTrace
static lldb::StopInfoSP CreateStopReasonProcessorTrace(Thread &thread, const char *description)
Definition: StopInfo.cpp:1295
lldb_private::StopInfo::GetOverrideShouldStop
bool GetOverrideShouldStop()
Definition: StopInfo.h:93
lldb_private::StopInfo::CreateStopReasonVForkDone
static lldb::StopInfoSP CreateStopReasonVForkDone(Thread &thread)
Definition: StopInfo.cpp:1317
lldb_private::StopInfo::PerformAction
virtual void PerformAction(Event *event_ptr)
Definition: StopInfo.h:160
lldb_private::StopInfo::GetExpressionVariable
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1331
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::StopInfo::MakeStopInfoValid
void MakeStopInfoValid()
Definition: StopInfo.cpp:44
lldb_private::StopInfo::ShouldStopSynchronous
virtual bool ShouldStopSynchronous(Event *event_ptr)
Definition: StopInfo.h:53
lldb_private::StopInfo::m_description
std::string m_description
Definition: StopInfo.h:179
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::StopInfo::GetCrashingDereference
static lldb::ValueObjectSP GetCrashingDereference(lldb::StopInfoSP &stop_info_sp, lldb::addr_t *crashing_address=nullptr)
Definition: StopInfo.cpp:1342
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
lldb_private::StopInfo
Definition: StopInfo.h:20
lldb_private::StopInfo::m_extended_info
StructuredData::ObjectSP m_extended_info
Definition: StopInfo.h:184
lldb_private::StopInfo::CreateStopReasonVFork
static lldb::StopInfoSP CreateStopReasonVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1311
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb_private::StopInfo::CreateStopReasonWithBreakpointSiteID
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
Definition: StopInfo.cpp:1256
lldb_private::StopInfo::GetReturnValueObject
static lldb::ValueObjectSP GetReturnValueObject(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1321
lldb_private::StopInfo::CreateStopReasonWithException
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
Definition: StopInfo.cpp:1290
lldb_private::StopInfo::SetDescription
virtual void SetDescription(const char *desc_cstr)
Definition: StopInfo.h:73
lldb_private::StopInfo::ShouldNotify
virtual bool ShouldNotify(Event *event_ptr)
Definition: StopInfo.h:60
lldb_private::StopInfo::OverrideShouldNotify
void OverrideShouldNotify(bool override_value)
Definition: StopInfo.h:55
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86