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