1 //===-- StopInfo.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_StopInfo_h_
11 #define liblldb_StopInfo_h_
15 #include "lldb/Target/Process.h"
16 #include "lldb/Utility/StructuredData.h"
17 #include "lldb/lldb-public.h"
19 namespace lldb_private {
22 friend class Process::ProcessEventData;
23 friend class ThreadPlanBase;
26 //------------------------------------------------------------------
27 // Constructors and Destructors
28 //------------------------------------------------------------------
29 StopInfo(Thread &thread, uint64_t value);
31 virtual ~StopInfo() {}
35 void SetThread(const lldb::ThreadSP &thread_sp) { m_thread_wp = thread_sp; }
37 lldb::ThreadSP GetThread() const { return m_thread_wp.lock(); }
39 // The value of the StopInfo depends on the StopReason. StopReason
40 // Meaning ----------------------------------------------
41 // eStopReasonBreakpoint BreakpointSiteID eStopReasonSignal
42 // Signal number eStopReasonWatchpoint WatchpointLocationID
43 // eStopReasonPlanComplete No significance
45 uint64_t GetValue() const { return m_value; }
47 virtual lldb::StopReason GetStopReason() const = 0;
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.
53 virtual bool ShouldStopSynchronous(Event *event_ptr) { return true; }
55 void OverrideShouldNotify(bool override_value) {
56 m_override_should_notify = override_value ? eLazyBoolYes : eLazyBoolNo;
59 // If should stop returns false, check if we should notify of this event
60 virtual bool ShouldNotify(Event *event_ptr) {
61 if (m_override_should_notify == eLazyBoolCalculate)
62 return DoShouldNotify(event_ptr);
64 return m_override_should_notify == eLazyBoolYes;
67 virtual void WillResume(lldb::StateType resume_state) {
68 // By default, don't do anything
71 virtual const char *GetDescription() { return m_description.c_str(); }
73 virtual void SetDescription(const char *desc_cstr) {
74 if (desc_cstr && desc_cstr[0])
75 m_description.assign(desc_cstr);
77 m_description.clear();
80 virtual bool IsValidForOperatingSystemThread(Thread &thread) { return true; }
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.
89 void OverrideShouldStop(bool override_value) {
90 m_override_should_stop = override_value ? eLazyBoolYes : eLazyBoolNo;
93 bool GetOverrideShouldStop() {
94 return m_override_should_stop != eLazyBoolCalculate;
97 bool GetOverriddenShouldStopValue() {
98 return m_override_should_stop == eLazyBoolYes;
101 StructuredData::ObjectSP GetExtendedInfo() { return m_extended_info; }
103 static lldb::StopInfoSP
104 CreateStopReasonWithBreakpointSiteID(Thread &thread,
105 lldb::break_id_t break_id);
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);
112 static lldb::StopInfoSP CreateStopReasonWithWatchpointID(
113 Thread &thread, lldb::break_id_t watch_id,
114 lldb::addr_t watch_hit_addr = LLDB_INVALID_ADDRESS);
116 static lldb::StopInfoSP
117 CreateStopReasonWithSignal(Thread &thread, int signo,
118 const char *description = nullptr);
120 static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread);
122 static lldb::StopInfoSP
123 CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan,
124 lldb::ValueObjectSP return_valobj_sp,
125 lldb::ExpressionVariableSP expression_variable_sp);
127 static lldb::StopInfoSP
128 CreateStopReasonWithException(Thread &thread, const char *description);
130 static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread);
132 static lldb::ValueObjectSP
133 GetReturnValueObject(lldb::StopInfoSP &stop_info_sp);
135 static lldb::ExpressionVariableSP
136 GetExpressionVariable(lldb::StopInfoSP &stop_info_sp);
138 static lldb::ValueObjectSP
139 GetCrashingDereference(lldb::StopInfoSP &stop_info_sp,
140 lldb::addr_t *crashing_address = nullptr);
143 // Perform any action that is associated with this stop. This is done as the
144 // Event is removed from the event queue. ProcessEventData::DoOnRemoval does
147 virtual void PerformAction(Event *event_ptr) {}
149 virtual bool DoShouldNotify(Event *event_ptr) { return false; }
151 // Stop the thread by default. Subclasses can override this to allow the
152 // thread to continue if desired. The ShouldStop method should not do
153 // anything that might run code. If you need to run code when deciding
154 // whether to stop at this StopInfo, that must be done in the PerformAction.
155 // The PerformAction will always get called before the ShouldStop. This is
156 // done by the ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs
157 // to consult this later on.
158 virtual bool ShouldStop(Event *event_ptr) { return true; }
160 //------------------------------------------------------------------
161 // Classes that inherit from StackID can see and modify these
162 //------------------------------------------------------------------
163 lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason.
164 uint32_t m_stop_id; // The process stop ID for which this stop info is valid
165 uint32_t m_resume_id; // This is the resume ID when we made this stop ID.
166 uint64_t m_value; // A generic value that can be used for things pertaining to
168 std::string m_description; // A textual description describing this stop.
169 LazyBool m_override_should_notify;
170 LazyBool m_override_should_stop;
172 StructuredData::ObjectSP
173 m_extended_info; // The extended info for this stop info
175 // This determines whether the target has run since this stop info. N.B.
176 // running to evaluate a user expression does not count.
177 bool HasTargetRunSinceMe();
179 // MakeStopInfoValid is necessary to allow saved stop infos to resurrect
180 // themselves as valid. It should only be used by
181 // Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
182 // needed for before-the-fact watchpoints does not prevent us from stopping
183 void MakeStopInfoValid();
188 DISALLOW_COPY_AND_ASSIGN(StopInfo);
191 } // namespace lldb_private
193 #endif // liblldb_StopInfo_h_