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