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 | { |
Jim Ingham | 9880efa | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 90 | return (bool) m_opaque_sp; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Jim Ingham | a442da2 | 2012-06-06 18:46:25 +0000 | [diff] [blame] | 93 | SBError |
| 94 | SBWatchpoint::GetError () |
| 95 | { |
| 96 | SBError sb_error; |
| 97 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 98 | if (watchpoint_sp) |
| 99 | { |
| 100 | sb_error.SetError(watchpoint_sp->GetError()); |
| 101 | } |
| 102 | return sb_error; |
| 103 | } |
| 104 | |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 105 | int32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 106 | SBWatchpoint::GetHardwareIndex () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 107 | { |
| 108 | int32_t hw_index = -1; |
| 109 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 110 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 111 | if (watchpoint_sp) |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 112 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 113 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 114 | hw_index = watchpoint_sp->GetHardwareIndex(); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | return hw_index; |
| 118 | } |
| 119 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 120 | addr_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 121 | SBWatchpoint::GetWatchAddress () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 122 | { |
| 123 | addr_t ret_addr = LLDB_INVALID_ADDRESS; |
| 124 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 125 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 126 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 127 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 128 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 129 | ret_addr = watchpoint_sp->GetLoadAddress(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | return ret_addr; |
| 133 | } |
| 134 | |
| 135 | size_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 136 | SBWatchpoint::GetWatchSize () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 137 | { |
| 138 | size_t watch_size = 0; |
| 139 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 140 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 141 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 142 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 143 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 144 | watch_size = watchpoint_sp->GetByteSize(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | return watch_size; |
| 148 | } |
| 149 | |
| 150 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 151 | SBWatchpoint::SetEnabled (bool enabled) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 152 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 153 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 154 | if (watchpoint_sp) |
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 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 157 | watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 162 | SBWatchpoint::IsEnabled () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 163 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 164 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 165 | if (watchpoint_sp) |
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 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 168 | return watchpoint_sp->IsEnabled(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 169 | } |
| 170 | else |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 175 | SBWatchpoint::GetHitCount () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 176 | { |
| 177 | uint32_t count = 0; |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 178 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 179 | if (watchpoint_sp) |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 180 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 181 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 182 | count = watchpoint_sp->GetHitCount(); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 186 | if (log) |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 187 | log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 188 | |
| 189 | return count; |
| 190 | } |
| 191 | |
| 192 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 193 | SBWatchpoint::GetIgnoreCount () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 194 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 195 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 196 | if (watchpoint_sp) |
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 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 199 | return watchpoint_sp->GetIgnoreCount(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 200 | } |
| 201 | else |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 206 | SBWatchpoint::SetIgnoreCount (uint32_t n) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 207 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 208 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 209 | if (watchpoint_sp) |
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 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 212 | watchpoint_sp->SetIgnoreCount (n); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 216 | const char * |
| 217 | SBWatchpoint::GetCondition () |
| 218 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 219 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 220 | if (watchpoint_sp) |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 221 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 222 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 223 | return watchpoint_sp->GetConditionText (); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 224 | } |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | void |
| 229 | SBWatchpoint::SetCondition (const char *condition) |
| 230 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 231 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 232 | if (watchpoint_sp) |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 233 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 234 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 235 | watchpoint_sp->SetCondition (condition); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 239 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 240 | SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 241 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 242 | Stream &strm = description.ref(); |
| 243 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 244 | lldb::WatchpointSP watchpoint_sp(GetSP()); |
| 245 | if (watchpoint_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 246 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 247 | Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); |
| 248 | watchpoint_sp->GetDescription (&strm, level); |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 249 | strm.EOL(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 250 | } |
| 251 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 252 | strm.PutCString ("No value"); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 253 | |
| 254 | return true; |
| 255 | } |
| 256 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 257 | void |
| 258 | SBWatchpoint::Clear () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 259 | { |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 260 | m_opaque_sp.reset(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 263 | lldb::WatchpointSP |
| 264 | SBWatchpoint::GetSP () const |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 265 | { |
| 266 | return m_opaque_sp; |
| 267 | } |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 268 | |
| 269 | void |
| 270 | SBWatchpoint::SetSP (const lldb::WatchpointSP &sp) |
| 271 | { |
| 272 | m_opaque_sp = sp; |
| 273 | } |