blob: ec2dc128f1509bbfb953b04dec0e57b0d047b9a6 [file] [log] [blame]
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001//===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===//
Johnny Chen096c2932011-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 Clayton1fa6b3d2011-10-13 18:08:26 +000010#include "lldb/API/SBWatchpoint.h"
Johnny Chen096c2932011-09-26 22:40:50 +000011#include "lldb/API/SBDefines.h"
12#include "lldb/API/SBAddress.h"
13#include "lldb/API/SBDebugger.h"
14#include "lldb/API/SBStream.h"
15
16#include "lldb/lldb-types.h"
17#include "lldb/lldb-defines.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000018#include "lldb/Breakpoint/Watchpoint.h"
19#include "lldb/Breakpoint/WatchpointList.h"
Johnny Chen096c2932011-09-26 22:40:50 +000020#include "lldb/Core/Log.h"
21#include "lldb/Core/Stream.h"
22#include "lldb/Core/StreamFile.h"
23#include "lldb/Target/Target.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
28
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000029SBWatchpoint::SBWatchpoint () :
Johnny Chen096c2932011-09-26 22:40:50 +000030 m_opaque_sp ()
31{
32}
33
Johnny Chenecd4feb2011-10-14 00:42:25 +000034SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp) :
35 m_opaque_sp (wp_sp)
Johnny Chen096c2932011-09-26 22:40:50 +000036{
37 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
38
39 if (log)
40 {
41 SBStream sstr;
42 GetDescription (sstr, lldb::eDescriptionLevelBrief);
Johnny Chenecd4feb2011-10-14 00:42:25 +000043 log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp"
44 "=%p) => this.sp = %p (%s)", wp_sp.get(), m_opaque_sp.get(), sstr.GetData());
Johnny Chen096c2932011-09-26 22:40:50 +000045 }
46}
47
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000048SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) :
Johnny Chen096c2932011-09-26 22:40:50 +000049 m_opaque_sp (rhs.m_opaque_sp)
50{
51}
52
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000053const SBWatchpoint &
54SBWatchpoint::operator = (const SBWatchpoint &rhs)
Johnny Chen096c2932011-09-26 22:40:50 +000055{
56 if (this != &rhs)
57 m_opaque_sp = rhs.m_opaque_sp;
58 return *this;
59}
60
61
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000062SBWatchpoint::~SBWatchpoint ()
Johnny Chen096c2932011-09-26 22:40:50 +000063{
64}
65
Johnny Chen092bd152011-09-27 01:19:20 +000066watch_id_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000067SBWatchpoint::GetID ()
Johnny Chen092bd152011-09-27 01:19:20 +000068{
69 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
70
71 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
72 if (m_opaque_sp)
73 watch_id = m_opaque_sp->GetID();
74
75 if (log)
76 {
77 if (watch_id == LLDB_INVALID_WATCH_ID)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000078 log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", m_opaque_sp.get());
Johnny Chen092bd152011-09-27 01:19:20 +000079 else
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000080 log->Printf ("SBWatchpoint(%p)::GetID () => %u", m_opaque_sp.get(), watch_id);
Johnny Chen092bd152011-09-27 01:19:20 +000081 }
82
83 return watch_id;
84}
85
Johnny Chen096c2932011-09-26 22:40:50 +000086bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000087SBWatchpoint::IsValid() const
Johnny Chen096c2932011-09-26 22:40:50 +000088{
Johnny Chen41a55ef2011-10-14 19:15:48 +000089 if (m_opaque_sp && m_opaque_sp->GetError().Success())
90 return true;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000091 return false;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000092}
93
94SBError
95SBWatchpoint::GetError ()
96{
97 SBError sb_error;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000098 if (m_opaque_sp)
99 {
Johnny Chen41a55ef2011-10-14 19:15:48 +0000100 sb_error.SetError(m_opaque_sp->GetError());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000101 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000102 return sb_error;
Johnny Chen096c2932011-09-26 22:40:50 +0000103}
104
Johnny Chen092bd152011-09-27 01:19:20 +0000105int32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000106SBWatchpoint::GetHardwareIndex ()
Johnny Chen092bd152011-09-27 01:19:20 +0000107{
108 int32_t hw_index = -1;
109
110 if (m_opaque_sp)
111 {
112 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
113 hw_index = m_opaque_sp->GetHardwareIndex();
114 }
115
116 return hw_index;
117}
118
Johnny Chen096c2932011-09-26 22:40:50 +0000119addr_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000120SBWatchpoint::GetWatchAddress ()
Johnny Chen096c2932011-09-26 22:40:50 +0000121{
122 addr_t ret_addr = LLDB_INVALID_ADDRESS;
123
124 if (m_opaque_sp)
125 {
126 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
127 ret_addr = m_opaque_sp->GetLoadAddress();
128 }
129
130 return ret_addr;
131}
132
133size_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000134SBWatchpoint::GetWatchSize ()
Johnny Chen096c2932011-09-26 22:40:50 +0000135{
136 size_t watch_size = 0;
137
138 if (m_opaque_sp)
139 {
140 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
141 watch_size = m_opaque_sp->GetByteSize();
142 }
143
144 return watch_size;
145}
146
147void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000148SBWatchpoint::SetEnabled (bool enabled)
Johnny Chen096c2932011-09-26 22:40:50 +0000149{
150 if (m_opaque_sp)
151 {
152 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000153 m_opaque_sp->GetTarget().DisableWatchpointByID(m_opaque_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000154 }
155}
156
157bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000158SBWatchpoint::IsEnabled ()
Johnny Chen096c2932011-09-26 22:40:50 +0000159{
160 if (m_opaque_sp)
161 {
162 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
163 return m_opaque_sp->IsEnabled();
164 }
165 else
166 return false;
167}
168
169uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000170SBWatchpoint::GetHitCount ()
Johnny Chen092bd152011-09-27 01:19:20 +0000171{
172 uint32_t count = 0;
173 if (m_opaque_sp)
174 {
175 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
176 count = m_opaque_sp->GetHitCount();
177 }
178
179 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
180 if (log)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000181 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
Johnny Chen092bd152011-09-27 01:19:20 +0000182
183 return count;
184}
185
186uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000187SBWatchpoint::GetIgnoreCount ()
Johnny Chen096c2932011-09-26 22:40:50 +0000188{
189 if (m_opaque_sp)
190 {
191 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
192 return m_opaque_sp->GetIgnoreCount();
193 }
194 else
195 return 0;
196}
197
198void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000199SBWatchpoint::SetIgnoreCount (uint32_t n)
Johnny Chen096c2932011-09-26 22:40:50 +0000200{
201 if (m_opaque_sp)
202 {
203 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
204 m_opaque_sp->SetIgnoreCount (n);
205 }
206}
207
Johnny Chen712a6282011-10-17 18:58:00 +0000208const char *
209SBWatchpoint::GetCondition ()
210{
211 if (m_opaque_sp)
212 {
213 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
214 return m_opaque_sp->GetConditionText ();
215 }
216 return NULL;
217}
218
219void
220SBWatchpoint::SetCondition (const char *condition)
221{
222 if (m_opaque_sp)
223 {
224 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
225 m_opaque_sp->SetCondition (condition);
226 }
227}
228
Johnny Chen096c2932011-09-26 22:40:50 +0000229bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000230SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen096c2932011-09-26 22:40:50 +0000231{
232 if (m_opaque_sp)
233 {
234 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
235 description.ref();
236 m_opaque_sp->GetDescription (description.get(), level);
237 description.get()->EOL();
238 }
239 else
240 description.Printf ("No value");
241
242 return true;
243}
244
Johnny Chenecd4feb2011-10-14 00:42:25 +0000245lldb_private::Watchpoint *
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000246SBWatchpoint::operator->()
Johnny Chen096c2932011-09-26 22:40:50 +0000247{
248 return m_opaque_sp.get();
249}
250
Johnny Chenecd4feb2011-10-14 00:42:25 +0000251lldb_private::Watchpoint *
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000252SBWatchpoint::get()
Johnny Chen096c2932011-09-26 22:40:50 +0000253{
254 return m_opaque_sp.get();
255}
256
Johnny Chenecd4feb2011-10-14 00:42:25 +0000257lldb::WatchpointSP &
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000258SBWatchpoint::operator *()
Johnny Chen096c2932011-09-26 22:40:50 +0000259{
260 return m_opaque_sp;
261}