1 //===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBWatchpoint.h"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBDebugger.h"
13 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBEvent.h"
15 #include "lldb/API/SBStream.h"
17 #include "lldb/Breakpoint/Watchpoint.h"
18 #include "lldb/Breakpoint/WatchpointList.h"
19 #include "lldb/Core/StreamFile.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Target/Target.h"
22 #include "lldb/Utility/Log.h"
23 #include "lldb/Utility/Stream.h"
24 #include "lldb/lldb-defines.h"
25 #include "lldb/lldb-types.h"
28 using namespace lldb_private;
30 SBWatchpoint::SBWatchpoint() {}
32 SBWatchpoint::SBWatchpoint(const lldb::WatchpointSP &wp_sp)
33 : m_opaque_wp(wp_sp) {
34 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
38 GetDescription(sstr, lldb::eDescriptionLevelBrief);
39 LLDB_LOG(log, "watchpoint = {0} ({1})", wp_sp.get(), sstr.GetData());
43 SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs)
44 : m_opaque_wp(rhs.m_opaque_wp) {}
46 const SBWatchpoint &SBWatchpoint::operator=(const SBWatchpoint &rhs) {
47 m_opaque_wp = rhs.m_opaque_wp;
51 SBWatchpoint::~SBWatchpoint() {}
53 watch_id_t SBWatchpoint::GetID() {
54 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
56 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
57 lldb::WatchpointSP watchpoint_sp(GetSP());
59 watch_id = watchpoint_sp->GetID();
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()));
66 log->Printf("SBWatchpoint(%p)::GetID () => %u",
67 static_cast<void *>(watchpoint_sp.get()), watch_id);
73 bool SBWatchpoint::IsValid() const { return bool(m_opaque_wp.lock()); }
75 SBError SBWatchpoint::GetError() {
77 lldb::WatchpointSP watchpoint_sp(GetSP());
79 sb_error.SetError(watchpoint_sp->GetError());
84 int32_t SBWatchpoint::GetHardwareIndex() {
85 int32_t hw_index = -1;
87 lldb::WatchpointSP watchpoint_sp(GetSP());
89 std::lock_guard<std::recursive_mutex> guard(
90 watchpoint_sp->GetTarget().GetAPIMutex());
91 hw_index = watchpoint_sp->GetHardwareIndex();
97 addr_t SBWatchpoint::GetWatchAddress() {
98 addr_t ret_addr = LLDB_INVALID_ADDRESS;
100 lldb::WatchpointSP watchpoint_sp(GetSP());
102 std::lock_guard<std::recursive_mutex> guard(
103 watchpoint_sp->GetTarget().GetAPIMutex());
104 ret_addr = watchpoint_sp->GetLoadAddress();
110 size_t SBWatchpoint::GetWatchSize() {
111 size_t watch_size = 0;
113 lldb::WatchpointSP watchpoint_sp(GetSP());
115 std::lock_guard<std::recursive_mutex> guard(
116 watchpoint_sp->GetTarget().GetAPIMutex());
117 watch_size = watchpoint_sp->GetByteSize();
123 void SBWatchpoint::SetEnabled(bool enabled) {
124 lldb::WatchpointSP watchpoint_sp(GetSP());
126 Target &target = watchpoint_sp->GetTarget();
127 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
128 ProcessSP process_sp = target.GetProcessSP();
129 const bool notify = true;
132 process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
134 process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
136 watchpoint_sp->SetEnabled(enabled, notify);
141 bool SBWatchpoint::IsEnabled() {
142 lldb::WatchpointSP watchpoint_sp(GetSP());
144 std::lock_guard<std::recursive_mutex> guard(
145 watchpoint_sp->GetTarget().GetAPIMutex());
146 return watchpoint_sp->IsEnabled();
151 uint32_t SBWatchpoint::GetHitCount() {
153 lldb::WatchpointSP watchpoint_sp(GetSP());
155 std::lock_guard<std::recursive_mutex> guard(
156 watchpoint_sp->GetTarget().GetAPIMutex());
157 count = watchpoint_sp->GetHitCount();
160 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
162 log->Printf("SBWatchpoint(%p)::GetHitCount () => %u",
163 static_cast<void *>(watchpoint_sp.get()), count);
168 uint32_t SBWatchpoint::GetIgnoreCount() {
169 lldb::WatchpointSP watchpoint_sp(GetSP());
171 std::lock_guard<std::recursive_mutex> guard(
172 watchpoint_sp->GetTarget().GetAPIMutex());
173 return watchpoint_sp->GetIgnoreCount();
178 void SBWatchpoint::SetIgnoreCount(uint32_t n) {
179 lldb::WatchpointSP watchpoint_sp(GetSP());
181 std::lock_guard<std::recursive_mutex> guard(
182 watchpoint_sp->GetTarget().GetAPIMutex());
183 watchpoint_sp->SetIgnoreCount(n);
187 const char *SBWatchpoint::GetCondition() {
188 lldb::WatchpointSP watchpoint_sp(GetSP());
190 std::lock_guard<std::recursive_mutex> guard(
191 watchpoint_sp->GetTarget().GetAPIMutex());
192 return watchpoint_sp->GetConditionText();
197 void SBWatchpoint::SetCondition(const char *condition) {
198 lldb::WatchpointSP watchpoint_sp(GetSP());
200 std::lock_guard<std::recursive_mutex> guard(
201 watchpoint_sp->GetTarget().GetAPIMutex());
202 watchpoint_sp->SetCondition(condition);
206 bool SBWatchpoint::GetDescription(SBStream &description,
207 DescriptionLevel level) {
208 Stream &strm = description.ref();
210 lldb::WatchpointSP watchpoint_sp(GetSP());
212 std::lock_guard<std::recursive_mutex> guard(
213 watchpoint_sp->GetTarget().GetAPIMutex());
214 watchpoint_sp->GetDescription(&strm, level);
217 strm.PutCString("No value");
222 void SBWatchpoint::Clear() { m_opaque_wp.reset(); }
224 lldb::WatchpointSP SBWatchpoint::GetSP() const { return m_opaque_wp.lock(); }
226 void SBWatchpoint::SetSP(const lldb::WatchpointSP &sp) { m_opaque_wp = sp; }
228 bool SBWatchpoint::EventIsWatchpointEvent(const lldb::SBEvent &event) {
229 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) !=
234 SBWatchpoint::GetWatchpointEventTypeFromEvent(const SBEvent &event) {
236 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent(
238 return eWatchpointEventTypeInvalidType;
241 SBWatchpoint SBWatchpoint::GetWatchpointFromEvent(const lldb::SBEvent &event) {
242 SBWatchpoint sb_watchpoint;
245 Watchpoint::WatchpointEventData::GetWatchpointFromEvent(event.GetSP());
246 return sb_watchpoint;