LLDB mainline
WatchpointOptions.h
Go to the documentation of this file.
1//===-- WatchpointOptions.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_BREAKPOINT_WATCHPOINTOPTIONS_H
10#define LLDB_BREAKPOINT_WATCHPOINTOPTIONS_H
11
12#include <memory>
13#include <string>
14
15#include "lldb/Utility/Baton.h"
17#include "lldb/lldb-private.h"
18
19namespace lldb_private {
20
21/// \class WatchpointOptions WatchpointOptions.h
22/// "lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a
23/// watchpoint.
24
26public:
27 // Constructors and Destructors
28 /// Default constructor. The watchpoint is enabled, and has no condition,
29 /// callback, ignore count, etc...
32
34 /// This constructor allows you to specify all the watchpoint options.
35 ///
36 /// \param[in] callback
37 /// This is the plugin for some code that gets run, returns \b true if we
38 /// are to stop.
39 ///
40 /// \param[in] baton
41 /// Client data that will get passed to the callback.
42 ///
43 /// \param[in] thread_id
44 /// Only stop if \a thread_id hits the watchpoint.
47
49
50 // Operators
52
53 // Callbacks
54 //
55 // Watchpoint callbacks come in two forms, synchronous and asynchronous.
56 // Synchronous callbacks will get run before any of the thread plans are
57 // consulted, and if they return false the target will continue "under the
58 // radar" of the thread plans. There are a couple of restrictions to
59 // synchronous callbacks: 1) They should NOT resume the target themselves.
60 // Just return false if you want the target to restart. 2) Watchpoints with
61 // synchronous callbacks can't have conditions (or rather, they can have
62 // them, but they won't do anything. Ditto with ignore counts, etc...
63 // You are supposed to control that all through the callback.
64 // Asynchronous callbacks get run as part of the "ShouldStop" logic in the
65 // thread plan. The logic there is:
66 // a) If the watchpoint is thread specific and not for this thread, continue
67 // w/o running the callback.
68 // b) If the ignore count says we shouldn't stop, then ditto.
69 // c) If the condition says we shouldn't stop, then ditto.
70 // d) Otherwise, the callback will get run, and if it returns true we will
71 // stop, and if false we won't.
72 // The asynchronous callback can run the target itself, but at present that
73 // should be the last action the callback does. We will relax this
74 // condition at some point, but it will take a bit of plumbing to get
75 // that to work.
76
77 /// Adds a callback to the watchpoint option set.
78 ///
79 /// \param[in] callback
80 /// The function to be called when the watchpoint gets hit.
81 ///
82 /// \param[in] baton_sp
83 /// A baton which will get passed back to the callback when it is invoked.
84 ///
85 /// \param[in] synchronous
86 /// Whether this is a synchronous or asynchronous callback.
87 /// See discussion above.
89 const lldb::BatonSP &baton_sp, bool synchronous = false);
90
91 /// Remove the callback from this option set.
92 void ClearCallback();
93
94 // The rest of these functions are meant to be used only within the
95 // watchpoint handling mechanism.
96
97 /// Use this function to invoke the callback for a specific stop.
98 ///
99 /// \param[in] context
100 /// The context in which the callback is to be invoked. This includes the
101 /// stop event, the execution context of the stop (since you might hit
102 /// the same watchpoint on multiple threads) and whether we are currently
103 /// executing synchronous or asynchronous callbacks.
104 ///
105 /// \param[in] watch_id
106 /// The watchpoint ID that owns this option set.
107 ///
108 /// \return
109 /// The callback return value.
111 lldb::user_id_t watch_id);
112
113 /// Used in InvokeCallback to tell whether it is the right time to run this
114 /// kind of callback.
115 ///
116 /// \return
117 /// The synchronicity of our callback.
119
120 /// Fetch the baton from the callback.
121 ///
122 /// \return
123 /// The baton.
124 Baton *GetBaton();
125
126 /// Fetch a const version of the baton from the callback.
127 ///
128 /// \return
129 /// The baton.
130 const Baton *GetBaton() const;
131
132 /// Return the current thread spec for this option. This will return nullptr
133 /// if the no thread specifications have been set for this WatchpointOptions
134 /// yet.
135 ///
136 /// \return
137 /// The thread specification pointer for this option, or nullptr if none
138 /// has been set yet.
139 const ThreadSpec *GetThreadSpecNoCreate() const;
140
141 /// Returns a pointer to the ThreadSpec for this option, creating it if it
142 /// hasn't been created already. This API is used for setting the
143 /// ThreadSpec items for this WatchpointOptions.
145
146 void SetThreadID(lldb::tid_t thread_id);
147
148 void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
149
150 /// Get description for callback only.
152
153 /// Returns true if the watchpoint option has a callback set.
154 bool HasCallback();
155
156 /// This is the default empty callback.
157 /// \return
158 /// The thread id for which the watchpoint hit will stop,
159 /// LLDB_INVALID_THREAD_ID for all threads.
160 static bool NullCallback(void *baton, StoppointCallbackContext *context,
161 lldb::user_id_t watch_id);
162
163 struct CommandData {
164 CommandData() = default;
165
166 ~CommandData() = default;
167
169 std::string script_source;
170 bool stop_on_error = true;
171 };
172
173 class CommandBaton : public TypedBaton<CommandData> {
174 public:
175 CommandBaton(std::unique_ptr<CommandData> Data)
176 : TypedBaton(std::move(Data)) {}
177
178 void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
179 unsigned indentation) const override;
180 };
181
182private:
183 WatchpointHitCallback m_callback; // This is the callback function pointer
184 lldb::BatonSP m_callback_baton_sp; // This is the client data for the callback
186 std::unique_ptr<ThreadSpec>
187 m_thread_spec_up; // Thread for which this watchpoint will take
188};
189
190} // namespace lldb_private
191
192#endif // LLDB_BREAKPOINT_WATCHPOINTOPTIONS_H
A class designed to wrap callback batons so they can cleanup any acquired resources.
Definition: Baton.h:35
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
CommandBaton(std::unique_ptr< CommandData > Data)
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level, unsigned indentation) const override
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
const WatchpointOptions & operator=(const WatchpointOptions &rhs)
static WatchpointOptions * CopyOptionsNoCallback(WatchpointOptions &rhs)
void SetThreadID(lldb::tid_t thread_id)
void ClearCallback()
Remove the callback from this option set.
bool HasCallback()
Returns true if the watchpoint option has a callback set.
std::unique_ptr< ThreadSpec > m_thread_spec_up
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
static bool NullCallback(void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
This is the default empty callback.
bool InvokeCallback(StoppointCallbackContext *context, lldb::user_id_t watch_id)
Use this function to invoke the callback for a specific stop.
void SetCallback(WatchpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the watchpoint option set.
WatchpointHitCallback m_callback
void GetCallbackDescription(Stream *s, lldb::DescriptionLevel level) const
Get description for callback only.
WatchpointOptions()
Default constructor.
const ThreadSpec * GetThreadSpecNoCreate() const
Return the current thread spec for this option.
bool IsCallbackSynchronous()
Used in InvokeCallback to tell whether it is the right time to run this kind of callback.
Baton * GetBaton()
Fetch the baton from the callback.
WatchpointOptions(WatchpointHitCallback callback, void *baton, lldb::tid_t thread_id=LLDB_INVALID_THREAD_ID)
This constructor allows you to specify all the watchpoint options.
ThreadSpec * GetThreadSpec()
Returns a pointer to the ThreadSpec for this option, creating it if it hasn't been created already.
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:90
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
bool(* WatchpointHitCallback)(void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::Baton > BatonSP
Definition: lldb-forward.h:311
uint64_t user_id_t
Definition: lldb-types.h:80
uint64_t tid_t
Definition: lldb-types.h:82