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_
17 // Other libraries and framework includes
19 #include "lldb/Target/Process.h"
20 #include "lldb/Utility/StructuredData.h"
21 #include "lldb/lldb-public.h"
23 namespace lldb_private {
26 friend class Process::ProcessEventData;
27 friend class ThreadPlanBase;
30 //------------------------------------------------------------------
31 // Constructors and Destructors
32 //------------------------------------------------------------------
33 StopInfo(Thread &thread, uint64_t value);
35 virtual ~StopInfo() {}
39 void SetThread(const lldb::ThreadSP &thread_sp) { m_thread_wp = thread_sp; }
41 lldb::ThreadSP GetThread() const { return m_thread_wp.lock(); }
43 // The value of the StopInfo depends on the StopReason.
45 // ----------------------------------------------
46 // eStopReasonBreakpoint BreakpointSiteID
47 // eStopReasonSignal Signal number
48 // eStopReasonWatchpoint WatchpointLocationID
49 // eStopReasonPlanComplete No significance
51 uint64_t GetValue() const { return m_value; }
53 virtual lldb::StopReason GetStopReason() const = 0;
55 // ShouldStopSynchronous will get called before any thread plans are
56 // consulted, and if it says we should
57 // resume the target, then we will just immediately resume. This should not
58 // run any code in or resume the
61 virtual bool ShouldStopSynchronous(Event *event_ptr) { return true; }
63 void OverrideShouldNotify(bool override_value) {
64 m_override_should_notify = override_value ? eLazyBoolYes : eLazyBoolNo;
67 // If should stop returns false, check if we should notify of this event
68 virtual bool ShouldNotify(Event *event_ptr) {
69 if (m_override_should_notify == eLazyBoolCalculate)
70 return DoShouldNotify(event_ptr);
72 return m_override_should_notify == eLazyBoolYes;
75 virtual void WillResume(lldb::StateType resume_state) {
76 // By default, don't do anything
79 virtual const char *GetDescription() { return m_description.c_str(); }
81 virtual void SetDescription(const char *desc_cstr) {
82 if (desc_cstr && desc_cstr[0])
83 m_description.assign(desc_cstr);
85 m_description.clear();
88 virtual bool IsValidForOperatingSystemThread(Thread &thread) { return true; }
90 // Sometimes the thread plan logic will know that it wants a given stop to
92 // regardless of what the ordinary logic for that StopInfo would dictate. The
94 // of this is the ThreadPlanCallFunction, which for instance knows - based on
95 // how that particular
96 // expression was executed - whether it wants all breakpoints to auto-continue
98 // Use OverrideShouldStop on the StopInfo to implement this.
100 void OverrideShouldStop(bool override_value) {
101 m_override_should_stop = override_value ? eLazyBoolYes : eLazyBoolNo;
104 bool GetOverrideShouldStop() {
105 return m_override_should_stop != eLazyBoolCalculate;
108 bool GetOverriddenShouldStopValue() {
109 return m_override_should_stop == eLazyBoolYes;
112 StructuredData::ObjectSP GetExtendedInfo() { return m_extended_info; }
114 static lldb::StopInfoSP
115 CreateStopReasonWithBreakpointSiteID(Thread &thread,
116 lldb::break_id_t break_id);
118 // This creates a StopInfo for the thread where the should_stop is already
119 // set, and won't be recalculated.
120 static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(
121 Thread &thread, lldb::break_id_t break_id, bool should_stop);
123 static lldb::StopInfoSP CreateStopReasonWithWatchpointID(
124 Thread &thread, lldb::break_id_t watch_id,
125 lldb::addr_t watch_hit_addr = LLDB_INVALID_ADDRESS);
127 static lldb::StopInfoSP
128 CreateStopReasonWithSignal(Thread &thread, int signo,
129 const char *description = nullptr);
131 static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread);
133 static lldb::StopInfoSP
134 CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan,
135 lldb::ValueObjectSP return_valobj_sp,
136 lldb::ExpressionVariableSP expression_variable_sp);
138 static lldb::StopInfoSP
139 CreateStopReasonWithException(Thread &thread, const char *description);
141 static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread);
143 static lldb::ValueObjectSP
144 GetReturnValueObject(lldb::StopInfoSP &stop_info_sp);
146 static lldb::ExpressionVariableSP
147 GetExpressionVariable(lldb::StopInfoSP &stop_info_sp);
149 static lldb::ValueObjectSP
150 GetCrashingDereference(lldb::StopInfoSP &stop_info_sp,
151 lldb::addr_t *crashing_address = nullptr);
154 // Perform any action that is associated with this stop. This is done as the
155 // Event is removed from the event queue. ProcessEventData::DoOnRemoval does
158 virtual void PerformAction(Event *event_ptr) {}
160 virtual bool DoShouldNotify(Event *event_ptr) { return false; }
162 // Stop the thread by default. Subclasses can override this to allow
163 // the thread to continue if desired. The ShouldStop method should not do
165 // that might run code. If you need to run code when deciding whether to stop
166 // at this StopInfo, that must be done in the PerformAction.
167 // The PerformAction will always get called before the ShouldStop. This is
169 // ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs to consult
171 virtual bool ShouldStop(Event *event_ptr) { return true; }
173 //------------------------------------------------------------------
174 // Classes that inherit from StackID can see and modify these
175 //------------------------------------------------------------------
176 lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason.
177 uint32_t m_stop_id; // The process stop ID for which this stop info is valid
178 uint32_t m_resume_id; // This is the resume ID when we made this stop ID.
179 uint64_t m_value; // A generic value that can be used for things pertaining to
181 std::string m_description; // A textual description describing this stop.
182 LazyBool m_override_should_notify;
183 LazyBool m_override_should_stop;
185 StructuredData::ObjectSP
186 m_extended_info; // The extended info for this stop info
188 // This determines whether the target has run since this stop info.
189 // N.B. running to evaluate a user expression does not count.
190 bool HasTargetRunSinceMe();
192 // MakeStopInfoValid is necessary to allow saved stop infos to resurrect
193 // themselves as valid.
194 // It should only be used by Thread::RestoreThreadStateFromCheckpoint and to
195 // make sure the one-step
196 // needed for before-the-fact watchpoints does not prevent us from stopping
197 void MakeStopInfoValid();
202 DISALLOW_COPY_AND_ASSIGN(StopInfo);
205 } // namespace lldb_private
207 #endif // liblldb_StopInfo_h_