blob: fd505aead54905e9b9c60fee15418198401b3286 [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;
Greg Clayton0a19a1b2012-02-04 02:27:34 +000072 lldb::WatchpointSP watchpoint_sp(GetSP());
73 if (watchpoint_sp)
74 watch_id = watchpoint_sp->GetID();
Johnny Chen092bd152011-09-27 01:19:20 +000075
76 if (log)
77 {
78 if (watch_id == LLDB_INVALID_WATCH_ID)
Greg Clayton0a19a1b2012-02-04 02:27:34 +000079 log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", watchpoint_sp.get());
Johnny Chen092bd152011-09-27 01:19:20 +000080 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +000081 log->Printf ("SBWatchpoint(%p)::GetID () => %u", watchpoint_sp.get(), watch_id);
Johnny Chen092bd152011-09-27 01:19:20 +000082 }
83
84 return watch_id;
85}
86
Johnny Chen096c2932011-09-26 22:40:50 +000087bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000088SBWatchpoint::IsValid() const
Johnny Chen096c2932011-09-26 22:40:50 +000089{
Greg Clayton0a19a1b2012-02-04 02:27:34 +000090 lldb::WatchpointSP watchpoint_sp(GetSP());
91 if (watchpoint_sp && watchpoint_sp->GetError().Success())
Johnny Chen41a55ef2011-10-14 19:15:48 +000092 return true;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000093 return false;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000094}
95
96SBError
97SBWatchpoint::GetError ()
98{
99 SBError sb_error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000100 lldb::WatchpointSP watchpoint_sp(GetSP());
101 if (watchpoint_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000102 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000103 sb_error.SetError(watchpoint_sp->GetError());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000104 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000105 return sb_error;
Johnny Chen096c2932011-09-26 22:40:50 +0000106}
107
Johnny Chen092bd152011-09-27 01:19:20 +0000108int32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000109SBWatchpoint::GetHardwareIndex ()
Johnny Chen092bd152011-09-27 01:19:20 +0000110{
111 int32_t hw_index = -1;
112
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000113 lldb::WatchpointSP watchpoint_sp(GetSP());
114 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000115 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000116 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
117 hw_index = watchpoint_sp->GetHardwareIndex();
Johnny Chen092bd152011-09-27 01:19:20 +0000118 }
119
120 return hw_index;
121}
122
Johnny Chen096c2932011-09-26 22:40:50 +0000123addr_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000124SBWatchpoint::GetWatchAddress ()
Johnny Chen096c2932011-09-26 22:40:50 +0000125{
126 addr_t ret_addr = LLDB_INVALID_ADDRESS;
127
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000128 lldb::WatchpointSP watchpoint_sp(GetSP());
129 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000130 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000131 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
132 ret_addr = watchpoint_sp->GetLoadAddress();
Johnny Chen096c2932011-09-26 22:40:50 +0000133 }
134
135 return ret_addr;
136}
137
138size_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000139SBWatchpoint::GetWatchSize ()
Johnny Chen096c2932011-09-26 22:40:50 +0000140{
141 size_t watch_size = 0;
142
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000143 lldb::WatchpointSP watchpoint_sp(GetSP());
144 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000145 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000146 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
147 watch_size = watchpoint_sp->GetByteSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000148 }
149
150 return watch_size;
151}
152
153void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000154SBWatchpoint::SetEnabled (bool enabled)
Johnny Chen096c2932011-09-26 22:40:50 +0000155{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000156 lldb::WatchpointSP watchpoint_sp(GetSP());
157 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000158 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000159 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
160 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000161 }
162}
163
164bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000165SBWatchpoint::IsEnabled ()
Johnny Chen096c2932011-09-26 22:40:50 +0000166{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000167 lldb::WatchpointSP watchpoint_sp(GetSP());
168 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000169 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000170 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
171 return watchpoint_sp->IsEnabled();
Johnny Chen096c2932011-09-26 22:40:50 +0000172 }
173 else
174 return false;
175}
176
177uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000178SBWatchpoint::GetHitCount ()
Johnny Chen092bd152011-09-27 01:19:20 +0000179{
180 uint32_t count = 0;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000181 lldb::WatchpointSP watchpoint_sp(GetSP());
182 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000183 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000184 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
185 count = watchpoint_sp->GetHitCount();
Johnny Chen092bd152011-09-27 01:19:20 +0000186 }
187
188 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
189 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000190 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count);
Johnny Chen092bd152011-09-27 01:19:20 +0000191
192 return count;
193}
194
195uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000196SBWatchpoint::GetIgnoreCount ()
Johnny Chen096c2932011-09-26 22:40:50 +0000197{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000198 lldb::WatchpointSP watchpoint_sp(GetSP());
199 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000200 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000201 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
202 return watchpoint_sp->GetIgnoreCount();
Johnny Chen096c2932011-09-26 22:40:50 +0000203 }
204 else
205 return 0;
206}
207
208void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000209SBWatchpoint::SetIgnoreCount (uint32_t n)
Johnny Chen096c2932011-09-26 22:40:50 +0000210{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000211 lldb::WatchpointSP watchpoint_sp(GetSP());
212 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000213 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000214 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
215 watchpoint_sp->SetIgnoreCount (n);
Johnny Chen096c2932011-09-26 22:40:50 +0000216 }
217}
218
Johnny Chen712a6282011-10-17 18:58:00 +0000219const char *
220SBWatchpoint::GetCondition ()
221{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000222 lldb::WatchpointSP watchpoint_sp(GetSP());
223 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000224 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000225 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
226 return watchpoint_sp->GetConditionText ();
Johnny Chen712a6282011-10-17 18:58:00 +0000227 }
228 return NULL;
229}
230
231void
232SBWatchpoint::SetCondition (const char *condition)
233{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000234 lldb::WatchpointSP watchpoint_sp(GetSP());
235 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000236 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000237 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
238 watchpoint_sp->SetCondition (condition);
Johnny Chen712a6282011-10-17 18:58:00 +0000239 }
240}
241
Johnny Chen096c2932011-09-26 22:40:50 +0000242bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000243SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen096c2932011-09-26 22:40:50 +0000244{
Greg Clayton96154be2011-11-13 06:57:31 +0000245 Stream &strm = description.ref();
246
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000247 lldb::WatchpointSP watchpoint_sp(GetSP());
248 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000249 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000250 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
251 watchpoint_sp->GetDescription (&strm, level);
Greg Clayton96154be2011-11-13 06:57:31 +0000252 strm.EOL();
Johnny Chen096c2932011-09-26 22:40:50 +0000253 }
254 else
Greg Clayton96154be2011-11-13 06:57:31 +0000255 strm.PutCString ("No value");
Johnny Chen096c2932011-09-26 22:40:50 +0000256
257 return true;
258}
259
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000260void
261SBWatchpoint::Clear ()
Johnny Chen096c2932011-09-26 22:40:50 +0000262{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000263 m_opaque_sp.reset();
Johnny Chen096c2932011-09-26 22:40:50 +0000264}
265
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000266lldb::WatchpointSP
267SBWatchpoint::GetSP () const
Johnny Chen096c2932011-09-26 22:40:50 +0000268{
269 return m_opaque_sp;
270}
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000271
272void
273SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
274{
275 m_opaque_sp = sp;
276}