blob: f5d72076487d2402b57aea6efe071683dd4e7167 [file] [log] [blame]
Greg Clayton1b282f92011-10-13 18:08:26 +00001//===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===//
Johnny Chen5d043462011-09-26 22:40:50 +00002//
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 Clayton1b282f92011-10-13 18:08:26 +000010#include "lldb/API/SBWatchpoint.h"
Johnny Chen5d043462011-09-26 22:40:50 +000011#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBDebugger.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000013#include "lldb/API/SBDefines.h"
Jim Ingham1b5792e2012-12-18 02:03:49 +000014#include "lldb/API/SBEvent.h"
Johnny Chen5d043462011-09-26 22:40:50 +000015#include "lldb/API/SBStream.h"
16
Johnny Chen01a67862011-10-14 00:42:25 +000017#include "lldb/Breakpoint/Watchpoint.h"
18#include "lldb/Breakpoint/WatchpointList.h"
Johnny Chen5d043462011-09-26 22:40:50 +000019#include "lldb/Core/Log.h"
20#include "lldb/Core/Stream.h"
21#include "lldb/Core/StreamFile.h"
22#include "lldb/Target/Target.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#include "lldb/lldb-defines.h"
24#include "lldb/lldb-types.h"
Johnny Chen5d043462011-09-26 22:40:50 +000025
26using namespace lldb;
27using namespace lldb_private;
28
Kate Stoneb9c1b512016-09-06 20:57:50 +000029SBWatchpoint::SBWatchpoint() : m_opaque_sp() {}
Johnny Chen5d043462011-09-26 22:40:50 +000030
Kate Stoneb9c1b512016-09-06 20:57:50 +000031SBWatchpoint::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 Chen5d043462011-09-26 22:40:50 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs)
46 : m_opaque_sp(rhs.m_opaque_sp) {}
Johnny Chen5d043462011-09-26 22:40:50 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048const SBWatchpoint &SBWatchpoint::operator=(const SBWatchpoint &rhs) {
49 if (this != &rhs)
50 m_opaque_sp = rhs.m_opaque_sp;
51 return *this;
Johnny Chen5d043462011-09-26 22:40:50 +000052}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054SBWatchpoint::~SBWatchpoint() {}
Johnny Chen5d043462011-09-26 22:40:50 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056watch_id_t SBWatchpoint::GetID() {
57 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 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 Chen5d043462011-09-26 22:40:50 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 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 Chen5d043462011-09-26 22:40:50 +000068 else
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 log->Printf("SBWatchpoint(%p)::GetID () => %u",
70 static_cast<void *>(watchpoint_sp.get()), watch_id);
71 }
72
73 return watch_id;
Johnny Chen5d043462011-09-26 22:40:50 +000074}
75
Kate Stoneb9c1b512016-09-06 20:57:50 +000076bool SBWatchpoint::IsValid() const { return (bool)m_opaque_sp; }
Johnny Chend4dd7992011-09-27 01:19:20 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078SBError 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 Chend4dd7992011-09-27 01:19:20 +000085}
86
Kate Stoneb9c1b512016-09-06 20:57:50 +000087int32_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 Chen5d043462011-09-26 22:40:50 +000098}
99
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100addr_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 Chen5d043462011-09-26 22:40:50 +0000111}
112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113size_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 Chen16dcf712011-10-17 18:58:00 +0000124}
125
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126void 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 Chen16dcf712011-10-17 18:58:00 +0000133}
134
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135bool 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 Chen5d043462011-09-26 22:40:50 +0000143}
144
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145uint32_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 Chen5d043462011-09-26 22:40:50 +0000160}
161
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162uint32_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 Chen5d043462011-09-26 22:40:50 +0000170}
Greg Clayton81e871e2012-02-04 02:27:34 +0000171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172void 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 Clayton81e871e2012-02-04 02:27:34 +0000179}
Jim Ingham1b5792e2012-12-18 02:03:49 +0000180
Kate Stoneb9c1b512016-09-06 20:57:50 +0000181const 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 Ingham1b5792e2012-12-18 02:03:49 +0000190
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191void 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
200bool 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
216void SBWatchpoint::Clear() { m_opaque_sp.reset(); }
217
218lldb::WatchpointSP SBWatchpoint::GetSP() const { return m_opaque_sp; }
219
220void SBWatchpoint::SetSP(const lldb::WatchpointSP &sp) { m_opaque_sp = sp; }
221
222bool SBWatchpoint::EventIsWatchpointEvent(const lldb::SBEvent &event) {
223 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) !=
224 NULL;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000225}
226
227WatchpointEventType
Kate Stoneb9c1b512016-09-06 20:57:50 +0000228SBWatchpoint::GetWatchpointEventTypeFromEvent(const SBEvent &event) {
229 if (event.IsValid())
230 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent(
231 event.GetSP());
232 return eWatchpointEventTypeInvalidType;
Jim Ingham1b5792e2012-12-18 02:03:49 +0000233}
234
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235SBWatchpoint 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 Ingham1b5792e2012-12-18 02:03:49 +0000241}