]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Breakpoint/Watchpoint.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Breakpoint / Watchpoint.h
1 //===-- Watchpoint.h --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Watchpoint_h_
11 #define liblldb_Watchpoint_h_
12
13 // C Includes
14 // C++ Includes
15 #include <memory>
16 #include <string>
17
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/Breakpoint/StoppointLocation.h"
21 #include "lldb/Breakpoint/WatchpointOptions.h"
22 #include "lldb/Core/UserID.h"
23 #include "lldb/Symbol/CompilerType.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/lldb-private.h"
26
27 namespace lldb_private {
28
29 class Watchpoint : public std::enable_shared_from_this<Watchpoint>,
30                    public StoppointLocation {
31 public:
32   class WatchpointEventData : public EventData {
33   public:
34     WatchpointEventData(lldb::WatchpointEventType sub_type,
35                         const lldb::WatchpointSP &new_watchpoint_sp);
36
37     ~WatchpointEventData() override;
38
39     static const ConstString &GetFlavorString();
40
41     const ConstString &GetFlavor() const override;
42
43     lldb::WatchpointEventType GetWatchpointEventType() const;
44
45     lldb::WatchpointSP &GetWatchpoint();
46
47     void Dump(Stream *s) const override;
48
49     static lldb::WatchpointEventType
50     GetWatchpointEventTypeFromEvent(const lldb::EventSP &event_sp);
51
52     static lldb::WatchpointSP
53     GetWatchpointFromEvent(const lldb::EventSP &event_sp);
54
55     static const WatchpointEventData *
56     GetEventDataFromEvent(const Event *event_sp);
57
58   private:
59     lldb::WatchpointEventType m_watchpoint_event;
60     lldb::WatchpointSP m_new_watchpoint_sp;
61
62     DISALLOW_COPY_AND_ASSIGN(WatchpointEventData);
63   };
64
65   Watchpoint(Target &target, lldb::addr_t addr, uint32_t size,
66              const CompilerType *type, bool hardware = true);
67
68   ~Watchpoint() override;
69
70   void IncrementFalseAlarmsAndReviseHitCount();
71
72   bool IsEnabled() const;
73
74   // This doesn't really enable/disable the watchpoint.  
75   // It is currently just for use in the Process plugin's
76   // {Enable,Disable}Watchpoint, which should be used instead.
77   
78   void SetEnabled(bool enabled, bool notify = true);
79
80   bool IsHardware() const override;
81
82   bool ShouldStop(StoppointCallbackContext *context) override;
83
84   bool WatchpointRead() const;
85   bool WatchpointWrite() const;
86   uint32_t GetIgnoreCount() const;
87   void SetIgnoreCount(uint32_t n);
88   void SetWatchpointType(uint32_t type, bool notify = true);
89   void SetDeclInfo(const std::string &str);
90   std::string GetWatchSpec();
91   void SetWatchSpec(const std::string &str);
92
93   // Snapshot management interface.
94   bool IsWatchVariable() const;
95   void SetWatchVariable(bool val);
96   bool CaptureWatchedValue(const ExecutionContext &exe_ctx);
97
98   void GetDescription(Stream *s, lldb::DescriptionLevel level);
99   void Dump(Stream *s) const override;
100   void DumpSnapshots(Stream *s, const char *prefix = nullptr) const;
101   void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
102   Target &GetTarget() { return m_target; }
103   const Error &GetError() { return m_error; }
104
105   //------------------------------------------------------------------
106   /// Returns the WatchpointOptions structure set for this watchpoint.
107   ///
108   /// @return
109   ///     A pointer to this watchpoint's WatchpointOptions.
110   //------------------------------------------------------------------
111   WatchpointOptions *GetOptions() { return &m_options; }
112
113   //------------------------------------------------------------------
114   /// Set the callback action invoked when the watchpoint is hit.
115   ///
116   /// @param[in] callback
117   ///    The method that will get called when the watchpoint is hit.
118   /// @param[in] callback_baton
119   ///    A void * pointer that will get passed back to the callback function.
120   /// @param[in] is_synchronous
121   ///    If \b true the callback will be run on the private event thread
122   ///    before the stop event gets reported.  If false, the callback will get
123   ///    handled on the public event thread after the stop has been posted.
124   ///
125   /// @return
126   ///    \b true if the process should stop when you hit the watchpoint.
127   ///    \b false if it should continue.
128   //------------------------------------------------------------------
129   void SetCallback(WatchpointHitCallback callback, void *callback_baton,
130                    bool is_synchronous = false);
131
132   void SetCallback(WatchpointHitCallback callback,
133                    const lldb::BatonSP &callback_baton_sp,
134                    bool is_synchronous = false);
135
136   void ClearCallback();
137
138   //------------------------------------------------------------------
139   /// Invoke the callback action when the watchpoint is hit.
140   ///
141   /// @param[in] context
142   ///     Described the watchpoint event.
143   ///
144   /// @return
145   ///     \b true if the target should stop at this watchpoint and \b false not.
146   //------------------------------------------------------------------
147   bool InvokeCallback(StoppointCallbackContext *context);
148
149   //------------------------------------------------------------------
150   // Condition
151   //------------------------------------------------------------------
152   //------------------------------------------------------------------
153   /// Set the watchpoint's condition.
154   ///
155   /// @param[in] condition
156   ///    The condition expression to evaluate when the watchpoint is hit.
157   ///    Pass in nullptr to clear the condition.
158   //------------------------------------------------------------------
159   void SetCondition(const char *condition);
160
161   //------------------------------------------------------------------
162   /// Return a pointer to the text of the condition expression.
163   ///
164   /// @return
165   ///    A pointer to the condition expression text, or nullptr if no
166   //     condition has been set.
167   //------------------------------------------------------------------
168   const char *GetConditionText() const;
169
170   void TurnOnEphemeralMode();
171
172   void TurnOffEphemeralMode();
173
174   bool IsDisabledDuringEphemeralMode();
175
176   const CompilerType &GetCompilerType() { return m_type; }
177
178 private:
179   friend class Target;
180   friend class WatchpointList;
181
182   void ResetHitCount() { m_hit_count = 0; }
183
184   void ResetHistoricValues() {
185     m_old_value_sp.reset(nullptr);
186     m_new_value_sp.reset(nullptr);
187   }
188
189   Target &m_target;
190   bool m_enabled;           // Is this watchpoint enabled
191   bool m_is_hardware;       // Is this a hardware watchpoint
192   bool m_is_watch_variable; // True if set via 'watchpoint set variable'.
193   bool m_is_ephemeral;      // True if the watchpoint is in the ephemeral mode,
194                             // meaning that it is
195   // undergoing a pair of temporary disable/enable actions to avoid recursively
196   // triggering further watchpoint events.
197   uint32_t m_disabled_count; // Keep track of the count that the watchpoint is
198                              // disabled while in ephemeral mode.
199   // At the end of the ephemeral mode when the watchpoint is to be enabled
200   // again,
201   // we check the count, if it is more than 1, it means the user-supplied
202   // actions
203   // actually want the watchpoint to be disabled!
204   uint32_t m_watch_read : 1, // 1 if we stop when the watched data is read from
205       m_watch_write : 1,     // 1 if we stop when the watched data is written to
206       m_watch_was_read : 1, // Set to 1 when watchpoint is hit for a read access
207       m_watch_was_written : 1;  // Set to 1 when watchpoint is hit for a write
208                                 // access
209   uint32_t m_ignore_count;      // Number of times to ignore this watchpoint
210   uint32_t m_false_alarms;      // Number of false alarms.
211   std::string m_decl_str;       // Declaration information, if any.
212   std::string m_watch_spec_str; // Spec for the watchpoint.
213   lldb::ValueObjectSP m_old_value_sp;
214   lldb::ValueObjectSP m_new_value_sp;
215   CompilerType m_type;
216   Error m_error; // An error object describing errors associated with this
217                  // watchpoint.
218   WatchpointOptions
219       m_options; // Settable watchpoint options, which is a delegate to handle
220                  // the callback machinery.
221   bool m_being_created;
222
223   std::unique_ptr<UserExpression> m_condition_ap; // The condition to test.
224
225   void SetID(lldb::watch_id_t id) { m_loc_id = id; }
226
227   void SendWatchpointChangedEvent(lldb::WatchpointEventType eventKind);
228
229   void SendWatchpointChangedEvent(WatchpointEventData *data);
230
231   DISALLOW_COPY_AND_ASSIGN(Watchpoint);
232 };
233
234 } // namespace lldb_private
235
236 #endif // liblldb_Watchpoint_h_