blob: a921ea120f539004078c631f7a5b001e89067720 [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"
18#include "lldb/Breakpoint/WatchpointLocation.h"
19#include "lldb/Breakpoint/WatchpointLocationList.h"
20#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
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000034SBWatchpoint::SBWatchpoint (const lldb::WatchpointLocationSP &watch_loc_sp) :
Johnny Chen096c2932011-09-26 22:40:50 +000035 m_opaque_sp (watch_loc_sp)
36{
37 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
38
39 if (log)
40 {
41 SBStream sstr;
42 GetDescription (sstr, lldb::eDescriptionLevelBrief);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000043 log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointLocationsSP &watch_loc_sp"
Johnny Chen096c2932011-09-26 22:40:50 +000044 "=%p) => this.sp = %p (%s)", watch_loc_sp.get(), m_opaque_sp.get(), sstr.GetData());
45 }
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{
89 return m_opaque_sp.get() != NULL;
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000090#if 0
91 if (m_opaque_sp)
92 return m_opaque_sp->GetError().Success();
93 return false;
94#endif
95}
96
97SBError
98SBWatchpoint::GetError ()
99{
100 SBError sb_error;
101#if 0
102 if (m_opaque_sp)
103 {
104 // TODO: Johnny fill this in
105 sb_error.ref() = m_opaque_sp->GetError();
106 }
107#endif
108 return sb_error;
Johnny Chen096c2932011-09-26 22:40:50 +0000109}
110
Johnny Chen092bd152011-09-27 01:19:20 +0000111int32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000112SBWatchpoint::GetHardwareIndex ()
Johnny Chen092bd152011-09-27 01:19:20 +0000113{
114 int32_t hw_index = -1;
115
116 if (m_opaque_sp)
117 {
118 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
119 hw_index = m_opaque_sp->GetHardwareIndex();
120 }
121
122 return hw_index;
123}
124
Johnny Chen096c2932011-09-26 22:40:50 +0000125addr_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000126SBWatchpoint::GetWatchAddress ()
Johnny Chen096c2932011-09-26 22:40:50 +0000127{
128 addr_t ret_addr = LLDB_INVALID_ADDRESS;
129
130 if (m_opaque_sp)
131 {
132 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
133 ret_addr = m_opaque_sp->GetLoadAddress();
134 }
135
136 return ret_addr;
137}
138
139size_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000140SBWatchpoint::GetWatchSize ()
Johnny Chen096c2932011-09-26 22:40:50 +0000141{
142 size_t watch_size = 0;
143
144 if (m_opaque_sp)
145 {
146 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
147 watch_size = m_opaque_sp->GetByteSize();
148 }
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{
156 if (m_opaque_sp)
157 {
158 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Johnny Chen092bd152011-09-27 01:19:20 +0000159 m_opaque_sp->GetTarget().DisableWatchpointLocationByID(m_opaque_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000160 }
161}
162
163bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000164SBWatchpoint::IsEnabled ()
Johnny Chen096c2932011-09-26 22:40:50 +0000165{
166 if (m_opaque_sp)
167 {
168 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
169 return m_opaque_sp->IsEnabled();
170 }
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;
179 if (m_opaque_sp)
180 {
181 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
182 count = m_opaque_sp->GetHitCount();
183 }
184
185 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
186 if (log)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000187 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", m_opaque_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{
195 if (m_opaque_sp)
196 {
197 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
198 return m_opaque_sp->GetIgnoreCount();
199 }
200 else
201 return 0;
202}
203
204void
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000205SBWatchpoint::SetIgnoreCount (uint32_t n)
Johnny Chen096c2932011-09-26 22:40:50 +0000206{
207 if (m_opaque_sp)
208 {
209 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
210 m_opaque_sp->SetIgnoreCount (n);
211 }
212}
213
214bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000215SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen096c2932011-09-26 22:40:50 +0000216{
217 if (m_opaque_sp)
218 {
219 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
220 description.ref();
221 m_opaque_sp->GetDescription (description.get(), level);
222 description.get()->EOL();
223 }
224 else
225 description.Printf ("No value");
226
227 return true;
228}
229
230lldb_private::WatchpointLocation *
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000231SBWatchpoint::operator->()
Johnny Chen096c2932011-09-26 22:40:50 +0000232{
233 return m_opaque_sp.get();
234}
235
236lldb_private::WatchpointLocation *
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000237SBWatchpoint::get()
Johnny Chen096c2932011-09-26 22:40:50 +0000238{
239 return m_opaque_sp.get();
240}
241
242lldb::WatchpointLocationSP &
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000243SBWatchpoint::operator *()
Johnny Chen096c2932011-09-26 22:40:50 +0000244{
245 return m_opaque_sp;
246}