blob: 33b035ff11fc6134c2bd26d18181e0f94c5f6f89 [file] [log] [blame]
Johnny Chen096c2932011-09-26 22:40:50 +00001//===-- SBWatchpointLocation.cpp --------------------------------*- C++ -*-===//
2//
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
10#include "lldb/API/SBWatchpointLocation.h"
11#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
29SBWatchpointLocation::SBWatchpointLocation () :
30 m_opaque_sp ()
31{
32}
33
34SBWatchpointLocation::SBWatchpointLocation (const lldb::WatchpointLocationSP &watch_loc_sp) :
35 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);
43 log->Printf ("SBWatchpointLocation::SBWatchpointLocation (const lldb::WatchpointLocationsSP &watch_loc_sp"
44 "=%p) => this.sp = %p (%s)", watch_loc_sp.get(), m_opaque_sp.get(), sstr.GetData());
45 }
46}
47
48SBWatchpointLocation::SBWatchpointLocation(const SBWatchpointLocation &rhs) :
49 m_opaque_sp (rhs.m_opaque_sp)
50{
51}
52
53const SBWatchpointLocation &
54SBWatchpointLocation::operator = (const SBWatchpointLocation &rhs)
55{
56 if (this != &rhs)
57 m_opaque_sp = rhs.m_opaque_sp;
58 return *this;
59}
60
61
62SBWatchpointLocation::~SBWatchpointLocation ()
63{
64}
65
Johnny Chen092bd152011-09-27 01:19:20 +000066watch_id_t
67SBWatchpointLocation::GetID () const
68{
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)
78 log->Printf ("SBWatchpointLocation(%p)::GetID () => LLDB_INVALID_WATCH_ID", m_opaque_sp.get());
79 else
80 log->Printf ("SBWatchpointLocation(%p)::GetID () => %u", m_opaque_sp.get(), watch_id);
81 }
82
83 return watch_id;
84}
85
Johnny Chen096c2932011-09-26 22:40:50 +000086bool
87SBWatchpointLocation::IsValid() const
88{
89 return m_opaque_sp.get() != NULL;
90}
91
Johnny Chen092bd152011-09-27 01:19:20 +000092int32_t
93SBWatchpointLocation::GetHardwareIndex () const
94{
95 int32_t hw_index = -1;
96
97 if (m_opaque_sp)
98 {
99 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
100 hw_index = m_opaque_sp->GetHardwareIndex();
101 }
102
103 return hw_index;
104}
105
Johnny Chen096c2932011-09-26 22:40:50 +0000106addr_t
107SBWatchpointLocation::GetWatchAddress () const
108{
109 addr_t ret_addr = LLDB_INVALID_ADDRESS;
110
111 if (m_opaque_sp)
112 {
113 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
114 ret_addr = m_opaque_sp->GetLoadAddress();
115 }
116
117 return ret_addr;
118}
119
120size_t
121SBWatchpointLocation::GetWatchSize () const
122{
123 size_t watch_size = 0;
124
125 if (m_opaque_sp)
126 {
127 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
128 watch_size = m_opaque_sp->GetByteSize();
129 }
130
131 return watch_size;
132}
133
134void
135SBWatchpointLocation::SetEnabled (bool enabled)
136{
137 if (m_opaque_sp)
138 {
139 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Johnny Chen092bd152011-09-27 01:19:20 +0000140 m_opaque_sp->GetTarget().DisableWatchpointLocationByID(m_opaque_sp->GetID());
Johnny Chen096c2932011-09-26 22:40:50 +0000141 }
142}
143
144bool
145SBWatchpointLocation::IsEnabled ()
146{
147 if (m_opaque_sp)
148 {
149 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
150 return m_opaque_sp->IsEnabled();
151 }
152 else
153 return false;
154}
155
156uint32_t
Johnny Chen092bd152011-09-27 01:19:20 +0000157SBWatchpointLocation::GetHitCount () const
158{
159 uint32_t count = 0;
160 if (m_opaque_sp)
161 {
162 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
163 count = m_opaque_sp->GetHitCount();
164 }
165
166 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
167 if (log)
168 log->Printf ("SBWatchpointLocation(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
169
170 return count;
171}
172
173uint32_t
Johnny Chen096c2932011-09-26 22:40:50 +0000174SBWatchpointLocation::GetIgnoreCount ()
175{
176 if (m_opaque_sp)
177 {
178 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
179 return m_opaque_sp->GetIgnoreCount();
180 }
181 else
182 return 0;
183}
184
185void
186SBWatchpointLocation::SetIgnoreCount (uint32_t n)
187{
188 if (m_opaque_sp)
189 {
190 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
191 m_opaque_sp->SetIgnoreCount (n);
192 }
193}
194
195bool
196SBWatchpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
197{
198 if (m_opaque_sp)
199 {
200 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
201 description.ref();
202 m_opaque_sp->GetDescription (description.get(), level);
203 description.get()->EOL();
204 }
205 else
206 description.Printf ("No value");
207
208 return true;
209}
210
211lldb_private::WatchpointLocation *
212SBWatchpointLocation::operator->() const
213{
214 return m_opaque_sp.get();
215}
216
217lldb_private::WatchpointLocation *
218SBWatchpointLocation::get() const
219{
220 return m_opaque_sp.get();
221}
222
223lldb::WatchpointLocationSP &
224SBWatchpointLocation::operator *()
225{
226 return m_opaque_sp;
227}
228
229const lldb::WatchpointLocationSP &
230SBWatchpointLocation::operator *() const
231{
232 return m_opaque_sp;
233}
234