Watchpoint.h revision f84e566ff66dceb58674494b26408d3c83921ab9
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 15// C++ Includes 16#include <list> 17#include <string> 18 19// Other libraries and framework includes 20 21// Project 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" 27 28namespace lldb_private { 29 30class Watchpoint : 31 public StoppointLocation 32{ 33public: 34 35 Watchpoint (lldb::addr_t addr, size_t size, bool hardware = true); 36 37 ~Watchpoint (); 38 39 void 40 IncrementFalseAlarmsAndReviseHitCount(); 41 42 bool 43 IsEnabled () const; 44 45 void 46 SetEnabled (bool enabled); 47 48 virtual bool 49 IsHardware () const; 50 51 virtual bool 52 ShouldStop (StoppointCallbackContext *context); 53 54 bool WatchpointRead () const; 55 bool WatchpointWrite () const; 56 uint32_t GetIgnoreCount () const; 57 void SetIgnoreCount (uint32_t n); 58 void SetWatchpointType (uint32_t type); 59 void SetDeclInfo (const std::string &str); 60 std::string GetWatchSpec(); 61 void SetWatchSpec (const std::string &str); 62 63 // Snapshot management interface. 64 bool IsWatchVariable() const; 65 void SetWatchVariable(bool val); 66 std::string GetOldSnapshot() const; 67 void SetOldSnapshot (const std::string &str); 68 std::string GetNewSnapshot() const; 69 void SetNewSnapshot (const std::string &str); 70 uint64_t GetOldSnapshotVal() const; 71 void SetOldSnapshotVal (uint64_t val); 72 uint64_t GetNewSnapshotVal() const; 73 void SetNewSnapshotVal (uint64_t val); 74 void ClearSnapshots(); 75 76 void GetDescription (Stream *s, lldb::DescriptionLevel level); 77 void Dump (Stream *s) const; 78 void DumpSnapshots (Stream *s, const char * prefix = NULL) const; 79 void DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const; 80 Target &GetTarget() { return *m_target; } 81 const Error &GetError() { return m_error; } 82 83 //------------------------------------------------------------------ 84 /// Returns the WatchpointOptions structure set for this watchpoint. 85 /// 86 /// @return 87 /// A pointer to this watchpoint's WatchpointOptions. 88 //------------------------------------------------------------------ 89 WatchpointOptions * 90 GetOptions () { return &m_options; } 91 92 //------------------------------------------------------------------ 93 /// Set the callback action invoked when the watchpoint is hit. 94 /// 95 /// @param[in] callback 96 /// The method that will get called when the watchpoint is hit. 97 /// @param[in] callback_baton 98 /// A void * pointer that will get passed back to the callback function. 99 /// @param[in] is_synchronous 100 /// If \b true the callback will be run on the private event thread 101 /// before the stop event gets reported. If false, the callback will get 102 /// handled on the public event thead after the stop has been posted. 103 /// 104 /// @return 105 /// \b true if the process should stop when you hit the watchpoint. 106 /// \b false if it should continue. 107 //------------------------------------------------------------------ 108 void 109 SetCallback (WatchpointHitCallback callback, 110 void *callback_baton, 111 bool is_synchronous = false); 112 113 void 114 SetCallback (WatchpointHitCallback callback, 115 const lldb::BatonSP &callback_baton_sp, 116 bool is_synchronous = false); 117 118 void ClearCallback(); 119 120 //------------------------------------------------------------------ 121 /// Invoke the callback action when the watchpoint is hit. 122 /// 123 /// @param[in] context 124 /// Described the watchpoint event. 125 /// 126 /// @return 127 /// \b true if the target should stop at this watchpoint and \b false not. 128 //------------------------------------------------------------------ 129 bool 130 InvokeCallback (StoppointCallbackContext *context); 131 132 //------------------------------------------------------------------ 133 // Condition 134 //------------------------------------------------------------------ 135 //------------------------------------------------------------------ 136 /// Set the watchpoint's condition. 137 /// 138 /// @param[in] condition 139 /// The condition expression to evaluate when the watchpoint is hit. 140 /// Pass in NULL to clear the condition. 141 //------------------------------------------------------------------ 142 void SetCondition (const char *condition); 143 144 //------------------------------------------------------------------ 145 /// Return a pointer to the text of the condition expression. 146 /// 147 /// @return 148 /// A pointer to the condition expression text, or NULL if no 149 // condition has been set. 150 //------------------------------------------------------------------ 151 const char *GetConditionText () const; 152 153 void 154 TurnOnEphemeralMode(); 155 156 void 157 TurnOffEphemeralMode(); 158 159private: 160 friend class Target; 161 friend class WatchpointList; 162 163 void SetTarget(Target *target_ptr) { m_target = target_ptr; } 164 void ResetHitCount() { m_hit_count = 0; } 165 166 Target *m_target; 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, meaning that it is 171 // undergoing a pair of temporary disable/enable actions to avoid recursively 172 // triggering further watchpoint events. 173 uint32_t m_watch_read:1, // 1 if we stop when the watched data is read from 174 m_watch_write:1, // 1 if we stop when the watched data is written to 175 m_watch_was_read:1, // Set to 1 when watchpoint is hit for a read access 176 m_watch_was_written:1; // Set to 1 when watchpoint is hit for a write access 177 uint32_t m_ignore_count; // Number of times to ignore this watchpoint 178 uint32_t m_false_alarms; // Number of false alarms. 179 std::string m_decl_str; // Declaration information, if any. 180 std::string m_watch_spec_str; // Spec for the watchpoint. 181 std::string m_snapshot_old_str; // Old snapshot for the watchpoint value as by ValueObject::DumpValueObject(). 182 std::string m_snapshot_new_str; // New Snapshot for the watchpoint value as by ValueObject::DumpValueObject(). 183 uint64_t m_snapshot_old_val; // Old snapshot for the watchpoint bytes. 184 uint64_t m_snapshot_new_val; // New Snapshot for the watchpoint bytes. 185 Error m_error; // An error object describing errors associated with this watchpoint. 186 WatchpointOptions m_options; // Settable watchpoint options, which is a delegate to handle 187 // the callback machinery. 188 189 std::auto_ptr<ClangUserExpression> m_condition_ap; // The condition to test. 190 191 void SetID(lldb::watch_id_t id) { m_loc_id = id; } 192 193 DISALLOW_COPY_AND_ASSIGN (Watchpoint); 194}; 195 196} // namespace lldb_private 197 198#endif // liblldb_Watchpoint_h_ 199