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
18namespace lldb_private {
19
20class StopInfo : public std::enable_shared_from_this<StopInfo> {
22 friend class ThreadPlanBase;
24
25public:
26 // Constructors and Destructors
27 StopInfo(Thread &thread, uint64_t value);
28
29 virtual ~StopInfo() = default;
30
31 bool IsValid() const;
32
33 void SetThread(const lldb::ThreadSP &thread_sp) { m_thread_wp = thread_sp; }
34
35 lldb::ThreadSP GetThread() const { return m_thread_wp.lock(); }
36
37 // The value of the StopInfo depends on the StopReason.
38 //
39 // StopReason Meaning
40 // ------------------------------------------------
41 // eStopReasonBreakpoint BreakpointSiteID
42 // eStopReasonSignal Signal number
43 // eStopReasonWatchpoint WatchpointLocationID
44 // eStopReasonPlanComplete No significance
45
46 uint64_t GetValue() const { return m_value; }
47
48 virtual lldb::StopReason GetStopReason() const = 0;
49
50 // ShouldStopSynchronous will get called before any thread plans are
51 // consulted, and if it says we should resume the target, then we will just
52 // immediately resume. This should not run any code in or resume the target.
53
54 virtual bool ShouldStopSynchronous(Event *event_ptr) { return true; }
55
56 void OverrideShouldNotify(bool override_value) {
58 }
59
60 // If should stop returns false, check if we should notify of this event
61 virtual bool ShouldNotify(Event *event_ptr) {
63 return DoShouldNotify(event_ptr);
64 else
66 }
67
68 virtual void WillResume(lldb::StateType resume_state) {
69 // By default, don't do anything
70 }
71
72 virtual const char *GetDescription() { return m_description.c_str(); }
73
74 virtual void SetDescription(const char *desc_cstr) {
75 if (desc_cstr && desc_cstr[0])
76 m_description.assign(desc_cstr);
77 else
78 m_description.clear();
79 }
80
81 /// This gives the StopInfo a chance to suggest a stack frame to select.
82 /// Passing true for inlined_stack will request changes to the inlined
83 /// call stack. Passing false will request changes to the real stack
84 /// frame. The inlined stack gets adjusted before we call into the thread
85 /// plans so they can reason based on the correct values. The real stack
86 /// adjustment is handled after the frame recognizers get a chance to adjust
87 /// the frame.
88 virtual std::optional<uint32_t>
89 GetSuggestedStackFrameIndex(bool inlined_stack) {
90 return {};
91 }
92
93 virtual bool IsValidForOperatingSystemThread(Thread &thread) { return true; }
94
95 /// A Continue operation can result in a false stop event
96 /// before any execution has happened. We need to detect this
97 /// and silently continue again one more time.
98 virtual bool WasContinueInterrupted(Thread &thread) { return false; }
99
100 virtual uint32_t GetStopReasonDataCount() const { return 0; }
101 virtual uint64_t GetStopReasonDataAtIndex(uint32_t idx) {
102 // Handle all the common cases that have no data.
103 return 0;
104 }
105
106 // Sometimes the thread plan logic will know that it wants a given stop to
107 // stop or not, regardless of what the ordinary logic for that StopInfo would
108 // dictate. The main example of this is the ThreadPlanCallFunction, which
109 // for instance knows - based on how that particular expression was executed
110 // - whether it wants all breakpoints to auto-continue or not. Use
111 // OverrideShouldStop on the StopInfo to implement this.
112
113 void OverrideShouldStop(bool override_value) {
115 }
116
120
124
126
127 /// Returns true if this is a stop reason that should be shown to a user when
128 /// viewing the thread with this stop info.
129 virtual bool ShouldShow() const { return IsValid(); }
130
131 /// Returns true if this is a stop reason that should cause a thread to be
132 /// selected when stopping.
133 virtual bool ShouldSelect() const {
135 return reason != lldb::eStopReasonNone &&
137 reason != lldb::eStopReasonInvalid;
138 }
139
140 static lldb::StopInfoSP
142 lldb::break_id_t break_id);
143
144 // This creates a StopInfo for the thread where the should_stop is already
145 // set, and won't be recalculated.
147 Thread &thread, lldb::break_id_t break_id, bool should_stop);
148
149 static lldb::StopInfoSP
151 bool silently_continue = false);
152
153 static lldb::StopInfoSP
154 CreateStopReasonWithSignal(Thread &thread, int signo,
155 const char *description = nullptr,
156 std::optional<int> code = std::nullopt);
157
158 static lldb::StopInfoSP
159 CreateStopReasonWithInterrupt(Thread &thread, int signo,
160 const char *description);
161
163
164 static lldb::StopInfoSP
166 lldb::ValueObjectSP return_valobj_sp,
167 lldb::ExpressionVariableSP expression_variable_sp);
168
169 static lldb::StopInfoSP
170 CreateStopReasonWithException(Thread &thread, const char *description);
171
173
174 static lldb::StopInfoSP
175 CreateStopReasonProcessorTrace(Thread &thread, const char *description);
176
177 // This creates a StopInfo indicating that execution stopped because
178 // it was replaying some recorded execution history, and execution reached
179 // the end of that recorded history.
180 static lldb::StopInfoSP
181 CreateStopReasonHistoryBoundary(Thread &thread, const char *description);
182
184 lldb::pid_t child_pid,
185 lldb::tid_t child_tid);
186
188 lldb::pid_t child_pid,
189 lldb::tid_t child_tid);
190
192
195
198
201 lldb::addr_t *crashing_address = nullptr);
202
203protected:
204 // Perform any action that is associated with this stop. This is done as the
205 // Event is removed from the event queue. ProcessEventData::DoOnRemoval does
206 // the job.
207
208 virtual void PerformAction(Event *event_ptr) {}
209
210 virtual bool DoShouldNotify(Event *event_ptr) { return false; }
211
212 // Stop the thread by default. Subclasses can override this to allow the
213 // thread to continue if desired. The ShouldStop method should not do
214 // anything that might run code. If you need to run code when deciding
215 // whether to stop at this StopInfo, that must be done in the PerformAction.
216 // The PerformAction will always get called before the ShouldStop. This is
217 // done by the ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs
218 // to consult this later on.
219 virtual bool ShouldStop(Event *event_ptr) { return true; }
220
221 // Classes that inherit from StackID can see and modify these
222 lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason.
223 uint32_t m_stop_id; // The process stop ID for which this stop info is valid
224 uint32_t m_resume_id; // This is the resume ID when we made this stop ID.
225 uint64_t m_value; // A generic value that can be used for things pertaining to
226 // this stop info
227 std::string m_description; // A textual description describing this stop.
230
232 m_extended_info; // The extended info for this stop info
233
234 // This determines whether the target has run since this stop info. N.B.
235 // running to evaluate a user expression does not count.
236 bool HasTargetRunSinceMe();
237
238 // MakeStopInfoValid is necessary to allow saved stop infos to resurrect
239 // themselves as valid. It should only be used by
240 // Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
241 // needed for before-the-fact watchpoints does not prevent us from stopping
242 void MakeStopInfoValid();
243
244private:
245 friend class Thread;
246
247 StopInfo(const StopInfo &) = delete;
248 const StopInfo &operator=(const StopInfo &) = delete;
249};
250
251} // namespace lldb_private
252
253#endif // LLDB_TARGET_STOPINFO_H
virtual std::optional< uint32_t > GetSuggestedStackFrameIndex(bool inlined_stack)
This gives the StopInfo a chance to suggest a stack frame to select.
Definition StopInfo.h:89
virtual uint64_t GetStopReasonDataAtIndex(uint32_t idx)
Definition StopInfo.h:101
virtual bool IsValidForOperatingSystemThread(Thread &thread)
Definition StopInfo.h:93
virtual bool ShouldSelect() const
Returns true if this is a stop reason that should cause a thread to be selected when stopping.
Definition StopInfo.h:133
virtual uint32_t GetStopReasonDataCount() const
Definition StopInfo.h:100
std::string m_description
Definition StopInfo.h:227
friend class ThreadPlanReverseContinue
Definition StopInfo.h:23
virtual bool ShouldStopSynchronous(Event *event_ptr)
Definition StopInfo.h:54
static lldb::StopInfoSP CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp, lldb::ExpressionVariableSP expression_variable_sp)
uint64_t GetValue() const
Definition StopInfo.h:46
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
virtual lldb::StopReason GetStopReason() const =0
virtual void PerformAction(Event *event_ptr)
Definition StopInfo.h:208
void OverrideShouldNotify(bool override_value)
Definition StopInfo.h:56
StructuredData::ObjectSP GetExtendedInfo()
Definition StopInfo.h:125
void SetThread(const lldb::ThreadSP &thread_sp)
Definition StopInfo.h:33
static lldb::ValueObjectSP GetReturnValueObject(lldb::StopInfoSP &stop_info_sp)
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
virtual bool WasContinueInterrupted(Thread &thread)
A Continue operation can result in a false stop event before any execution has happened.
Definition StopInfo.h:98
const StopInfo & operator=(const StopInfo &)=delete
StopInfo(const StopInfo &)=delete
static lldb::StopInfoSP CreateStopReasonVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
static lldb::StopInfoSP CreateStopReasonWithInterrupt(Thread &thread, int signo, const char *description)
bool IsValid() const
Definition StopInfo.cpp:41
virtual ~StopInfo()=default
StructuredData::ObjectSP m_extended_info
Definition StopInfo.h:232
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr, std::optional< int > code=std::nullopt)
virtual void WillResume(lldb::StateType resume_state)
Definition StopInfo.h:68
virtual bool ShouldNotify(Event *event_ptr)
Definition StopInfo.h:61
lldb::ThreadSP GetThread() const
Definition StopInfo.h:35
static lldb::StopInfoSP CreateStopReasonFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
static lldb::StopInfoSP CreateStopReasonVForkDone(Thread &thread)
static lldb::StopInfoSP CreateStopReasonWithWatchpointID(Thread &thread, lldb::break_id_t watch_id, bool silently_continue=false)
virtual void SetDescription(const char *desc_cstr)
Definition StopInfo.h:74
virtual const char * GetDescription()
Definition StopInfo.h:72
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
static lldb::StopInfoSP CreateStopReasonHistoryBoundary(Thread &thread, const char *description)
static lldb::ValueObjectSP GetCrashingDereference(lldb::StopInfoSP &stop_info_sp, lldb::addr_t *crashing_address=nullptr)
LazyBool m_override_should_notify
Definition StopInfo.h:228
static lldb::StopInfoSP CreateStopReasonProcessorTrace(Thread &thread, const char *description)
virtual bool DoShouldNotify(Event *event_ptr)
Definition StopInfo.h:210
void OverrideShouldStop(bool override_value)
Definition StopInfo.h:113
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id, bool should_stop)
static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread)
friend class Thread
Definition StopInfo.h:245
StopInfo(Thread &thread, uint64_t value)
Definition StopInfo.cpp:34
lldb::ThreadWP m_thread_wp
Definition StopInfo.h:222
LazyBool m_override_should_stop
Definition StopInfo.h:229
virtual bool ShouldShow() const
Returns true if this is a stop reason that should be shown to a user when viewing the thread with thi...
Definition StopInfo.h:129
bool GetOverriddenShouldStopValue()
Definition StopInfo.h:121
virtual bool ShouldStop(Event *event_ptr)
Definition StopInfo.h:219
friend class ThreadPlanBase
Definition StopInfo.h:22
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
StateType
Process and Thread States.
int32_t break_id_t
Definition lldb-types.h:86
uint64_t pid_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
@ eStopReasonHistoryBoundary
std::weak_ptr< lldb_private::Thread > ThreadWP
uint64_t tid_t
Definition lldb-types.h:84