blob: 4794ba4c50113b27c1c76f93b6a6531bdd4e7fbf [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{
Jim Ingham9880efa2012-08-11 00:35:26 +000090 return (bool) m_opaque_sp;
Johnny Chen096c2932011-09-26 22:40:50 +000091}
92
Jim Inghama442da22012-06-06 18:46:25 +000093SBError
94SBWatchpoint::GetError ()
95{
96 SBError sb_error;
97 lldb::WatchpointSP watchpoint_sp(GetSP());
98 if (watchpoint_sp)
99 {
100 sb_error.SetError(watchpoint_sp->GetError());
101 }
102 return sb_error;
103}
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
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000110 lldb::WatchpointSP watchpoint_sp(GetSP());
111 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000112 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000113 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
114 hw_index = watchpoint_sp->GetHardwareIndex();
Johnny Chen092bd152011-09-27 01:19:20 +0000115 }
116
117 return hw_index;
118}
119
Johnny Chen096c2932011-09-26 22:40:50 +0000120addr_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000121SBWatchpoint::GetWatchAddress ()
Johnny Chen096c2932011-09-26 22:40:50 +0000122{
123 addr_t ret_addr = LLDB_INVALID_ADDRESS;
124
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000125 lldb::WatchpointSP watchpoint_sp(GetSP());
126 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000127 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000128 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
129 ret_addr = watchpoint_sp->GetLoadAddress();
Johnny Chen096c2932011-09-26 22:40:50 +0000130 }
131
132 return ret_addr;
133}
134
135size_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000136SBWatchpoint::GetWatchSize ()
Johnny Chen096c2932011-09-26 22:40:50 +0000137{
138 size_t watch_size = 0;
139
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000140 lldb::WatchpointSP watchpoint_sp(GetSP());
141 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000142 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000143 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
144 watch_size = watchpoint_sp->GetByteSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000145 }
146
147 return watch_size;
148}
149
150void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000151SBWatchpoint::SetEnabled (bool enabled)
Johnny Chen096c2932011-09-26 22:40:50 +0000152{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000153 lldb::WatchpointSP watchpoint_sp(GetSP());
154 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000155 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000156 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
157 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000158 }
159}
160
161bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000162SBWatchpoint::IsEnabled ()
Johnny Chen096c2932011-09-26 22:40:50 +0000163{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000164 lldb::WatchpointSP watchpoint_sp(GetSP());
165 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000166 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000167 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
168 return watchpoint_sp->IsEnabled();
Johnny Chen096c2932011-09-26 22:40:50 +0000169 }
170 else
171 return false;
172}
173
174uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000175SBWatchpoint::GetHitCount ()
Johnny Chen092bd152011-09-27 01:19:20 +0000176{
177 uint32_t count = 0;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000178 lldb::WatchpointSP watchpoint_sp(GetSP());
179 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000180 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000181 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
182 count = watchpoint_sp->GetHitCount();
Johnny Chen092bd152011-09-27 01:19:20 +0000183 }
184
185 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
186 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000187 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count);
Johnny Chen092bd152011-09-27 01:19:20 +0000188
189 return count;
190}
191
192uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000193SBWatchpoint::GetIgnoreCount ()
Johnny Chen096c2932011-09-26 22:40:50 +0000194{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000195 lldb::WatchpointSP watchpoint_sp(GetSP());
196 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000197 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000198 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
199 return watchpoint_sp->GetIgnoreCount();
Johnny Chen096c2932011-09-26 22:40:50 +0000200 }
201 else
202 return 0;
203}
204
205void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000206SBWatchpoint::SetIgnoreCount (uint32_t n)
Johnny Chen096c2932011-09-26 22:40:50 +0000207{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000208 lldb::WatchpointSP watchpoint_sp(GetSP());
209 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000210 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000211 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
212 watchpoint_sp->SetIgnoreCount (n);
Johnny Chen096c2932011-09-26 22:40:50 +0000213 }
214}
215
Johnny Chen712a6282011-10-17 18:58:00 +0000216const char *
217SBWatchpoint::GetCondition ()
218{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000219 lldb::WatchpointSP watchpoint_sp(GetSP());
220 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000221 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000222 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
223 return watchpoint_sp->GetConditionText ();
Johnny Chen712a6282011-10-17 18:58:00 +0000224 }
225 return NULL;
226}
227
228void
229SBWatchpoint::SetCondition (const char *condition)
230{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000231 lldb::WatchpointSP watchpoint_sp(GetSP());
232 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000233 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000234 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
235 watchpoint_sp->SetCondition (condition);
Johnny Chen712a6282011-10-17 18:58:00 +0000236 }
237}
238
Johnny Chen096c2932011-09-26 22:40:50 +0000239bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000240SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen096c2932011-09-26 22:40:50 +0000241{
Greg Clayton96154be2011-11-13 06:57:31 +0000242 Stream &strm = description.ref();
243
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000244 lldb::WatchpointSP watchpoint_sp(GetSP());
245 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000246 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000247 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
248 watchpoint_sp->GetDescription (&strm, level);
Greg Clayton96154be2011-11-13 06:57:31 +0000249 strm.EOL();
Johnny Chen096c2932011-09-26 22:40:50 +0000250 }
251 else
Greg Clayton96154be2011-11-13 06:57:31 +0000252 strm.PutCString ("No value");
Johnny Chen096c2932011-09-26 22:40:50 +0000253
254 return true;
255}
256
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000257void
258SBWatchpoint::Clear ()
Johnny Chen096c2932011-09-26 22:40:50 +0000259{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000260 m_opaque_sp.reset();
Johnny Chen096c2932011-09-26 22:40:50 +0000261}
262
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000263lldb::WatchpointSP
264SBWatchpoint::GetSP () const
Johnny Chen096c2932011-09-26 22:40:50 +0000265{
266 return m_opaque_sp;
267}
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000268
269void
270SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
271{
272 m_opaque_sp = sp;
273}