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;
23
24public:
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 /// This gives the StopInfo a chance to suggest a stack frame to select.
81 /// Passing true for inlined_stack will request changes to the inlined
82 /// call stack. Passing false will request changes to the real stack
83 /// frame. The inlined stack gets adjusted before we call into the thread
84 /// plans so they can reason based on the correct values. The real stack
85 /// adjustment is handled after the frame recognizers get a chance to adjust
86 /// the frame.
87 virtual std::optional<uint32_t>
88 GetSuggestedStackFrameIndex(bool inlined_stack) {
89 return {};
90 }
91
92 virtual bool IsValidForOperatingSystemThread(Thread &thread) { return true; }
93
94 /// A Continue operation can result in a false stop event
95 /// before any execution has happened. We need to detect this
96 /// and silently continue again one more time.
97 virtual bool WasContinueInterrupted(Thread &thread) { return false; }
98
99 // Sometimes the thread plan logic will know that it wants a given stop to
100 // stop or not, regardless of what the ordinary logic for that StopInfo would
101 // dictate. The main example of this is the ThreadPlanCallFunction, which
102 // for instance knows - based on how that particular expression was executed
103 // - whether it wants all breakpoints to auto-continue or not. Use
104 // OverrideShouldStop on the StopInfo to implement this.
105
106 void OverrideShouldStop(bool override_value) {
108 }
109
112 }
113
116 }
117
119
120 static lldb::StopInfoSP
122 lldb::break_id_t break_id);
123
124 // This creates a StopInfo for the thread where the should_stop is already
125 // set, and won't be recalculated.
127 Thread &thread, lldb::break_id_t break_id, bool should_stop);
128
129 static lldb::StopInfoSP
131 bool silently_continue = false);
132
133 static lldb::StopInfoSP
134 CreateStopReasonWithSignal(Thread &thread, int signo,
135 const char *description = nullptr,
136 std::optional<int> code = std::nullopt);
137
138 static lldb::StopInfoSP
139 CreateStopReasonWithInterrupt(Thread &thread, int signo,
140 const char *description);
141
143
144 static lldb::StopInfoSP
146 lldb::ValueObjectSP return_valobj_sp,
147 lldb::ExpressionVariableSP expression_variable_sp);
148
149 static lldb::StopInfoSP
150 CreateStopReasonWithException(Thread &thread, const char *description);
151
153
154 static lldb::StopInfoSP
155 CreateStopReasonProcessorTrace(Thread &thread, const char *description);
156
158 lldb::pid_t child_pid,
159 lldb::tid_t child_tid);
160
162 lldb::pid_t child_pid,
163 lldb::tid_t child_tid);
164
166
169
172
175 lldb::addr_t *crashing_address = nullptr);
176
177protected:
178 // Perform any action that is associated with this stop. This is done as the
179 // Event is removed from the event queue. ProcessEventData::DoOnRemoval does
180 // the job.
181
182 virtual void PerformAction(Event *event_ptr) {}
183
184 virtual bool DoShouldNotify(Event *event_ptr) { return false; }
185
186 // Stop the thread by default. Subclasses can override this to allow the
187 // thread to continue if desired. The ShouldStop method should not do
188 // anything that might run code. If you need to run code when deciding
189 // whether to stop at this StopInfo, that must be done in the PerformAction.
190 // The PerformAction will always get called before the ShouldStop. This is
191 // done by the ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs
192 // to consult this later on.
193 virtual bool ShouldStop(Event *event_ptr) { return true; }
194
195 // Classes that inherit from StackID can see and modify these
196 lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason.
197 uint32_t m_stop_id; // The process stop ID for which this stop info is valid
198 uint32_t m_resume_id; // This is the resume ID when we made this stop ID.
199 uint64_t m_value; // A generic value that can be used for things pertaining to
200 // this stop info
201 std::string m_description; // A textual description describing this stop.
204
206 m_extended_info; // The extended info for this stop info
207
208 // This determines whether the target has run since this stop info. N.B.
209 // running to evaluate a user expression does not count.
210 bool HasTargetRunSinceMe();
211
212 // MakeStopInfoValid is necessary to allow saved stop infos to resurrect
213 // themselves as valid. It should only be used by
214 // Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
215 // needed for before-the-fact watchpoints does not prevent us from stopping
216 void MakeStopInfoValid();
217
218private:
219 friend class Thread;
220
221 StopInfo(const StopInfo &) = delete;
222 const StopInfo &operator=(const StopInfo &) = delete;
223};
224
225} // namespace lldb_private
226
227#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:88
virtual bool IsValidForOperatingSystemThread(Thread &thread)
Definition: StopInfo.h:92
std::string m_description
Definition: StopInfo.h:201
virtual bool ShouldStopSynchronous(Event *event_ptr)
Definition: StopInfo.h:53
static lldb::StopInfoSP CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp, lldb::ExpressionVariableSP expression_variable_sp)
Definition: StopInfo.cpp:1482
uint64_t GetValue() const
Definition: StopInfo.h:45
bool GetOverrideShouldStop()
Definition: StopInfo.h:110
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1530
virtual lldb::StopReason GetStopReason() const =0
virtual void PerformAction(Event *event_ptr)
Definition: StopInfo.h:182
void OverrideShouldNotify(bool override_value)
Definition: StopInfo.h:55
StructuredData::ObjectSP GetExtendedInfo()
Definition: StopInfo.h:118
void SetThread(const lldb::ThreadSP &thread_sp)
Definition: StopInfo.h:32
static lldb::ValueObjectSP GetReturnValueObject(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1520
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
Definition: StopInfo.cpp:1478
virtual bool WasContinueInterrupted(Thread &thread)
A Continue operation can result in a false stop event before any execution has happened.
Definition: StopInfo.h:97
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)
Definition: StopInfo.cpp:1510
static lldb::StopInfoSP CreateStopReasonWithInterrupt(Thread &thread, int signo, const char *description)
Definition: StopInfo.cpp:1473
bool IsValid() const
Definition: StopInfo.cpp:41
virtual ~StopInfo()=default
StructuredData::ObjectSP m_extended_info
Definition: StopInfo.h:206
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr, std::optional< int > code=std::nullopt)
Definition: StopInfo.cpp:1466
virtual void WillResume(lldb::StateType resume_state)
Definition: StopInfo.h:67
virtual bool ShouldNotify(Event *event_ptr)
Definition: StopInfo.h:60
lldb::ThreadSP GetThread() const
Definition: StopInfo.h:34
static lldb::StopInfoSP CreateStopReasonFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1503
static lldb::StopInfoSP CreateStopReasonVForkDone(Thread &thread)
Definition: StopInfo.cpp:1516
static lldb::StopInfoSP CreateStopReasonWithWatchpointID(Thread &thread, lldb::break_id_t watch_id, bool silently_continue=false)
Definition: StopInfo.cpp:1459
virtual void SetDescription(const char *desc_cstr)
Definition: StopInfo.h:73
virtual const char * GetDescription()
Definition: StopInfo.h:71
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
Definition: StopInfo.cpp:1489
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
static lldb::ValueObjectSP GetCrashingDereference(lldb::StopInfoSP &stop_info_sp, lldb::addr_t *crashing_address=nullptr)
Definition: StopInfo.cpp:1541
LazyBool m_override_should_notify
Definition: StopInfo.h:202
static lldb::StopInfoSP CreateStopReasonProcessorTrace(Thread &thread, const char *description)
Definition: StopInfo.cpp:1494
virtual bool DoShouldNotify(Event *event_ptr)
Definition: StopInfo.h:184
void OverrideShouldStop(bool override_value)
Definition: StopInfo.h:106
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id, bool should_stop)
static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread)
Definition: StopInfo.cpp:1499
lldb::ThreadWP m_thread_wp
Definition: StopInfo.h:196
LazyBool m_override_should_stop
Definition: StopInfo.h:203
bool GetOverriddenShouldStopValue()
Definition: StopInfo.h:114
virtual bool ShouldStop(Event *event_ptr)
Definition: StopInfo.h:193
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:453
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Definition: lldb-forward.h:351
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
Definition: lldb-forward.h:431
uint64_t addr_t
Definition: lldb-types.h:80
StopReason
Thread stop reasons.
std::weak_ptr< lldb_private::Thread > ThreadWP
Definition: lldb-forward.h:451
uint64_t tid_t
Definition: lldb-types.h:84