1 //===-- Watchpoint.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_Watchpoint_h_
11 #define liblldb_Watchpoint_h_
18 // Other libraries and framework includes
20 #include "lldb/lldb-private.h"
21 #include "lldb/Breakpoint/WatchpointOptions.h"
22 #include "lldb/Breakpoint/StoppointLocation.h"
23 #include "lldb/Core/UserID.h"
24 #include "lldb/Symbol/CompilerType.h"
25 #include "lldb/Target/Target.h"
27 namespace lldb_private {
30 public std::enable_shared_from_this<Watchpoint>,
31 public StoppointLocation
34 class WatchpointEventData :
38 WatchpointEventData (lldb::WatchpointEventType sub_type,
39 const lldb::WatchpointSP &new_watchpoint_sp);
41 ~WatchpointEventData() override;
43 static const ConstString &
47 GetFlavor() const override;
49 lldb::WatchpointEventType
50 GetWatchpointEventType () const;
56 Dump(Stream *s) const override;
58 static lldb::WatchpointEventType
59 GetWatchpointEventTypeFromEvent (const lldb::EventSP &event_sp);
61 static lldb::WatchpointSP
62 GetWatchpointFromEvent (const lldb::EventSP &event_sp);
64 static const WatchpointEventData *
65 GetEventDataFromEvent (const Event *event_sp);
68 lldb::WatchpointEventType m_watchpoint_event;
69 lldb::WatchpointSP m_new_watchpoint_sp;
71 DISALLOW_COPY_AND_ASSIGN (WatchpointEventData);
74 Watchpoint (Target& target, lldb::addr_t addr, uint32_t size, const CompilerType *type, bool hardware = true);
76 ~Watchpoint() override;
79 IncrementFalseAlarmsAndReviseHitCount();
85 SetEnabled (bool enabled, bool notify = true);
88 IsHardware() const override;
91 ShouldStop(StoppointCallbackContext *context) override;
93 bool WatchpointRead () const;
94 bool WatchpointWrite () const;
95 uint32_t GetIgnoreCount () const;
96 void SetIgnoreCount (uint32_t n);
97 void SetWatchpointType (uint32_t type, bool notify = true);
98 void SetDeclInfo (const std::string &str);
99 std::string GetWatchSpec();
100 void SetWatchSpec (const std::string &str);
102 // Snapshot management interface.
103 bool IsWatchVariable() const;
104 void SetWatchVariable(bool val);
105 bool CaptureWatchedValue (const ExecutionContext &exe_ctx);
107 void GetDescription (Stream *s, lldb::DescriptionLevel level);
108 void Dump (Stream *s) const override;
109 void DumpSnapshots(Stream *s, const char *prefix = nullptr) const;
110 void DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const;
111 Target &GetTarget() { return m_target; }
112 const Error &GetError() { return m_error; }
114 //------------------------------------------------------------------
115 /// Returns the WatchpointOptions structure set for this watchpoint.
118 /// A pointer to this watchpoint's WatchpointOptions.
119 //------------------------------------------------------------------
121 GetOptions () { return &m_options; }
123 //------------------------------------------------------------------
124 /// Set the callback action invoked when the watchpoint is hit.
126 /// @param[in] callback
127 /// The method that will get called when the watchpoint is hit.
128 /// @param[in] callback_baton
129 /// A void * pointer that will get passed back to the callback function.
130 /// @param[in] is_synchronous
131 /// If \b true the callback will be run on the private event thread
132 /// before the stop event gets reported. If false, the callback will get
133 /// handled on the public event thread after the stop has been posted.
136 /// \b true if the process should stop when you hit the watchpoint.
137 /// \b false if it should continue.
138 //------------------------------------------------------------------
140 SetCallback (WatchpointHitCallback callback,
141 void *callback_baton,
142 bool is_synchronous = false);
145 SetCallback (WatchpointHitCallback callback,
146 const lldb::BatonSP &callback_baton_sp,
147 bool is_synchronous = false);
149 void ClearCallback();
151 //------------------------------------------------------------------
152 /// Invoke the callback action when the watchpoint is hit.
154 /// @param[in] context
155 /// Described the watchpoint event.
158 /// \b true if the target should stop at this watchpoint and \b false not.
159 //------------------------------------------------------------------
161 InvokeCallback (StoppointCallbackContext *context);
163 //------------------------------------------------------------------
165 //------------------------------------------------------------------
166 //------------------------------------------------------------------
167 /// Set the watchpoint's condition.
169 /// @param[in] condition
170 /// The condition expression to evaluate when the watchpoint is hit.
171 /// Pass in nullptr to clear the condition.
172 //------------------------------------------------------------------
173 void SetCondition (const char *condition);
175 //------------------------------------------------------------------
176 /// Return a pointer to the text of the condition expression.
179 /// A pointer to the condition expression text, or nullptr if no
180 // condition has been set.
181 //------------------------------------------------------------------
182 const char *GetConditionText () const;
185 TurnOnEphemeralMode();
188 TurnOffEphemeralMode();
191 IsDisabledDuringEphemeralMode();
201 friend class WatchpointList;
210 ResetHistoricValues ()
212 m_old_value_sp.reset(nullptr);
213 m_new_value_sp.reset(nullptr);
217 bool m_enabled; // Is this watchpoint enabled
218 bool m_is_hardware; // Is this a hardware watchpoint
219 bool m_is_watch_variable; // True if set via 'watchpoint set variable'.
220 bool m_is_ephemeral; // True if the watchpoint is in the ephemeral mode, meaning that it is
221 // undergoing a pair of temporary disable/enable actions to avoid recursively
222 // triggering further watchpoint events.
223 uint32_t m_disabled_count; // Keep track of the count that the watchpoint is disabled while in ephemeral mode.
224 // At the end of the ephemeral mode when the watchpoint is to be enabled again,
225 // we check the count, if it is more than 1, it means the user-supplied actions
226 // actually want the watchpoint to be disabled!
227 uint32_t m_watch_read:1, // 1 if we stop when the watched data is read from
228 m_watch_write:1, // 1 if we stop when the watched data is written to
229 m_watch_was_read:1, // Set to 1 when watchpoint is hit for a read access
230 m_watch_was_written:1; // Set to 1 when watchpoint is hit for a write access
231 uint32_t m_ignore_count; // Number of times to ignore this watchpoint
232 uint32_t m_false_alarms; // Number of false alarms.
233 std::string m_decl_str; // Declaration information, if any.
234 std::string m_watch_spec_str; // Spec for the watchpoint.
235 lldb::ValueObjectSP m_old_value_sp;
236 lldb::ValueObjectSP m_new_value_sp;
238 Error m_error; // An error object describing errors associated with this watchpoint.
239 WatchpointOptions m_options; // Settable watchpoint options, which is a delegate to handle
240 // the callback machinery.
241 bool m_being_created;
243 std::unique_ptr<UserExpression> m_condition_ap; // The condition to test.
245 void SetID(lldb::watch_id_t id) { m_loc_id = id; }
248 SendWatchpointChangedEvent (lldb::WatchpointEventType eventKind);
251 SendWatchpointChangedEvent (WatchpointEventData *data);
253 DISALLOW_COPY_AND_ASSIGN (Watchpoint);
256 } // namespace lldb_private
258 #endif // liblldb_Watchpoint_h_