]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/Watchpoint.h
Merge ^/head r309263 through r309518.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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/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"
26
27 namespace lldb_private {
28
29 class Watchpoint :
30     public std::enable_shared_from_this<Watchpoint>,
31     public StoppointLocation
32 {
33 public:
34     class WatchpointEventData :
35         public EventData
36     {
37     public:
38         WatchpointEventData (lldb::WatchpointEventType sub_type,
39                              const lldb::WatchpointSP &new_watchpoint_sp);
40
41         ~WatchpointEventData() override;
42
43         static const ConstString &
44         GetFlavorString ();
45
46         const ConstString &
47         GetFlavor() const override;
48
49         lldb::WatchpointEventType
50         GetWatchpointEventType () const;
51
52         lldb::WatchpointSP &
53         GetWatchpoint ();
54         
55         void
56         Dump(Stream *s) const override;
57
58         static lldb::WatchpointEventType
59         GetWatchpointEventTypeFromEvent (const lldb::EventSP &event_sp);
60
61         static lldb::WatchpointSP
62         GetWatchpointFromEvent (const lldb::EventSP &event_sp);
63
64         static const WatchpointEventData *
65         GetEventDataFromEvent (const Event *event_sp);
66
67     private:
68         lldb::WatchpointEventType m_watchpoint_event;
69         lldb::WatchpointSP m_new_watchpoint_sp;
70
71         DISALLOW_COPY_AND_ASSIGN (WatchpointEventData);
72     };
73
74     Watchpoint (Target& target, lldb::addr_t addr, uint32_t size, const CompilerType *type, bool hardware = true);
75
76     ~Watchpoint() override;
77
78     void
79     IncrementFalseAlarmsAndReviseHitCount();
80
81     bool
82     IsEnabled () const;
83
84     void
85     SetEnabled (bool enabled, bool notify = true);
86
87     bool
88     IsHardware() const override;
89
90     bool
91     ShouldStop(StoppointCallbackContext *context) override;
92
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);
101
102     // Snapshot management interface.
103     bool        IsWatchVariable() const;
104     void        SetWatchVariable(bool val);
105     bool        CaptureWatchedValue (const ExecutionContext &exe_ctx);
106
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; }
113
114     //------------------------------------------------------------------
115     /// Returns the WatchpointOptions structure set for this watchpoint.
116     ///
117     /// @return
118     ///     A pointer to this watchpoint's WatchpointOptions.
119     //------------------------------------------------------------------
120     WatchpointOptions *
121     GetOptions () { return &m_options; }
122
123     //------------------------------------------------------------------
124     /// Set the callback action invoked when the watchpoint is hit.  
125     /// 
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.
134     ///
135     /// @return
136     ///    \b true if the process should stop when you hit the watchpoint.
137     ///    \b false if it should continue.
138     //------------------------------------------------------------------
139     void
140     SetCallback (WatchpointHitCallback callback, 
141                  void *callback_baton,
142                  bool is_synchronous = false);
143
144     void
145     SetCallback (WatchpointHitCallback callback, 
146                  const lldb::BatonSP &callback_baton_sp,
147                  bool is_synchronous = false);
148
149     void        ClearCallback();
150
151     //------------------------------------------------------------------
152     /// Invoke the callback action when the watchpoint is hit.
153     ///
154     /// @param[in] context
155     ///     Described the watchpoint event.
156     ///
157     /// @return
158     ///     \b true if the target should stop at this watchpoint and \b false not.
159     //------------------------------------------------------------------
160     bool
161     InvokeCallback (StoppointCallbackContext *context);
162
163     //------------------------------------------------------------------
164     // Condition
165     //------------------------------------------------------------------
166     //------------------------------------------------------------------
167     /// Set the watchpoint's condition.
168     ///
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);
174     
175     //------------------------------------------------------------------
176     /// Return a pointer to the text of the condition expression.
177     ///
178     /// @return
179     ///    A pointer to the condition expression text, or nullptr if no
180     //     condition has been set.
181     //------------------------------------------------------------------
182     const char *GetConditionText () const;
183
184     void
185     TurnOnEphemeralMode();
186
187     void
188     TurnOffEphemeralMode();
189
190     bool
191     IsDisabledDuringEphemeralMode();
192     
193     const CompilerType &
194     GetCompilerType()
195     {
196         return m_type;
197     }
198
199 private:
200     friend class Target;
201     friend class WatchpointList;
202
203     void
204     ResetHitCount ()
205     {
206         m_hit_count = 0;
207     }
208     
209     void
210     ResetHistoricValues ()
211     {
212         m_old_value_sp.reset(nullptr);
213         m_new_value_sp.reset(nullptr);
214     }
215
216     Target      &m_target;
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;
237     CompilerType m_type;
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;
242
243     std::unique_ptr<UserExpression> m_condition_ap;  // The condition to test.
244
245     void SetID(lldb::watch_id_t id) { m_loc_id = id; }
246     
247     void
248     SendWatchpointChangedEvent (lldb::WatchpointEventType eventKind);
249
250     void
251     SendWatchpointChangedEvent (WatchpointEventData *data);
252
253     DISALLOW_COPY_AND_ASSIGN (Watchpoint);
254 };
255
256 } // namespace lldb_private
257
258 #endif // liblldb_Watchpoint_h_