Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1 | //===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===// |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBWatchpoint.h" |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBDefines.h" |
| 12 | #include "lldb/API/SBAddress.h" |
| 13 | #include "lldb/API/SBDebugger.h" |
| 14 | #include "lldb/API/SBStream.h" |
| 15 | |
| 16 | #include "lldb/lldb-types.h" |
| 17 | #include "lldb/lldb-defines.h" |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/Watchpoint.h" |
| 19 | #include "lldb/Breakpoint/WatchpointList.h" |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Log.h" |
| 21 | #include "lldb/Core/Stream.h" |
| 22 | #include "lldb/Core/StreamFile.h" |
| 23 | #include "lldb/Target/Target.h" |
| 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
| 28 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 29 | SBWatchpoint::SBWatchpoint () : |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 30 | m_opaque_sp () |
| 31 | { |
| 32 | } |
| 33 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 34 | SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp) : |
| 35 | m_opaque_sp (wp_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 36 | { |
| 37 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 38 | |
| 39 | if (log) |
| 40 | { |
| 41 | SBStream sstr; |
| 42 | GetDescription (sstr, lldb::eDescriptionLevelBrief); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 43 | log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp" |
| 44 | "=%p) => this.sp = %p (%s)", wp_sp.get(), m_opaque_sp.get(), sstr.GetData()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 48 | SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) : |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 49 | m_opaque_sp (rhs.m_opaque_sp) |
| 50 | { |
| 51 | } |
| 52 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 53 | const SBWatchpoint & |
| 54 | SBWatchpoint::operator = (const SBWatchpoint &rhs) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 55 | { |
| 56 | if (this != &rhs) |
| 57 | m_opaque_sp = rhs.m_opaque_sp; |
| 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 62 | SBWatchpoint::~SBWatchpoint () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 66 | watch_id_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 67 | SBWatchpoint::GetID () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 68 | { |
| 69 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 70 | |
| 71 | watch_id_t watch_id = LLDB_INVALID_WATCH_ID; |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 72 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 73 | if (watchpoint_sp) |
| 74 | watch_id = watchpoint_sp->GetID(); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 75 | |
| 76 | if (log) |
| 77 | { |
| 78 | if (watch_id == LLDB_INVALID_WATCH_ID) |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 79 | log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", watchpoint_sp.get()); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 80 | else |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 81 | log->Printf ("SBWatchpoint(%p)::GetID () => %u", watchpoint_sp.get(), watch_id); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return watch_id; |
| 85 | } |
| 86 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 87 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 88 | SBWatchpoint::IsValid() const |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 89 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 90 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 91 | if (watchpoint_sp && watchpoint_sp->GetError().Success()) |
Johnny Chen | 41a55ef | 2011-10-14 19:15:48 +0000 | [diff] [blame] | 92 | return true; |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 93 | return false; |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | SBError |
| 97 | SBWatchpoint::GetError () |
| 98 | { |
| 99 | SBError sb_error; |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 100 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 101 | if (watchpoint_sp) |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 102 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 103 | sb_error.SetError(watchpoint_sp->GetError()); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 104 | } |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 105 | return sb_error; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 108 | int32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 109 | SBWatchpoint::GetHardwareIndex () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 110 | { |
| 111 | int32_t hw_index = -1; |
| 112 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 113 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 114 | if (watchpoint_sp) |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 115 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 116 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 117 | hw_index = watchpoint_sp->GetHardwareIndex(); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | return hw_index; |
| 121 | } |
| 122 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 123 | addr_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 124 | SBWatchpoint::GetWatchAddress () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 125 | { |
| 126 | addr_t ret_addr = LLDB_INVALID_ADDRESS; |
| 127 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 128 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 129 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 130 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 131 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 132 | ret_addr = watchpoint_sp->GetLoadAddress(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | return ret_addr; |
| 136 | } |
| 137 | |
| 138 | size_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 139 | SBWatchpoint::GetWatchSize () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 140 | { |
| 141 | size_t watch_size = 0; |
| 142 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 143 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 144 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 145 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 146 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 147 | watch_size = watchpoint_sp->GetByteSize(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | return watch_size; |
| 151 | } |
| 152 | |
| 153 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 154 | SBWatchpoint::SetEnabled (bool enabled) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 155 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 156 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 157 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 158 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 159 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 160 | watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
| 164 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 165 | SBWatchpoint::IsEnabled () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 166 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 167 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 168 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 169 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 170 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 171 | return watchpoint_sp->IsEnabled(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 172 | } |
| 173 | else |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 178 | SBWatchpoint::GetHitCount () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 179 | { |
| 180 | uint32_t count = 0; |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 181 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 182 | if (watchpoint_sp) |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 183 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 184 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 185 | count = watchpoint_sp->GetHitCount(); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 189 | if (log) |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 190 | log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 191 | |
| 192 | return count; |
| 193 | } |
| 194 | |
| 195 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 196 | SBWatchpoint::GetIgnoreCount () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 197 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 198 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 199 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 200 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 201 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 202 | return watchpoint_sp->GetIgnoreCount(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 203 | } |
| 204 | else |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 209 | SBWatchpoint::SetIgnoreCount (uint32_t n) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 210 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 211 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 212 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 213 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 214 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 215 | watchpoint_sp->SetIgnoreCount (n); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 219 | const char * |
| 220 | SBWatchpoint::GetCondition () |
| 221 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 222 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 223 | if (watchpoint_sp) |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 224 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 225 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 226 | return watchpoint_sp->GetConditionText (); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 227 | } |
| 228 | return NULL; |
| 229 | } |
| 230 | |
| 231 | void |
| 232 | SBWatchpoint::SetCondition (const char *condition) |
| 233 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 234 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 235 | if (watchpoint_sp) |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 236 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 237 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 238 | watchpoint_sp->SetCondition (condition); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 242 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 243 | SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 244 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 245 | Stream &strm = description.ref(); |
| 246 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 247 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 248 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 249 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 250 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 251 | watchpoint_sp->GetDescription (&strm, level); |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 252 | strm.EOL(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 253 | } |
| 254 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 255 | strm.PutCString ("No value"); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 256 | |
| 257 | return true; |
| 258 | } |
| 259 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 260 | void |
| 261 | SBWatchpoint::Clear () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 262 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 263 | m_opaque_sp.reset(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 266 | lldb::WatchpointSP |
| 267 | SBWatchpoint::GetSP () const |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 268 | { |
| 269 | return m_opaque_sp; |
| 270 | } |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 271 | |
| 272 | void |
| 273 | SBWatchpoint::SetSP (const lldb::WatchpointSP &sp) |
| 274 | { |
| 275 | m_opaque_sp = sp; |
| 276 | } |