LLDB  mainline
Watchpoint.h
Go to the documentation of this file.
1 //===-- Watchpoint.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_WATCHPOINT_H
10 #define LLDB_BREAKPOINT_WATCHPOINT_H
11 
12 #include <memory>
13 #include <string>
14 
18 #include "lldb/Target/Target.h"
19 #include "lldb/Utility/UserID.h"
20 #include "lldb/lldb-private.h"
21 
22 namespace lldb_private {
23 
24 class Watchpoint : public std::enable_shared_from_this<Watchpoint>,
25  public StoppointSite {
26 public:
27  class WatchpointEventData : public EventData {
28  public:
29  WatchpointEventData(lldb::WatchpointEventType sub_type,
30  const lldb::WatchpointSP &new_watchpoint_sp);
31 
32  ~WatchpointEventData() override;
33 
35 
36  ConstString GetFlavor() const override;
37 
38  lldb::WatchpointEventType GetWatchpointEventType() const;
39 
40  lldb::WatchpointSP &GetWatchpoint();
41 
42  void Dump(Stream *s) const override;
43 
44  static lldb::WatchpointEventType
45  GetWatchpointEventTypeFromEvent(const lldb::EventSP &event_sp);
46 
47  static lldb::WatchpointSP
48  GetWatchpointFromEvent(const lldb::EventSP &event_sp);
49 
50  static const WatchpointEventData *
51  GetEventDataFromEvent(const Event *event_sp);
52 
53  private:
54  lldb::WatchpointEventType m_watchpoint_event;
55  lldb::WatchpointSP m_new_watchpoint_sp;
56 
57  WatchpointEventData(const WatchpointEventData &) = delete;
58  const WatchpointEventData &operator=(const WatchpointEventData &) = delete;
59  };
60 
61  Watchpoint(Target &target, lldb::addr_t addr, uint32_t size,
62  const CompilerType *type, bool hardware = true);
63 
64  ~Watchpoint() override;
65 
67 
68  bool IsEnabled() const;
69 
70  // This doesn't really enable/disable the watchpoint. It is currently just
71  // for use in the Process plugin's {Enable,Disable}Watchpoint, which should
72  // be used instead.
73  void SetEnabled(bool enabled, bool notify = true);
74 
75  bool IsHardware() const override;
76 
77  bool ShouldStop(StoppointCallbackContext *context) override;
78 
79  bool WatchpointRead() const;
80  bool WatchpointWrite() const;
81  uint32_t GetIgnoreCount() const;
82  void SetIgnoreCount(uint32_t n);
83  void SetWatchpointType(uint32_t type, bool notify = true);
84  void SetDeclInfo(const std::string &str);
86  void SetWatchSpec(const std::string &str);
87 
88  // Snapshot management interface.
89  bool IsWatchVariable() const;
90  void SetWatchVariable(bool val);
91  bool CaptureWatchedValue(const ExecutionContext &exe_ctx);
92 
94  void Dump(Stream *s) const override;
95  void DumpSnapshots(Stream *s, const char *prefix = nullptr) const;
96  void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
97  Target &GetTarget() { return m_target; }
98  const Status &GetError() { return m_error; }
99 
100  /// Returns the WatchpointOptions structure set for this watchpoint.
101  ///
102  /// \return
103  /// A pointer to this watchpoint's WatchpointOptions.
105 
106  /// Set the callback action invoked when the watchpoint is hit.
107  ///
108  /// \param[in] callback
109  /// The method that will get called when the watchpoint is hit.
110  /// \param[in] callback_baton
111  /// A void * pointer that will get passed back to the callback function.
112  /// \param[in] is_synchronous
113  /// If \b true the callback will be run on the private event thread
114  /// before the stop event gets reported. If false, the callback will get
115  /// handled on the public event thread after the stop has been posted.
116  void SetCallback(WatchpointHitCallback callback, void *callback_baton,
117  bool is_synchronous = false);
118 
119  void SetCallback(WatchpointHitCallback callback,
120  const lldb::BatonSP &callback_baton_sp,
121  bool is_synchronous = false);
122 
123  void ClearCallback();
124 
125  /// Invoke the callback action when the watchpoint is hit.
126  ///
127  /// \param[in] context
128  /// Described the watchpoint event.
129  ///
130  /// \return
131  /// \b true if the target should stop at this watchpoint and \b false not.
133 
134  // Condition
135  /// Set the watchpoint's condition.
136  ///
137  /// \param[in] condition
138  /// The condition expression to evaluate when the watchpoint is hit.
139  /// Pass in nullptr to clear the condition.
140  void SetCondition(const char *condition);
141 
142  /// Return a pointer to the text of the condition expression.
143  ///
144  /// \return
145  /// A pointer to the condition expression text, or nullptr if no
146  // condition has been set.
147  const char *GetConditionText() const;
148 
149  void TurnOnEphemeralMode();
150 
151  void TurnOffEphemeralMode();
152 
154 
155  const CompilerType &GetCompilerType() { return m_type; }
156 
157 private:
158  friend class Target;
159  friend class WatchpointList;
160 
162  m_old_value_sp.reset();
163  m_new_value_sp.reset();
164  }
165 
167  bool m_enabled; // Is this watchpoint enabled
168  bool m_is_hardware; // Is this a hardware watchpoint
169  bool m_is_watch_variable; // True if set via 'watchpoint set variable'.
170  bool m_is_ephemeral; // True if the watchpoint is in the ephemeral mode,
171  // meaning that it is
172  // undergoing a pair of temporary disable/enable actions to avoid recursively
173  // triggering further watchpoint events.
174  uint32_t m_disabled_count; // Keep track of the count that the watchpoint is
175  // disabled while in ephemeral mode.
176  // At the end of the ephemeral mode when the watchpoint is to be enabled
177  // again, we check the count, if it is more than 1, it means the user-
178  // supplied actions actually want the watchpoint to be disabled!
179  uint32_t m_watch_read : 1, // 1 if we stop when the watched data is read from
180  m_watch_write : 1, // 1 if we stop when the watched data is written to
181  m_watch_was_read : 1, // Set to 1 when watchpoint is hit for a read access
182  m_watch_was_written : 1; // Set to 1 when watchpoint is hit for a write
183  // access
184  uint32_t m_ignore_count; // Number of times to ignore this watchpoint
185  uint32_t m_false_alarms; // Number of false alarms.
186  std::string m_decl_str; // Declaration information, if any.
187  std::string m_watch_spec_str; // Spec for the watchpoint.
188  lldb::ValueObjectSP m_old_value_sp;
189  lldb::ValueObjectSP m_new_value_sp;
191  Status m_error; // An error object describing errors associated with this
192  // watchpoint.
194  m_options; // Settable watchpoint options, which is a delegate to handle
195  // the callback machinery.
197 
198  std::unique_ptr<UserExpression> m_condition_up; // The condition to test.
199 
200  void SetID(lldb::watch_id_t id) { m_id = id; }
201 
202  void SendWatchpointChangedEvent(lldb::WatchpointEventType eventKind);
203 
204  void SendWatchpointChangedEvent(WatchpointEventData *data);
205 
206  Watchpoint(const Watchpoint &) = delete;
207  const Watchpoint &operator=(const Watchpoint &) = delete;
208 };
209 
210 } // namespace lldb_private
211 
212 #endif // LLDB_BREAKPOINT_WATCHPOINT_H
lldb_private::Watchpoint::m_options
WatchpointOptions m_options
Definition: Watchpoint.h:194
lldb_private::Watchpoint::m_error
Status m_error
Definition: Watchpoint.h:191
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::StoppointSite::m_id
lldb::break_id_t m_id
Stoppoint site ID.
Definition: StoppointSite.h:53
lldb_private::Watchpoint::m_watch_was_read
uint32_t m_watch_was_read
Definition: Watchpoint.h:181
lldb_private::Watchpoint::WatchpointEventData::GetFlavorString
static ConstString GetFlavorString()
Definition: Watchpoint.cpp:338
lldb_private::Watchpoint::SetID
void SetID(lldb::watch_id_t id)
Definition: Watchpoint.h:200
lldb_private::StoppointCallbackContext
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Definition: StoppointCallbackContext.h:26
lldb_private::Event
Definition: Event.h:180
lldb_private::Watchpoint::TurnOffEphemeralMode
void TurnOffEphemeralMode()
Definition: Watchpoint.cpp:228
lldb_private::Watchpoint::IsWatchVariable
bool IsWatchVariable() const
Definition: Watchpoint.cpp:101
lldb_private::Watchpoint::GetConditionText
const char * GetConditionText() const
Return a pointer to the text of the condition expression.
Definition: Watchpoint.cpp:302
lldb_private::Watchpoint::IsHardware
bool IsHardware() const override
Definition: Watchpoint.cpp:96
lldb_private::Watchpoint::WatchpointEventData::GetWatchpointFromEvent
static lldb::WatchpointSP GetWatchpointFromEvent(const lldb::EventSP &event_sp)
Definition: Watchpoint.cpp:380
lldb_private::Watchpoint::GetCompilerType
const CompilerType & GetCompilerType()
Definition: Watchpoint.h:155
lldb_private::Watchpoint::IncrementFalseAlarmsAndReviseHitCount
void IncrementFalseAlarmsAndReviseHitCount()
Definition: Watchpoint.cpp:124
lldb_private::Watchpoint::m_watch_write
uint32_t m_watch_write
Definition: Watchpoint.h:180
lldb_private::Watchpoint::m_target
Target & m_target
Definition: Watchpoint.h:166
lldb_private::Watchpoint::ClearCallback
void ClearCallback()
Definition: Watchpoint.cpp:83
lldb_private::EventData
Definition: Event.h:36
lldb_private::Watchpoint::m_ignore_count
uint32_t m_ignore_count
Definition: Watchpoint.h:184
lldb_private::Watchpoint::SetWatchpointType
void SetWatchpointType(uint32_t type, bool notify=true)
Definition: Watchpoint.cpp:256
lldb_private::Watchpoint::SetWatchSpec
void SetWatchSpec(const std::string &str)
Definition: Watchpoint.cpp:92
lldb_private::Watchpoint::InvokeCallback
bool InvokeCallback(StoppointCallbackContext *context)
Invoke the callback action when the watchpoint is hit.
Definition: Watchpoint.cpp:279
lldb_private::Watchpoint::~Watchpoint
~Watchpoint() override
lldb_private::Watchpoint::m_old_value_sp
lldb::ValueObjectSP m_old_value_sp
Definition: Watchpoint.h:188
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Watchpoint::WatchpointEventData::GetFlavor
ConstString GetFlavor() const override
Definition: Watchpoint.cpp:343
lldb_private::Watchpoint::ShouldStop
bool ShouldStop(StoppointCallbackContext *context) override
Definition: Watchpoint.cpp:140
lldb_private::Target
Definition: Target.h:450
lldb_private::Watchpoint::SetDeclInfo
void SetDeclInfo(const std::string &str)
Definition: Watchpoint.cpp:88
lldb_private::Watchpoint::WatchpointEventData::~WatchpointEventData
~WatchpointEventData() override
lldb_private::Watchpoint::SetEnabled
void SetEnabled(bool enabled, bool notify=true)
Definition: Watchpoint.cpp:238
lldb_private::Watchpoint::m_type
CompilerType m_type
Definition: Watchpoint.h:190
lldb_private::Watchpoint::DumpWithLevel
void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
Definition: Watchpoint.cpp:185
Target.h
lldb_private::Watchpoint::IsEnabled
bool IsEnabled() const
Definition: Watchpoint.cpp:219
lldb_private::Watchpoint::GetTarget
Target & GetTarget()
Definition: Watchpoint.h:97
WatchpointOptions.h
lldb_private::Watchpoint::m_disabled_count
uint32_t m_disabled_count
Definition: Watchpoint.h:174
lldb_private::Watchpoint::m_watch_read
uint32_t m_watch_read
Definition: Watchpoint.h:179
lldb_private::Watchpoint::m_condition_up
std::unique_ptr< UserExpression > m_condition_up
Definition: Watchpoint.h:198
lldb_private::Watchpoint::GetWatchSpec
std::string GetWatchSpec()
Definition: Watchpoint.cpp:90
lldb_private::Watchpoint::m_is_ephemeral
bool m_is_ephemeral
Definition: Watchpoint.h:170
lldb_private::Watchpoint::DumpSnapshots
void DumpSnapshots(Stream *s, const char *prefix=nullptr) const
Definition: Watchpoint.cpp:156
lldb_private::Watchpoint::IsDisabledDuringEphemeralMode
bool IsDisabledDuringEphemeralMode()
Definition: Watchpoint.cpp:234
lldb_private::Watchpoint::m_watch_was_written
uint32_t m_watch_was_written
Definition: Watchpoint.h:182
lldb_private::Watchpoint::operator=
const Watchpoint & operator=(const Watchpoint &)=delete
lldb_private::Watchpoint
Definition: Watchpoint.h:24
lldb_private::Watchpoint::SetIgnoreCount
void SetIgnoreCount(uint32_t n)
Definition: Watchpoint.cpp:272
lldb_private::Watchpoint::SendWatchpointChangedEvent
void SendWatchpointChangedEvent(lldb::WatchpointEventType eventKind)
Definition: Watchpoint.cpp:309
lldb_private::WatchpointOptions
Definition: WatchpointOptions.h:25
lldb_private::Watchpoint::m_is_watch_variable
bool m_is_watch_variable
Definition: Watchpoint.h:169
lldb_private::Watchpoint::m_is_hardware
bool m_is_hardware
Definition: Watchpoint.h:168
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::Watchpoint::WatchpointRead
bool WatchpointRead() const
Definition: Watchpoint.cpp:266
lldb_private::Watchpoint::WatchpointEventData::operator=
const WatchpointEventData & operator=(const WatchpointEventData &)=delete
lldb_private::Watchpoint::m_decl_str
std::string m_decl_str
Definition: Watchpoint.h:186
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb::watch_id_t
int32_t watch_id_t
Definition: lldb-types.h:89
lldb_private::Watchpoint::m_new_value_sp
lldb::ValueObjectSP m_new_value_sp
Definition: Watchpoint.h:189
CompilerType.h
lldb_private::Watchpoint::ResetHistoricValues
void ResetHistoricValues()
Definition: Watchpoint.h:161
UserID.h
lldb_private::Watchpoint::TurnOnEphemeralMode
void TurnOnEphemeralMode()
Definition: Watchpoint.cpp:226
lldb_private::Watchpoint::m_watch_spec_str
std::string m_watch_spec_str
Definition: Watchpoint.h:187
lldb_private::Watchpoint::CaptureWatchedValue
bool CaptureWatchedValue(const ExecutionContext &exe_ctx)
Definition: Watchpoint.cpp:105
lldb_private::Watchpoint::SetCondition
void SetCondition(const char *condition)
Set the watchpoint's condition.
Definition: Watchpoint.cpp:283
lldb-private.h
lldb_private::Watchpoint::GetError
const Status & GetError()
Definition: Watchpoint.h:98
lldb_private::Watchpoint::Watchpoint
Watchpoint(Target &target, lldb::addr_t addr, uint32_t size, const CompilerType *type, bool hardware=true)
Definition: Watchpoint.cpp:26
lldb_private::Watchpoint::WatchpointEventData::GetWatchpoint
lldb::WatchpointSP & GetWatchpoint()
Definition: Watchpoint.cpp:347
lldb_private::Status
Definition: Status.h:44
lldb_private::WatchpointList
Definition: WatchpointList.h:27
lldb_private::Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::EventSP &event_sp)
Definition: Watchpoint.cpp:370
uint32_t
lldb_private::Watchpoint::WatchpointEventData::GetEventDataFromEvent
static const WatchpointEventData * GetEventDataFromEvent(const Event *event_sp)
Definition: Watchpoint.cpp:359
lldb_private::Watchpoint::m_false_alarms
uint32_t m_false_alarms
Definition: Watchpoint.h:185
lldb_private::Watchpoint::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level)
Definition: Watchpoint.cpp:146
id
void * id
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:20
lldb_private::Watchpoint::WatchpointEventData::m_new_watchpoint_sp
lldb::WatchpointSP m_new_watchpoint_sp
Definition: Watchpoint.h:55
lldb_private::Watchpoint::Dump
void Dump(Stream *s) const override
Definition: Watchpoint.cpp:150
lldb_private::Watchpoint::SetWatchVariable
void SetWatchVariable(bool val)
Definition: Watchpoint.cpp:103
StoppointSite.h
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Watchpoint::WatchpointEventData::m_watchpoint_event
lldb::WatchpointEventType m_watchpoint_event
Definition: Watchpoint.h:54
lldb_private::Watchpoint::GetOptions
WatchpointOptions * GetOptions()
Returns the WatchpointOptions structure set for this watchpoint.
Definition: Watchpoint.h:104
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Watchpoint::WatchpointEventData::GetWatchpointEventType
lldb::WatchpointEventType GetWatchpointEventType() const
Definition: Watchpoint.cpp:352
lldb_private::Watchpoint::GetIgnoreCount
uint32_t GetIgnoreCount() const
Definition: Watchpoint.cpp:270
lldb_private::Watchpoint::m_enabled
bool m_enabled
Definition: Watchpoint.h:167
lldb_private::Watchpoint::WatchpointEventData::WatchpointEventData
WatchpointEventData(lldb::WatchpointEventType sub_type, const lldb::WatchpointSP &new_watchpoint_sp)
lldb_private::Watchpoint::m_being_created
bool m_being_created
Definition: Watchpoint.h:196
lldb_private::Watchpoint::SetCallback
void SetCallback(WatchpointHitCallback callback, void *callback_baton, bool is_synchronous=false)
Set the callback action invoked when the watchpoint is hit.
Definition: Watchpoint.cpp:64
lldb_private::Watchpoint::WatchpointWrite
bool WatchpointWrite() const
Definition: Watchpoint.cpp:268
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb_private::StoppointSite
Definition: StoppointSite.h:18
lldb_private::Watchpoint::WatchpointEventData
Definition: Watchpoint.h:27
lldb_private::Watchpoint::WatchpointEventData::Dump
void Dump(Stream *s) const override
Definition: Watchpoint.cpp:356