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