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" |
| 18 | #include "lldb/Breakpoint/WatchpointLocation.h" |
| 19 | #include "lldb/Breakpoint/WatchpointLocationList.h" |
| 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 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 34 | SBWatchpoint::SBWatchpoint (const lldb::WatchpointLocationSP &watch_loc_sp) : |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 35 | m_opaque_sp (watch_loc_sp) |
| 36 | { |
| 37 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 38 | |
| 39 | if (log) |
| 40 | { |
| 41 | SBStream sstr; |
| 42 | GetDescription (sstr, lldb::eDescriptionLevelBrief); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 43 | log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointLocationsSP &watch_loc_sp" |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 44 | "=%p) => this.sp = %p (%s)", watch_loc_sp.get(), m_opaque_sp.get(), sstr.GetData()); |
| 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 | { |
| 89 | return m_opaque_sp.get() != NULL; |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 90 | #if 0 |
| 91 | if (m_opaque_sp) |
| 92 | return m_opaque_sp->GetError().Success(); |
| 93 | return false; |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | SBError |
| 98 | SBWatchpoint::GetError () |
| 99 | { |
| 100 | SBError sb_error; |
| 101 | #if 0 |
| 102 | if (m_opaque_sp) |
| 103 | { |
| 104 | // TODO: Johnny fill this in |
| 105 | sb_error.ref() = m_opaque_sp->GetError(); |
| 106 | } |
| 107 | #endif |
| 108 | return sb_error; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 111 | int32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 112 | SBWatchpoint::GetHardwareIndex () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 113 | { |
| 114 | int32_t hw_index = -1; |
| 115 | |
| 116 | if (m_opaque_sp) |
| 117 | { |
| 118 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 119 | hw_index = m_opaque_sp->GetHardwareIndex(); |
| 120 | } |
| 121 | |
| 122 | return hw_index; |
| 123 | } |
| 124 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 125 | addr_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 126 | SBWatchpoint::GetWatchAddress () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 127 | { |
| 128 | addr_t ret_addr = LLDB_INVALID_ADDRESS; |
| 129 | |
| 130 | if (m_opaque_sp) |
| 131 | { |
| 132 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 133 | ret_addr = m_opaque_sp->GetLoadAddress(); |
| 134 | } |
| 135 | |
| 136 | return ret_addr; |
| 137 | } |
| 138 | |
| 139 | size_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 140 | SBWatchpoint::GetWatchSize () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 141 | { |
| 142 | size_t watch_size = 0; |
| 143 | |
| 144 | if (m_opaque_sp) |
| 145 | { |
| 146 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 147 | watch_size = m_opaque_sp->GetByteSize(); |
| 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 | { |
| 156 | if (m_opaque_sp) |
| 157 | { |
| 158 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 159 | m_opaque_sp->GetTarget().DisableWatchpointLocationByID(m_opaque_sp->GetID()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 164 | SBWatchpoint::IsEnabled () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 165 | { |
| 166 | if (m_opaque_sp) |
| 167 | { |
| 168 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 169 | return m_opaque_sp->IsEnabled(); |
| 170 | } |
| 171 | else |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 176 | SBWatchpoint::GetHitCount () |
Johnny Chen | 092bd15 | 2011-09-27 01:19:20 +0000 | [diff] [blame] | 177 | { |
| 178 | uint32_t count = 0; |
| 179 | if (m_opaque_sp) |
| 180 | { |
| 181 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 182 | count = m_opaque_sp->GetHitCount(); |
| 183 | } |
| 184 | |
| 185 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 186 | if (log) |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 187 | log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", m_opaque_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 | { |
| 195 | if (m_opaque_sp) |
| 196 | { |
| 197 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 198 | return m_opaque_sp->GetIgnoreCount(); |
| 199 | } |
| 200 | else |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | void |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 205 | SBWatchpoint::SetIgnoreCount (uint32_t n) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 206 | { |
| 207 | if (m_opaque_sp) |
| 208 | { |
| 209 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 210 | m_opaque_sp->SetIgnoreCount (n); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 215 | SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 216 | { |
| 217 | if (m_opaque_sp) |
| 218 | { |
| 219 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 220 | description.ref(); |
| 221 | m_opaque_sp->GetDescription (description.get(), level); |
| 222 | description.get()->EOL(); |
| 223 | } |
| 224 | else |
| 225 | description.Printf ("No value"); |
| 226 | |
| 227 | return true; |
| 228 | } |
| 229 | |
| 230 | lldb_private::WatchpointLocation * |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 231 | SBWatchpoint::operator->() |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 232 | { |
| 233 | return m_opaque_sp.get(); |
| 234 | } |
| 235 | |
| 236 | lldb_private::WatchpointLocation * |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 237 | SBWatchpoint::get() |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 238 | { |
| 239 | return m_opaque_sp.get(); |
| 240 | } |
| 241 | |
| 242 | lldb::WatchpointLocationSP & |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame^] | 243 | SBWatchpoint::operator *() |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 244 | { |
| 245 | return m_opaque_sp; |
| 246 | } |