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_
19 // Other libraries and framework includes
22 #include "lldb/lldb-private.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Core/UserID.h"
25 #include "lldb/Breakpoint/WatchpointOptions.h"
26 #include "lldb/Breakpoint/StoppointLocation.h"
28 namespace lldb_private {
31 public std::enable_shared_from_this<Watchpoint>,
32 public StoppointLocation
36 class WatchpointEventData :
41 static const ConstString &
44 virtual const ConstString &
47 WatchpointEventData (lldb::WatchpointEventType sub_type,
48 const lldb::WatchpointSP &new_watchpoint_sp);
51 ~WatchpointEventData();
53 lldb::WatchpointEventType
54 GetWatchpointEventType () const;
60 Dump (Stream *s) const;
62 static lldb::WatchpointEventType
63 GetWatchpointEventTypeFromEvent (const lldb::EventSP &event_sp);
65 static lldb::WatchpointSP
66 GetWatchpointFromEvent (const lldb::EventSP &event_sp);
68 static const WatchpointEventData *
69 GetEventDataFromEvent (const Event *event_sp);
73 lldb::WatchpointEventType m_watchpoint_event;
74 lldb::WatchpointSP m_new_watchpoint_sp;
76 DISALLOW_COPY_AND_ASSIGN (WatchpointEventData);
79 Watchpoint (Target& target, lldb::addr_t addr, uint32_t size, const ClangASTType *type, bool hardware = true);
83 IncrementFalseAlarmsAndReviseHitCount();
89 SetEnabled (bool enabled, bool notify = true);
95 ShouldStop (StoppointCallbackContext *context);
97 bool WatchpointRead () const;
98 bool WatchpointWrite () const;
99 uint32_t GetIgnoreCount () const;
100 void SetIgnoreCount (uint32_t n);
101 void SetWatchpointType (uint32_t type, bool notify = true);
102 void SetDeclInfo (const std::string &str);
103 std::string GetWatchSpec();
104 void SetWatchSpec (const std::string &str);
106 // Snapshot management interface.
107 bool IsWatchVariable() const;
108 void SetWatchVariable(bool val);
109 bool CaptureWatchedValue (const ExecutionContext &exe_ctx);
111 void GetDescription (Stream *s, lldb::DescriptionLevel level);
112 void Dump (Stream *s) const;
113 void DumpSnapshots (Stream *s, const char * prefix = NULL) const;
114 void DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const;
115 Target &GetTarget() { return m_target; }
116 const Error &GetError() { return m_error; }
118 //------------------------------------------------------------------
119 /// Returns the WatchpointOptions structure set for this watchpoint.
122 /// A pointer to this watchpoint's WatchpointOptions.
123 //------------------------------------------------------------------
125 GetOptions () { return &m_options; }
127 //------------------------------------------------------------------
128 /// Set the callback action invoked when the watchpoint is hit.
130 /// @param[in] callback
131 /// The method that will get called when the watchpoint is hit.
132 /// @param[in] callback_baton
133 /// A void * pointer that will get passed back to the callback function.
134 /// @param[in] is_synchronous
135 /// If \b true the callback will be run on the private event thread
136 /// before the stop event gets reported. If false, the callback will get
137 /// handled on the public event thead after the stop has been posted.
140 /// \b true if the process should stop when you hit the watchpoint.
141 /// \b false if it should continue.
142 //------------------------------------------------------------------
144 SetCallback (WatchpointHitCallback callback,
145 void *callback_baton,
146 bool is_synchronous = false);
149 SetCallback (WatchpointHitCallback callback,
150 const lldb::BatonSP &callback_baton_sp,
151 bool is_synchronous = false);
153 void ClearCallback();
155 //------------------------------------------------------------------
156 /// Invoke the callback action when the watchpoint is hit.
158 /// @param[in] context
159 /// Described the watchpoint event.
162 /// \b true if the target should stop at this watchpoint and \b false not.
163 //------------------------------------------------------------------
165 InvokeCallback (StoppointCallbackContext *context);
167 //------------------------------------------------------------------
169 //------------------------------------------------------------------
170 //------------------------------------------------------------------
171 /// Set the watchpoint's condition.
173 /// @param[in] condition
174 /// The condition expression to evaluate when the watchpoint is hit.
175 /// Pass in NULL to clear the condition.
176 //------------------------------------------------------------------
177 void SetCondition (const char *condition);
179 //------------------------------------------------------------------
180 /// Return a pointer to the text of the condition expression.
183 /// A pointer to the condition expression text, or NULL if no
184 // condition has been set.
185 //------------------------------------------------------------------
186 const char *GetConditionText () const;
189 TurnOnEphemeralMode();
192 TurnOffEphemeralMode();
195 IsDisabledDuringEphemeralMode();
206 friend class WatchpointList;
208 void ResetHitCount() { m_hit_count = 0; }
211 bool m_enabled; // Is this watchpoint enabled
212 bool m_is_hardware; // Is this a hardware watchpoint
213 bool m_is_watch_variable; // True if set via 'watchpoint set variable'.
214 bool m_is_ephemeral; // True if the watchpoint is in the ephemeral mode, meaning that it is
215 // undergoing a pair of temporary disable/enable actions to avoid recursively
216 // triggering further watchpoint events.
217 uint32_t m_disabled_count; // Keep track of the count that the watchpoint is disabled while in ephemeral mode.
218 // At the end of the ephemeral mode when the watchpoint is to be enabled agian,
219 // we check the count, if it is more than 1, it means the user-supplied actions
220 // actually want the watchpoint to be disabled!
221 uint32_t m_watch_read:1, // 1 if we stop when the watched data is read from
222 m_watch_write:1, // 1 if we stop when the watched data is written to
223 m_watch_was_read:1, // Set to 1 when watchpoint is hit for a read access
224 m_watch_was_written:1; // Set to 1 when watchpoint is hit for a write access
225 uint32_t m_ignore_count; // Number of times to ignore this watchpoint
226 uint32_t m_false_alarms; // Number of false alarms.
227 std::string m_decl_str; // Declaration information, if any.
228 std::string m_watch_spec_str; // Spec for the watchpoint.
229 lldb::ValueObjectSP m_old_value_sp;
230 lldb::ValueObjectSP m_new_value_sp;
232 Error m_error; // An error object describing errors associated with this watchpoint.
233 WatchpointOptions m_options; // Settable watchpoint options, which is a delegate to handle
234 // the callback machinery.
235 bool m_being_created;
237 std::unique_ptr<ClangUserExpression> m_condition_ap; // The condition to test.
239 void SetID(lldb::watch_id_t id) { m_loc_id = id; }
242 SendWatchpointChangedEvent (lldb::WatchpointEventType eventKind);
245 SendWatchpointChangedEvent (WatchpointEventData *data);
247 DISALLOW_COPY_AND_ASSIGN (Watchpoint);
250 } // namespace lldb_private
252 #endif // liblldb_Watchpoint_h_