1 //===-- SBBreakpointLocation.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/SBBreakpointLocation.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/Breakpoint.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Target/ThreadSpec.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamFile.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Target/ThreadSpec.h"
26
27 using namespace lldb;
28 using namespace lldb_private;
29
30
SBBreakpointLocation()31 SBBreakpointLocation::SBBreakpointLocation () :
32 m_opaque_sp ()
33 {
34 }
35
SBBreakpointLocation(const lldb::BreakpointLocationSP & break_loc_sp)36 SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
37 m_opaque_sp (break_loc_sp)
38 {
39 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
40
41 if (log)
42 {
43 SBStream sstr;
44 GetDescription (sstr, lldb::eDescriptionLevelBrief);
45 log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp"
46 "=%p) => this.sp = %p (%s)", break_loc_sp.get(), m_opaque_sp.get(), sstr.GetData());
47 }
48 }
49
SBBreakpointLocation(const SBBreakpointLocation & rhs)50 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
51 m_opaque_sp (rhs.m_opaque_sp)
52 {
53 }
54
55 const SBBreakpointLocation &
operator =(const SBBreakpointLocation & rhs)56 SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
57 {
58 if (this != &rhs)
59 m_opaque_sp = rhs.m_opaque_sp;
60 return *this;
61 }
62
63
~SBBreakpointLocation()64 SBBreakpointLocation::~SBBreakpointLocation ()
65 {
66 }
67
68 bool
IsValid() const69 SBBreakpointLocation::IsValid() const
70 {
71 return m_opaque_sp.get() != NULL;
72 }
73
74 SBAddress
GetAddress()75 SBBreakpointLocation::GetAddress ()
76 {
77 if (m_opaque_sp)
78 return SBAddress(&m_opaque_sp->GetAddress());
79 else
80 return SBAddress();
81 }
82
83 addr_t
GetLoadAddress()84 SBBreakpointLocation::GetLoadAddress ()
85 {
86 addr_t ret_addr = LLDB_INVALID_ADDRESS;
87
88 if (m_opaque_sp)
89 {
90 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
91 ret_addr = m_opaque_sp->GetLoadAddress();
92 }
93
94 return ret_addr;
95 }
96
97 void
SetEnabled(bool enabled)98 SBBreakpointLocation::SetEnabled (bool enabled)
99 {
100 if (m_opaque_sp)
101 {
102 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
103 m_opaque_sp->SetEnabled (enabled);
104 }
105 }
106
107 bool
IsEnabled()108 SBBreakpointLocation::IsEnabled ()
109 {
110 if (m_opaque_sp)
111 {
112 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
113 return m_opaque_sp->IsEnabled();
114 }
115 else
116 return false;
117 }
118
119 uint32_t
GetIgnoreCount()120 SBBreakpointLocation::GetIgnoreCount ()
121 {
122 if (m_opaque_sp)
123 {
124 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
125 return m_opaque_sp->GetIgnoreCount();
126 }
127 else
128 return 0;
129 }
130
131 void
SetIgnoreCount(uint32_t n)132 SBBreakpointLocation::SetIgnoreCount (uint32_t n)
133 {
134 if (m_opaque_sp)
135 {
136 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
137 m_opaque_sp->SetIgnoreCount (n);
138 }
139 }
140
141 void
SetCondition(const char * condition)142 SBBreakpointLocation::SetCondition (const char *condition)
143 {
144 if (m_opaque_sp)
145 {
146 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
147 m_opaque_sp->SetCondition (condition);
148 }
149 }
150
151 const char *
GetCondition()152 SBBreakpointLocation::GetCondition ()
153 {
154 if (m_opaque_sp)
155 {
156 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
157 return m_opaque_sp->GetConditionText ();
158 }
159 return NULL;
160 }
161
162 void
SetThreadID(tid_t thread_id)163 SBBreakpointLocation::SetThreadID (tid_t thread_id)
164 {
165 if (m_opaque_sp)
166 {
167 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
168 m_opaque_sp->SetThreadID (thread_id);
169 }
170 }
171
172 tid_t
GetThreadID()173 SBBreakpointLocation::GetThreadID ()
174 {
175 tid_t tid = LLDB_INVALID_THREAD_ID;
176 if (m_opaque_sp)
177 {
178 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
179 return m_opaque_sp->GetThreadID();
180 }
181 return tid;
182 }
183
184 void
SetThreadIndex(uint32_t index)185 SBBreakpointLocation::SetThreadIndex (uint32_t index)
186 {
187 if (m_opaque_sp)
188 {
189 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
190 m_opaque_sp->SetThreadIndex (index);
191 }
192 }
193
194 uint32_t
GetThreadIndex() const195 SBBreakpointLocation::GetThreadIndex() const
196 {
197 uint32_t thread_idx = UINT32_MAX;
198 if (m_opaque_sp)
199 {
200 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
201 return m_opaque_sp->GetThreadIndex();
202 }
203 return thread_idx;
204 }
205
206
207 void
SetThreadName(const char * thread_name)208 SBBreakpointLocation::SetThreadName (const char *thread_name)
209 {
210 if (m_opaque_sp)
211 {
212 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
213 m_opaque_sp->SetThreadName (thread_name);
214 }
215 }
216
217 const char *
GetThreadName() const218 SBBreakpointLocation::GetThreadName () const
219 {
220 if (m_opaque_sp)
221 {
222 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
223 return m_opaque_sp->GetThreadName();
224 }
225 return NULL;
226 }
227
228 void
SetQueueName(const char * queue_name)229 SBBreakpointLocation::SetQueueName (const char *queue_name)
230 {
231 if (m_opaque_sp)
232 {
233 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
234 m_opaque_sp->SetQueueName (queue_name);
235 }
236 }
237
238 const char *
GetQueueName() const239 SBBreakpointLocation::GetQueueName () const
240 {
241 if (m_opaque_sp)
242 {
243 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
244 m_opaque_sp->GetQueueName ();
245 }
246 return NULL;
247 }
248
249 bool
IsResolved()250 SBBreakpointLocation::IsResolved ()
251 {
252 if (m_opaque_sp)
253 {
254 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
255 return m_opaque_sp->IsResolved();
256 }
257 return false;
258 }
259
260 void
SetLocation(const lldb::BreakpointLocationSP & break_loc_sp)261 SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
262 {
263 // Uninstall the callbacks?
264 m_opaque_sp = break_loc_sp;
265 }
266
267 bool
GetDescription(SBStream & description,DescriptionLevel level)268 SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
269 {
270 Stream &strm = description.ref();
271
272 if (m_opaque_sp)
273 {
274 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
275 m_opaque_sp->GetDescription (&strm, level);
276 strm.EOL();
277 }
278 else
279 strm.PutCString ("No value");
280
281 return true;
282 }
283
284 break_id_t
GetID()285 SBBreakpointLocation::GetID ()
286 {
287 if (m_opaque_sp)
288 {
289 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
290 return m_opaque_sp->GetID ();
291 }
292 else
293 return LLDB_INVALID_BREAK_ID;
294 }
295
296 SBBreakpoint
GetBreakpoint()297 SBBreakpointLocation::GetBreakpoint ()
298 {
299 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
300
301 //if (log)
302 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
303
304 SBBreakpoint sb_bp;
305 if (m_opaque_sp)
306 {
307 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
308 *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this();
309 }
310
311 if (log)
312 {
313 SBStream sstr;
314 sb_bp.GetDescription (sstr);
315 log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
316 m_opaque_sp.get(), sb_bp.get(), sstr.GetData());
317 }
318 return sb_bp;
319 }
320
321