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/Log.h"
20 #include "lldb/Core/Stream.h"
21 #include "lldb/Core/StreamFile.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/lldb-defines.h"
25 #include "lldb/lldb-types.h"
28 using namespace lldb_private;
30 SBWatchpoint::SBWatchpoint() : m_opaque_sp() {}
32 SBWatchpoint::SBWatchpoint(const lldb::WatchpointSP &wp_sp)
33 : m_opaque_sp(wp_sp) {
34 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
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());
46 SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs)
47 : m_opaque_sp(rhs.m_opaque_sp) {}
49 const SBWatchpoint &SBWatchpoint::operator=(const SBWatchpoint &rhs) {
51 m_opaque_sp = rhs.m_opaque_sp;
55 SBWatchpoint::~SBWatchpoint() {}
57 watch_id_t SBWatchpoint::GetID() {
58 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
60 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
61 lldb::WatchpointSP watchpoint_sp(GetSP());
63 watch_id = watchpoint_sp->GetID();
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()));
70 log->Printf("SBWatchpoint(%p)::GetID () => %u",
71 static_cast<void *>(watchpoint_sp.get()), watch_id);
77 bool SBWatchpoint::IsValid() const { return (bool)m_opaque_sp; }
79 SBError SBWatchpoint::GetError() {
81 lldb::WatchpointSP watchpoint_sp(GetSP());
83 sb_error.SetError(watchpoint_sp->GetError());
88 int32_t SBWatchpoint::GetHardwareIndex() {
89 int32_t hw_index = -1;
91 lldb::WatchpointSP watchpoint_sp(GetSP());
93 std::lock_guard<std::recursive_mutex> guard(
94 watchpoint_sp->GetTarget().GetAPIMutex());
95 hw_index = watchpoint_sp->GetHardwareIndex();
101 addr_t SBWatchpoint::GetWatchAddress() {
102 addr_t ret_addr = LLDB_INVALID_ADDRESS;
104 lldb::WatchpointSP watchpoint_sp(GetSP());
106 std::lock_guard<std::recursive_mutex> guard(
107 watchpoint_sp->GetTarget().GetAPIMutex());
108 ret_addr = watchpoint_sp->GetLoadAddress();
114 size_t SBWatchpoint::GetWatchSize() {
115 size_t watch_size = 0;
117 lldb::WatchpointSP watchpoint_sp(GetSP());
119 std::lock_guard<std::recursive_mutex> guard(
120 watchpoint_sp->GetTarget().GetAPIMutex());
121 watch_size = watchpoint_sp->GetByteSize();
127 void SBWatchpoint::SetEnabled(bool enabled) {
128 lldb::WatchpointSP watchpoint_sp(GetSP());
130 Target &target = watchpoint_sp->GetTarget();
131 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
132 ProcessSP process_sp = target.GetProcessSP();
133 const bool notify = true;
136 process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
138 process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
140 watchpoint_sp->SetEnabled(enabled, notify);
145 bool SBWatchpoint::IsEnabled() {
146 lldb::WatchpointSP watchpoint_sp(GetSP());
148 std::lock_guard<std::recursive_mutex> guard(
149 watchpoint_sp->GetTarget().GetAPIMutex());
150 return watchpoint_sp->IsEnabled();
155 uint32_t SBWatchpoint::GetHitCount() {
157 lldb::WatchpointSP watchpoint_sp(GetSP());
159 std::lock_guard<std::recursive_mutex> guard(
160 watchpoint_sp->GetTarget().GetAPIMutex());
161 count = watchpoint_sp->GetHitCount();
164 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
166 log->Printf("SBWatchpoint(%p)::GetHitCount () => %u",
167 static_cast<void *>(watchpoint_sp.get()), count);
172 uint32_t SBWatchpoint::GetIgnoreCount() {
173 lldb::WatchpointSP watchpoint_sp(GetSP());
175 std::lock_guard<std::recursive_mutex> guard(
176 watchpoint_sp->GetTarget().GetAPIMutex());
177 return watchpoint_sp->GetIgnoreCount();
182 void SBWatchpoint::SetIgnoreCount(uint32_t n) {
183 lldb::WatchpointSP watchpoint_sp(GetSP());
185 std::lock_guard<std::recursive_mutex> guard(
186 watchpoint_sp->GetTarget().GetAPIMutex());
187 watchpoint_sp->SetIgnoreCount(n);
191 const char *SBWatchpoint::GetCondition() {
192 lldb::WatchpointSP watchpoint_sp(GetSP());
194 std::lock_guard<std::recursive_mutex> guard(
195 watchpoint_sp->GetTarget().GetAPIMutex());
196 return watchpoint_sp->GetConditionText();
201 void SBWatchpoint::SetCondition(const char *condition) {
202 lldb::WatchpointSP watchpoint_sp(GetSP());
204 std::lock_guard<std::recursive_mutex> guard(
205 watchpoint_sp->GetTarget().GetAPIMutex());
206 watchpoint_sp->SetCondition(condition);
210 bool SBWatchpoint::GetDescription(SBStream &description,
211 DescriptionLevel level) {
212 Stream &strm = description.ref();
214 lldb::WatchpointSP watchpoint_sp(GetSP());
216 std::lock_guard<std::recursive_mutex> guard(
217 watchpoint_sp->GetTarget().GetAPIMutex());
218 watchpoint_sp->GetDescription(&strm, level);
221 strm.PutCString("No value");
226 void SBWatchpoint::Clear() { m_opaque_sp.reset(); }
228 lldb::WatchpointSP SBWatchpoint::GetSP() const { return m_opaque_sp; }
230 void SBWatchpoint::SetSP(const lldb::WatchpointSP &sp) { m_opaque_sp = sp; }
232 bool SBWatchpoint::EventIsWatchpointEvent(const lldb::SBEvent &event) {
233 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) !=
238 SBWatchpoint::GetWatchpointEventTypeFromEvent(const SBEvent &event) {
240 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent(
242 return eWatchpointEventTypeInvalidType;
245 SBWatchpoint SBWatchpoint::GetWatchpointFromEvent(const lldb::SBEvent &event) {
246 SBWatchpoint sb_watchpoint;
248 sb_watchpoint.m_opaque_sp =
249 Watchpoint::WatchpointEventData::GetWatchpointFromEvent(event.GetSP());
250 return sb_watchpoint;