blob: 76ce57cccf75390987e0893e68bcfc3b0157aa2c [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{
Johnny Chen3f883492012-06-04 23:19:54 +000090 return m_opaque_sp;
Johnny Chen096c2932011-09-26 22:40:50 +000091}
92
Johnny Chen092bd152011-09-27 01:19:20 +000093int32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000094SBWatchpoint::GetHardwareIndex ()
Johnny Chen092bd152011-09-27 01:19:20 +000095{
96 int32_t hw_index = -1;
97
Greg Clayton0a19a1b2012-02-04 02:27:34 +000098 lldb::WatchpointSP watchpoint_sp(GetSP());
99 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000100 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000101 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
102 hw_index = watchpoint_sp->GetHardwareIndex();
Johnny Chen092bd152011-09-27 01:19:20 +0000103 }
104
105 return hw_index;
106}
107
Johnny Chen096c2932011-09-26 22:40:50 +0000108addr_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000109SBWatchpoint::GetWatchAddress ()
Johnny Chen096c2932011-09-26 22:40:50 +0000110{
111 addr_t ret_addr = LLDB_INVALID_ADDRESS;
112
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000113 lldb::WatchpointSP watchpoint_sp(GetSP());
114 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000115 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000116 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
117 ret_addr = watchpoint_sp->GetLoadAddress();
Johnny Chen096c2932011-09-26 22:40:50 +0000118 }
119
120 return ret_addr;
121}
122
123size_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000124SBWatchpoint::GetWatchSize ()
Johnny Chen096c2932011-09-26 22:40:50 +0000125{
126 size_t watch_size = 0;
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 watch_size = watchpoint_sp->GetByteSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000133 }
134
135 return watch_size;
136}
137
138void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000139SBWatchpoint::SetEnabled (bool enabled)
Johnny Chen096c2932011-09-26 22:40:50 +0000140{
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 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000146 }
147}
148
149bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000150SBWatchpoint::IsEnabled ()
Johnny Chen096c2932011-09-26 22:40:50 +0000151{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000152 lldb::WatchpointSP watchpoint_sp(GetSP());
153 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000154 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000155 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
156 return watchpoint_sp->IsEnabled();
Johnny Chen096c2932011-09-26 22:40:50 +0000157 }
158 else
159 return false;
160}
161
162uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000163SBWatchpoint::GetHitCount ()
Johnny Chen092bd152011-09-27 01:19:20 +0000164{
165 uint32_t count = 0;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000166 lldb::WatchpointSP watchpoint_sp(GetSP());
167 if (watchpoint_sp)
Johnny Chen092bd152011-09-27 01:19:20 +0000168 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000169 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
170 count = watchpoint_sp->GetHitCount();
Johnny Chen092bd152011-09-27 01:19:20 +0000171 }
172
173 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
174 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000175 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count);
Johnny Chen092bd152011-09-27 01:19:20 +0000176
177 return count;
178}
179
180uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000181SBWatchpoint::GetIgnoreCount ()
Johnny Chen096c2932011-09-26 22:40:50 +0000182{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000183 lldb::WatchpointSP watchpoint_sp(GetSP());
184 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000185 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000186 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
187 return watchpoint_sp->GetIgnoreCount();
Johnny Chen096c2932011-09-26 22:40:50 +0000188 }
189 else
190 return 0;
191}
192
193void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000194SBWatchpoint::SetIgnoreCount (uint32_t n)
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 watchpoint_sp->SetIgnoreCount (n);
Johnny Chen096c2932011-09-26 22:40:50 +0000201 }
202}
203
Johnny Chen712a6282011-10-17 18:58:00 +0000204const char *
205SBWatchpoint::GetCondition ()
206{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000207 lldb::WatchpointSP watchpoint_sp(GetSP());
208 if (watchpoint_sp)
Johnny Chen712a6282011-10-17 18:58:00 +0000209 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000210 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
211 return watchpoint_sp->GetConditionText ();
Johnny Chen712a6282011-10-17 18:58:00 +0000212 }
213 return NULL;
214}
215
216void
217SBWatchpoint::SetCondition (const char *condition)
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 watchpoint_sp->SetCondition (condition);
Johnny Chen712a6282011-10-17 18:58:00 +0000224 }
225}
226
Johnny Chen096c2932011-09-26 22:40:50 +0000227bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000228SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen096c2932011-09-26 22:40:50 +0000229{
Greg Clayton96154be2011-11-13 06:57:31 +0000230 Stream &strm = description.ref();
231
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000232 lldb::WatchpointSP watchpoint_sp(GetSP());
233 if (watchpoint_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000234 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000235 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
236 watchpoint_sp->GetDescription (&strm, level);
Greg Clayton96154be2011-11-13 06:57:31 +0000237 strm.EOL();
Johnny Chen096c2932011-09-26 22:40:50 +0000238 }
239 else
Greg Clayton96154be2011-11-13 06:57:31 +0000240 strm.PutCString ("No value");
Johnny Chen096c2932011-09-26 22:40:50 +0000241
242 return true;
243}
244
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000245void
246SBWatchpoint::Clear ()
Johnny Chen096c2932011-09-26 22:40:50 +0000247{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000248 m_opaque_sp.reset();
Johnny Chen096c2932011-09-26 22:40:50 +0000249}
250
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000251lldb::WatchpointSP
252SBWatchpoint::GetSP () const
Johnny Chen096c2932011-09-26 22:40:50 +0000253{
254 return m_opaque_sp;
255}
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000256
257void
258SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
259{
260 m_opaque_sp = sp;
261}