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