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