blob: 194695c31d5b30061463381cb095951efbe9a578 [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"
Jim Ingham9c970a32012-12-18 02:03:49 +000014#include "lldb/API/SBEvent.h"
Johnny Chen096c2932011-09-26 22:40:50 +000015#include "lldb/API/SBStream.h"
16
17#include "lldb/lldb-types.h"
18#include "lldb/lldb-defines.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000019#include "lldb/Breakpoint/Watchpoint.h"
20#include "lldb/Breakpoint/WatchpointList.h"
Johnny Chen096c2932011-09-26 22:40:50 +000021#include "lldb/Core/Log.h"
22#include "lldb/Core/Stream.h"
23#include "lldb/Core/StreamFile.h"
24#include "lldb/Target/Target.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
29
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000030SBWatchpoint::SBWatchpoint () :
Johnny Chen096c2932011-09-26 22:40:50 +000031 m_opaque_sp ()
32{
33}
34
Johnny Chenecd4feb2011-10-14 00:42:25 +000035SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp) :
36 m_opaque_sp (wp_sp)
Johnny Chen096c2932011-09-26 22:40:50 +000037{
Greg Clayton952e9dc2013-03-27 23:08:40 +000038 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen096c2932011-09-26 22:40:50 +000039
40 if (log)
41 {
42 SBStream sstr;
43 GetDescription (sstr, lldb::eDescriptionLevelBrief);
Johnny Chenecd4feb2011-10-14 00:42:25 +000044 log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp"
45 "=%p) => this.sp = %p (%s)", wp_sp.get(), m_opaque_sp.get(), sstr.GetData());
Johnny Chen096c2932011-09-26 22:40:50 +000046 }
47}
48
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000049SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) :
Johnny Chen096c2932011-09-26 22:40:50 +000050 m_opaque_sp (rhs.m_opaque_sp)
51{
52}
53
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000054const SBWatchpoint &
55SBWatchpoint::operator = (const SBWatchpoint &rhs)
Johnny Chen096c2932011-09-26 22:40:50 +000056{
57 if (this != &rhs)
58 m_opaque_sp = rhs.m_opaque_sp;
59 return *this;
60}
61
62
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000063SBWatchpoint::~SBWatchpoint ()
Johnny Chen096c2932011-09-26 22:40:50 +000064{
65}
66
Johnny Chen092bd152011-09-27 01:19:20 +000067watch_id_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000068SBWatchpoint::GetID ()
Johnny Chen092bd152011-09-27 01:19:20 +000069{
Greg Clayton952e9dc2013-03-27 23:08:40 +000070 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen092bd152011-09-27 01:19:20 +000071
72 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
Greg Clayton0a19a1b2012-02-04 02:27:34 +000073 lldb::WatchpointSP watchpoint_sp(GetSP());
74 if (watchpoint_sp)
75 watch_id = watchpoint_sp->GetID();
Johnny Chen092bd152011-09-27 01:19:20 +000076
77 if (log)
78 {
79 if (watch_id == LLDB_INVALID_WATCH_ID)
Greg Clayton0a19a1b2012-02-04 02:27:34 +000080 log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", watchpoint_sp.get());
Johnny Chen092bd152011-09-27 01:19:20 +000081 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +000082 log->Printf ("SBWatchpoint(%p)::GetID () => %u", watchpoint_sp.get(), watch_id);
Johnny Chen092bd152011-09-27 01:19:20 +000083 }
84
85 return watch_id;
86}
87
Johnny Chen096c2932011-09-26 22:40:50 +000088bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000089SBWatchpoint::IsValid() const
Johnny Chen096c2932011-09-26 22:40:50 +000090{
Jim Ingham9880efa2012-08-11 00:35:26 +000091 return (bool) m_opaque_sp;
Johnny Chen096c2932011-09-26 22:40:50 +000092}
93
Jim Inghama442da22012-06-06 18:46:25 +000094SBError
95SBWatchpoint::GetError ()
96{
97 SBError sb_error;
98 lldb::WatchpointSP watchpoint_sp(GetSP());
99 if (watchpoint_sp)
100 {
101 sb_error.SetError(watchpoint_sp->GetError());
102 }
103 return sb_error;
104}
105
Johnny Chen092bd152011-09-27 01:19:20 +0000106int32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000107SBWatchpoint::GetHardwareIndex ()
Johnny Chen092bd152011-09-27 01:19:20 +0000108{
109 int32_t hw_index = -1;
110
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000111 lldb::WatchpointSP watchpoint_sp(GetSP());
112 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000113 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000114 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
115 hw_index = watchpoint_sp->GetHardwareIndex();
Johnny Chen092bd152011-09-27 01:19:20 +0000116 }
117
118 return hw_index;
119}
120
Johnny Chen096c2932011-09-26 22:40:50 +0000121addr_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000122SBWatchpoint::GetWatchAddress ()
Johnny Chen096c2932011-09-26 22:40:50 +0000123{
124 addr_t ret_addr = LLDB_INVALID_ADDRESS;
125
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000126 lldb::WatchpointSP watchpoint_sp(GetSP());
127 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000128 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000129 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
130 ret_addr = watchpoint_sp->GetLoadAddress();
Johnny Chen096c2932011-09-26 22:40:50 +0000131 }
132
133 return ret_addr;
134}
135
136size_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000137SBWatchpoint::GetWatchSize ()
Johnny Chen096c2932011-09-26 22:40:50 +0000138{
139 size_t watch_size = 0;
140
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000141 lldb::WatchpointSP watchpoint_sp(GetSP());
142 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000143 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000144 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
145 watch_size = watchpoint_sp->GetByteSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000146 }
147
148 return watch_size;
149}
150
151void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000152SBWatchpoint::SetEnabled (bool enabled)
Johnny Chen096c2932011-09-26 22:40:50 +0000153{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000154 lldb::WatchpointSP watchpoint_sp(GetSP());
155 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000156 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000157 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
158 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000159 }
160}
161
162bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000163SBWatchpoint::IsEnabled ()
Johnny Chen096c2932011-09-26 22:40:50 +0000164{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000165 lldb::WatchpointSP watchpoint_sp(GetSP());
166 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000167 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000168 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
169 return watchpoint_sp->IsEnabled();
Johnny Chen096c2932011-09-26 22:40:50 +0000170 }
171 else
172 return false;
173}
174
175uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000176SBWatchpoint::GetHitCount ()
Johnny Chen092bd152011-09-27 01:19:20 +0000177{
178 uint32_t count = 0;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000179 lldb::WatchpointSP watchpoint_sp(GetSP());
180 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000181 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000182 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
183 count = watchpoint_sp->GetHitCount();
Johnny Chen092bd152011-09-27 01:19:20 +0000184 }
185
Greg Clayton952e9dc2013-03-27 23:08:40 +0000186 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen092bd152011-09-27 01:19:20 +0000187 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000188 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count);
Johnny Chen092bd152011-09-27 01:19:20 +0000189
190 return count;
191}
192
193uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000194SBWatchpoint::GetIgnoreCount ()
Johnny Chen096c2932011-09-26 22:40:50 +0000195{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000196 lldb::WatchpointSP watchpoint_sp(GetSP());
197 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000198 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000199 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
200 return watchpoint_sp->GetIgnoreCount();
Johnny Chen096c2932011-09-26 22:40:50 +0000201 }
202 else
203 return 0;
204}
205
206void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000207SBWatchpoint::SetIgnoreCount (uint32_t n)
Johnny Chen096c2932011-09-26 22:40:50 +0000208{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000209 lldb::WatchpointSP watchpoint_sp(GetSP());
210 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000211 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000212 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
213 watchpoint_sp->SetIgnoreCount (n);
Johnny Chen096c2932011-09-26 22:40:50 +0000214 }
215}
216
Johnny Chen712a6282011-10-17 18:58:00 +0000217const char *
218SBWatchpoint::GetCondition ()
219{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000220 lldb::WatchpointSP watchpoint_sp(GetSP());
221 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000222 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000223 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
224 return watchpoint_sp->GetConditionText ();
Johnny Chen712a6282011-10-17 18:58:00 +0000225 }
226 return NULL;
227}
228
229void
230SBWatchpoint::SetCondition (const char *condition)
231{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000232 lldb::WatchpointSP watchpoint_sp(GetSP());
233 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000234 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000235 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
236 watchpoint_sp->SetCondition (condition);
Johnny Chen712a6282011-10-17 18:58:00 +0000237 }
238}
239
Johnny Chen096c2932011-09-26 22:40:50 +0000240bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000241SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen096c2932011-09-26 22:40:50 +0000242{
Greg Clayton96154be2011-11-13 06:57:31 +0000243 Stream &strm = description.ref();
244
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000245 lldb::WatchpointSP watchpoint_sp(GetSP());
246 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000247 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000248 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
249 watchpoint_sp->GetDescription (&strm, level);
Greg Clayton96154be2011-11-13 06:57:31 +0000250 strm.EOL();
Johnny Chen096c2932011-09-26 22:40:50 +0000251 }
252 else
Greg Clayton96154be2011-11-13 06:57:31 +0000253 strm.PutCString ("No value");
Johnny Chen096c2932011-09-26 22:40:50 +0000254
255 return true;
256}
257
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000258void
259SBWatchpoint::Clear ()
Johnny Chen096c2932011-09-26 22:40:50 +0000260{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000261 m_opaque_sp.reset();
Johnny Chen096c2932011-09-26 22:40:50 +0000262}
263
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000264lldb::WatchpointSP
265SBWatchpoint::GetSP () const
Johnny Chen096c2932011-09-26 22:40:50 +0000266{
267 return m_opaque_sp;
268}
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000269
270void
271SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
272{
273 m_opaque_sp = sp;
274}
Jim Ingham9c970a32012-12-18 02:03:49 +0000275
276bool
277SBWatchpoint::EventIsWatchpointEvent (const lldb::SBEvent &event)
278{
279 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) != NULL;
280
281}
282
283WatchpointEventType
284SBWatchpoint::GetWatchpointEventTypeFromEvent (const SBEvent& event)
285{
286 if (event.IsValid())
287 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (event.GetSP());
288 return eWatchpointEventTypeInvalidType;
289}
290
291SBWatchpoint
292SBWatchpoint::GetWatchpointFromEvent (const lldb::SBEvent& event)
293{
294 SBWatchpoint sb_watchpoint;
295 if (event.IsValid())
296 sb_watchpoint.m_opaque_sp = Watchpoint::WatchpointEventData::GetWatchpointFromEvent (event.GetSP());
297 return sb_watchpoint;
298}