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; |
| 72 | if (m_opaque_sp) |
| 73 | watch_id = m_opaque_sp->GetID(); |
| 74 | |
| 75 | if (log) |
| 76 | { |
| 77 | if (watch_id == LLDB_INVALID_WATCH_ID) |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 78 | log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", m_opaque_sp.get()); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 79 | else |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 80 | log->Printf ("SBWatchpoint(%p)::GetID () => %u", m_opaque_sp.get(), watch_id); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | return watch_id; |
| 84 | } |
| 85 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 86 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 87 | SBWatchpoint::IsValid() const |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 88 | { |
Johnny Chen | 41a55ef | 2011-10-14 19:15:48 +0000 | [diff] [blame^] | 89 | if (m_opaque_sp && m_opaque_sp->GetError().Success()) |
| 90 | return true; |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 91 | return false; |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | SBError |
| 95 | SBWatchpoint::GetError () |
| 96 | { |
| 97 | SBError sb_error; |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 98 | if (m_opaque_sp) |
| 99 | { |
Johnny Chen | 41a55ef | 2011-10-14 19:15:48 +0000 | [diff] [blame^] | 100 | sb_error.SetError(m_opaque_sp->GetError()); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 101 | } |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 102 | return sb_error; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 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 | |
| 110 | if (m_opaque_sp) |
| 111 | { |
| 112 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 113 | hw_index = m_opaque_sp->GetHardwareIndex(); |
| 114 | } |
| 115 | |
| 116 | return hw_index; |
| 117 | } |
| 118 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 119 | addr_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 120 | SBWatchpoint::GetWatchAddress () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 121 | { |
| 122 | addr_t ret_addr = LLDB_INVALID_ADDRESS; |
| 123 | |
| 124 | if (m_opaque_sp) |
| 125 | { |
| 126 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 127 | ret_addr = m_opaque_sp->GetLoadAddress(); |
| 128 | } |
| 129 | |
| 130 | return ret_addr; |
| 131 | } |
| 132 | |
| 133 | size_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 134 | SBWatchpoint::GetWatchSize () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 135 | { |
| 136 | size_t watch_size = 0; |
| 137 | |
| 138 | if (m_opaque_sp) |
| 139 | { |
| 140 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 141 | watch_size = m_opaque_sp->GetByteSize(); |
| 142 | } |
| 143 | |
| 144 | return watch_size; |
| 145 | } |
| 146 | |
| 147 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 148 | SBWatchpoint::SetEnabled (bool enabled) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 149 | { |
| 150 | if (m_opaque_sp) |
| 151 | { |
| 152 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 153 | m_opaque_sp->GetTarget().DisableWatchpointByID(m_opaque_sp->GetID()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
| 157 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 158 | SBWatchpoint::IsEnabled () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 159 | { |
| 160 | if (m_opaque_sp) |
| 161 | { |
| 162 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 163 | return m_opaque_sp->IsEnabled(); |
| 164 | } |
| 165 | else |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 170 | SBWatchpoint::GetHitCount () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 171 | { |
| 172 | uint32_t count = 0; |
| 173 | if (m_opaque_sp) |
| 174 | { |
| 175 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 176 | count = m_opaque_sp->GetHitCount(); |
| 177 | } |
| 178 | |
| 179 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 180 | if (log) |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 181 | log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 182 | |
| 183 | return count; |
| 184 | } |
| 185 | |
| 186 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 187 | SBWatchpoint::GetIgnoreCount () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 188 | { |
| 189 | if (m_opaque_sp) |
| 190 | { |
| 191 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 192 | return m_opaque_sp->GetIgnoreCount(); |
| 193 | } |
| 194 | else |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 199 | SBWatchpoint::SetIgnoreCount (uint32_t n) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 200 | { |
| 201 | if (m_opaque_sp) |
| 202 | { |
| 203 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 204 | m_opaque_sp->SetIgnoreCount (n); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 209 | SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 210 | { |
| 211 | if (m_opaque_sp) |
| 212 | { |
| 213 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 214 | description.ref(); |
| 215 | m_opaque_sp->GetDescription (description.get(), level); |
| 216 | description.get()->EOL(); |
| 217 | } |
| 218 | else |
| 219 | description.Printf ("No value"); |
| 220 | |
| 221 | return true; |
| 222 | } |
| 223 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 224 | lldb_private::Watchpoint * |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 225 | SBWatchpoint::operator->() |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 226 | { |
| 227 | return m_opaque_sp.get(); |
| 228 | } |
| 229 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 230 | lldb_private::Watchpoint * |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 231 | SBWatchpoint::get() |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 232 | { |
| 233 | return m_opaque_sp.get(); |
| 234 | } |
| 235 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 236 | lldb::WatchpointSP & |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 237 | SBWatchpoint::operator *() |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 238 | { |
| 239 | return m_opaque_sp; |
| 240 | } |