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/lldb-public.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Core/StructuredData.h"
23 namespace lldb_private {
27 friend class Process::ProcessEventData;
28 friend class ThreadPlanBase;
31 //------------------------------------------------------------------
32 // Constructors and Destructors
33 //------------------------------------------------------------------
34 StopInfo (Thread &thread, uint64_t value);
45 SetThread (const lldb::ThreadSP &thread_sp)
47 m_thread_wp = thread_sp;
53 return m_thread_wp.lock();
56 // The value of the StopInfo depends on the StopReason.
58 // ----------------------------------------------
59 // eStopReasonBreakpoint BreakpointSiteID
60 // eStopReasonSignal Signal number
61 // eStopReasonWatchpoint WatchpointLocationID
62 // eStopReasonPlanComplete No significance
70 virtual lldb::StopReason
71 GetStopReason () const = 0;
73 // ShouldStopSynchronous will get called before any thread plans are consulted, and if it says we should
74 // resume the target, then we will just immediately resume. This should not run any code in or resume the
78 ShouldStopSynchronous (Event *event_ptr)
84 OverrideShouldNotify (bool override_value)
86 m_override_should_notify = override_value ? eLazyBoolYes : eLazyBoolNo;
89 // If should stop returns false, check if we should notify of this event
91 ShouldNotify (Event *event_ptr)
93 if (m_override_should_notify == eLazyBoolCalculate)
94 return DoShouldNotify (event_ptr);
96 return m_override_should_notify == eLazyBoolYes;
100 WillResume (lldb::StateType resume_state)
102 // By default, don't do anything
108 return m_description.c_str();
112 SetDescription (const char *desc_cstr)
114 if (desc_cstr && desc_cstr[0])
115 m_description.assign (desc_cstr);
117 m_description.clear();
121 IsValidForOperatingSystemThread (Thread &thread)
126 // Sometimes the thread plan logic will know that it wants a given stop to stop or not,
127 // regardless of what the ordinary logic for that StopInfo would dictate. The main example
128 // of this is the ThreadPlanCallFunction, which for instance knows - based on how that particular
129 // expression was executed - whether it wants all breakpoints to auto-continue or not.
130 // Use OverrideShouldStop on the StopInfo to implement this.
133 OverrideShouldStop (bool override_value)
135 m_override_should_stop = override_value ? eLazyBoolYes : eLazyBoolNo;
139 GetOverrideShouldStop()
141 return m_override_should_stop != eLazyBoolCalculate;
145 GetOverriddenShouldStopValue ()
147 return m_override_should_stop == eLazyBoolYes;
150 StructuredData::ObjectSP
153 return m_extended_info;
156 static lldb::StopInfoSP
157 CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id);
159 // This creates a StopInfo for the thread where the should_stop is already set, and won't be recalculated.
160 static lldb::StopInfoSP
161 CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id, bool should_stop);
163 static lldb::StopInfoSP
164 CreateStopReasonWithWatchpointID (Thread &thread, lldb::break_id_t watch_id, lldb::addr_t watch_hit_addr = LLDB_INVALID_ADDRESS);
166 static lldb::StopInfoSP
167 CreateStopReasonWithSignal (Thread &thread, int signo, const char *description = nullptr);
169 static lldb::StopInfoSP
170 CreateStopReasonToTrace (Thread &thread);
172 static lldb::StopInfoSP
173 CreateStopReasonWithPlan (lldb::ThreadPlanSP &plan,
174 lldb::ValueObjectSP return_valobj_sp,
175 lldb::ExpressionVariableSP expression_variable_sp);
177 static lldb::StopInfoSP
178 CreateStopReasonWithException (Thread &thread, const char *description);
180 static lldb::StopInfoSP
181 CreateStopReasonWithExec (Thread &thread);
183 static lldb::ValueObjectSP
184 GetReturnValueObject (lldb::StopInfoSP &stop_info_sp);
186 static lldb::ExpressionVariableSP
187 GetExpressionVariable (lldb::StopInfoSP &stop_info_sp);
190 // Perform any action that is associated with this stop. This is done as the
191 // Event is removed from the event queue. ProcessEventData::DoOnRemoval does the job.
194 PerformAction (Event *event_ptr)
199 DoShouldNotify (Event *event_ptr)
204 // Stop the thread by default. Subclasses can override this to allow
205 // the thread to continue if desired. The ShouldStop method should not do anything
206 // that might run code. If you need to run code when deciding whether to stop
207 // at this StopInfo, that must be done in the PerformAction.
208 // The PerformAction will always get called before the ShouldStop. This is done by the
209 // ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs to consult this later on.
211 ShouldStop (Event *event_ptr)
216 //------------------------------------------------------------------
217 // Classes that inherit from StackID can see and modify these
218 //------------------------------------------------------------------
219 lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason.
220 uint32_t m_stop_id; // The process stop ID for which this stop info is valid
221 uint32_t m_resume_id; // This is the resume ID when we made this stop ID.
222 uint64_t m_value; // A generic value that can be used for things pertaining to this stop info
223 std::string m_description; // A textual description describing this stop.
224 LazyBool m_override_should_notify;
225 LazyBool m_override_should_stop;
227 StructuredData::ObjectSP m_extended_info; // The extended info for this stop info
229 // This determines whether the target has run since this stop info.
230 // N.B. running to evaluate a user expression does not count.
231 bool HasTargetRunSinceMe ();
233 // MakeStopInfoValid is necessary to allow saved stop infos to resurrect themselves as valid.
234 // It should only be used by Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
235 // needed for before-the-fact watchpoints does not prevent us from stopping
237 MakeStopInfoValid ();
242 DISALLOW_COPY_AND_ASSIGN (StopInfo);
245 } // namespace lldb_private
247 #endif // liblldb_StopInfo_h_