blob: f0e29176a9ea40b9ff4ca54ec3452d04c69af2ce [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBBreakpoint.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/SBBreakpoint.h"
11#include "lldb/API/SBBreakpointLocation.h"
12#include "lldb/API/SBDebugger.h"
Greg Claytonc7f5d5c2010-07-23 23:33:17 +000013#include "lldb/API/SBEvent.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/API/SBThread.h"
17
18#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
20#include "lldb/Breakpoint/StoppointCallbackContext.h"
21#include "lldb/Core/Address.h"
Caroline Tice7826c882010-10-26 03:11:13 +000022#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Stream.h"
24#include "lldb/Core/StreamFile.h"
25#include "lldb/Target/Process.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Target/Target.h"
Jim Ingham8e5e38f2010-06-18 01:47:08 +000027#include "lldb/Target/Thread.h"
28#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029
30
31#include "lldb/lldb-enumerations.h"
32
33using namespace lldb;
34using namespace lldb_private;
35
36struct CallbackData
37{
38 SBBreakpoint::BreakpointHitCallback callback;
39 void *callback_baton;
40};
41
42class SBBreakpointCallbackBaton : public Baton
43{
44public:
45
46 SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
47 Baton (new CallbackData)
48 {
49 CallbackData *data = (CallbackData *)m_data;
50 data->callback = callback;
51 data->callback_baton = baton;
52 }
53
54 virtual ~SBBreakpointCallbackBaton()
55 {
56 CallbackData *data = (CallbackData *)m_data;
57
58 if (data)
59 {
60 delete data;
61 m_data = NULL;
62 }
63 }
64};
65
66
67SBBreakpoint::SBBreakpoint () :
Greg Clayton63094e02010-06-23 01:19:29 +000068 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000069{
70}
71
72SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000073 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000074{
75}
76
77
78SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000079 m_opaque_sp (bp_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000080{
81}
82
83SBBreakpoint::~SBBreakpoint()
84{
85}
86
87const SBBreakpoint &
88SBBreakpoint::operator = (const SBBreakpoint& rhs)
89{
90 if (this != &rhs)
Greg Clayton63094e02010-06-23 01:19:29 +000091 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000092 return *this;
93}
94
Greg Claytonea49cc72010-12-12 19:25:26 +000095bool
96SBBreakpoint::operator == (const lldb::SBBreakpoint& rhs)
97{
98 if (m_opaque_sp && rhs.m_opaque_sp)
99 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
100 return false;
101}
102
Chris Lattner24943d22010-06-08 16:52:24 +0000103break_id_t
104SBBreakpoint::GetID () const
105{
Greg Claytone005f2c2010-11-06 01:53:30 +0000106 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000107
Greg Claytonbdcda462010-12-20 20:49:23 +0000108 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000109 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000110 break_id = m_opaque_sp->GetID();
Caroline Tice7826c882010-10-26 03:11:13 +0000111
112 if (log)
Greg Claytonbdcda462010-12-20 20:49:23 +0000113 {
114 if (break_id == LLDB_INVALID_BREAK_ID)
115 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get());
116 else
117 log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id);
118 }
Caroline Tice7826c882010-10-26 03:11:13 +0000119
Greg Claytonbdcda462010-12-20 20:49:23 +0000120 return break_id;
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123
124bool
125SBBreakpoint::IsValid() const
126{
Jim Ingham9880efa2012-08-11 00:35:26 +0000127 return (bool) m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000128}
129
130void
Chris Lattner24943d22010-06-08 16:52:24 +0000131SBBreakpoint::ClearAllBreakpointSites ()
132{
Greg Clayton63094e02010-06-23 01:19:29 +0000133 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000134 {
135 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000136 m_opaque_sp->ClearAllBreakpointSites ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000137 }
Chris Lattner24943d22010-06-08 16:52:24 +0000138}
139
140SBBreakpointLocation
141SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
142{
143 SBBreakpointLocation sb_bp_location;
144
Greg Clayton63094e02010-06-23 01:19:29 +0000145 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000146 {
147 if (vm_addr != LLDB_INVALID_ADDRESS)
148 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000149 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000150 Address address;
Greg Claytoneea26402010-09-14 23:36:40 +0000151 Target &target = m_opaque_sp->GetTarget();
152 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000153 {
Greg Clayton3508c382012-02-24 01:59:29 +0000154 address.SetRawAddress (vm_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000155 }
Greg Clayton63094e02010-06-23 01:19:29 +0000156 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner24943d22010-06-08 16:52:24 +0000157 }
158 }
159 return sb_bp_location;
160}
161
162break_id_t
163SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
164{
Greg Claytonbdcda462010-12-20 20:49:23 +0000165 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000166
Greg Claytonbdcda462010-12-20 20:49:23 +0000167 if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +0000168 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000169 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
170 Address address;
171 Target &target = m_opaque_sp->GetTarget();
172 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000173 {
Greg Clayton3508c382012-02-24 01:59:29 +0000174 address.SetRawAddress (vm_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000175 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000176 break_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner24943d22010-06-08 16:52:24 +0000177 }
178
Greg Claytonbdcda462010-12-20 20:49:23 +0000179 return break_id;
Chris Lattner24943d22010-06-08 16:52:24 +0000180}
181
182SBBreakpointLocation
183SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
184{
185 SBBreakpointLocation sb_bp_location;
186
Greg Clayton63094e02010-06-23 01:19:29 +0000187 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000188 {
189 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000190 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Greg Claytonbdcda462010-12-20 20:49:23 +0000191 }
Chris Lattner24943d22010-06-08 16:52:24 +0000192
193 return sb_bp_location;
194}
195
196SBBreakpointLocation
197SBBreakpoint::GetLocationAtIndex (uint32_t index)
198{
199 SBBreakpointLocation sb_bp_location;
200
Greg Clayton63094e02010-06-23 01:19:29 +0000201 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000202 {
203 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000204 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Greg Claytonbdcda462010-12-20 20:49:23 +0000205 }
Chris Lattner24943d22010-06-08 16:52:24 +0000206
207 return sb_bp_location;
208}
209
210void
Chris Lattner24943d22010-06-08 16:52:24 +0000211SBBreakpoint::SetEnabled (bool enable)
212{
Greg Claytone005f2c2010-11-06 01:53:30 +0000213 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000214
215 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000216 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable);
Caroline Tice7826c882010-10-26 03:11:13 +0000217
Greg Clayton63094e02010-06-23 01:19:29 +0000218 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000219 {
220 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000221 m_opaque_sp->SetEnabled (enable);
Greg Claytonbdcda462010-12-20 20:49:23 +0000222 }
Chris Lattner24943d22010-06-08 16:52:24 +0000223}
224
225bool
226SBBreakpoint::IsEnabled ()
227{
Greg Clayton63094e02010-06-23 01:19:29 +0000228 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000229 {
230 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000231 return m_opaque_sp->IsEnabled();
Greg Claytonbdcda462010-12-20 20:49:23 +0000232 }
Chris Lattner24943d22010-06-08 16:52:24 +0000233 else
234 return false;
235}
236
Jim Ingham2753a022012-10-05 19:16:31 +0000237void
238SBBreakpoint::SetOneShot (bool one_shot)
239{
240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
241
242 if (log)
243 log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)", m_opaque_sp.get(), one_shot);
244
245 if (m_opaque_sp)
246 {
247 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
248 m_opaque_sp->SetOneShot (one_shot);
249 }
250}
251
252bool
253SBBreakpoint::IsOneShot () const
254{
255 if (m_opaque_sp)
256 {
257 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
258 return m_opaque_sp->IsOneShot();
259 }
260 else
261 return false;
262}
263
Jim Ingham3fcc2972012-09-25 23:55:19 +0000264bool
265SBBreakpoint::IsInternal ()
266{
267 if (m_opaque_sp)
268 {
269 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
270 return m_opaque_sp->IsInternal();
271 }
272 else
273 return false;
274}
275
Chris Lattner24943d22010-06-08 16:52:24 +0000276void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000277SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner24943d22010-06-08 16:52:24 +0000278{
Greg Claytone005f2c2010-11-06 01:53:30 +0000279 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000280
281 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000282 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Tice7826c882010-10-26 03:11:13 +0000283
Greg Clayton63094e02010-06-23 01:19:29 +0000284 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000285 {
286 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000287 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonbdcda462010-12-20 20:49:23 +0000288 }
Chris Lattner24943d22010-06-08 16:52:24 +0000289}
290
Jim Inghame3740832010-10-22 01:15:49 +0000291void
292SBBreakpoint::SetCondition (const char *condition)
293{
Greg Claytonbdcda462010-12-20 20:49:23 +0000294 if (m_opaque_sp)
295 {
296 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
297 m_opaque_sp->SetCondition (condition);
298 }
Jim Inghame3740832010-10-22 01:15:49 +0000299}
300
301const char *
302SBBreakpoint::GetCondition ()
303{
Greg Claytonbdcda462010-12-20 20:49:23 +0000304 if (m_opaque_sp)
305 {
306 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
307 return m_opaque_sp->GetConditionText ();
308 }
309 return NULL;
Jim Inghame3740832010-10-22 01:15:49 +0000310}
311
Greg Clayton54e7afa2010-07-09 20:39:50 +0000312uint32_t
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000313SBBreakpoint::GetHitCount () const
314{
Greg Claytona66ba462010-10-30 04:51:46 +0000315 uint32_t count = 0;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000316 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000317 {
318 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000319 count = m_opaque_sp->GetHitCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000320 }
Greg Claytona66ba462010-10-30 04:51:46 +0000321
Greg Claytone005f2c2010-11-06 01:53:30 +0000322 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000323 if (log)
324 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
325
326 return count;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000327}
328
329uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000330SBBreakpoint::GetIgnoreCount () const
331{
Greg Claytona66ba462010-10-30 04:51:46 +0000332 uint32_t count = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000333 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000334 {
335 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000336 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000337 }
Greg Claytona66ba462010-10-30 04:51:46 +0000338
Greg Claytone005f2c2010-11-06 01:53:30 +0000339 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000340 if (log)
341 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
342
343 return count;
Chris Lattner24943d22010-06-08 16:52:24 +0000344}
345
346void
Greg Claytona66ba462010-10-30 04:51:46 +0000347SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner24943d22010-06-08 16:52:24 +0000348{
Greg Clayton63094e02010-06-23 01:19:29 +0000349 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000350 {
351 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000352 m_opaque_sp->SetThreadID (tid);
Greg Claytonbdcda462010-12-20 20:49:23 +0000353 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000354 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000355 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000356 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")", m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000357
Chris Lattner24943d22010-06-08 16:52:24 +0000358}
359
360tid_t
361SBBreakpoint::GetThreadID ()
362{
Greg Claytona66ba462010-10-30 04:51:46 +0000363 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000364 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000365 {
366 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000367 tid = m_opaque_sp->GetThreadID();
Greg Claytonbdcda462010-12-20 20:49:23 +0000368 }
Chris Lattner24943d22010-06-08 16:52:24 +0000369
Greg Claytone005f2c2010-11-06 01:53:30 +0000370 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000371 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000372 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64, m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000373 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000374}
375
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000376void
377SBBreakpoint::SetThreadIndex (uint32_t index)
378{
Greg Claytone005f2c2010-11-06 01:53:30 +0000379 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000380 if (log)
381 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton63094e02010-06-23 01:19:29 +0000382 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000383 {
384 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000385 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonbdcda462010-12-20 20:49:23 +0000386 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000387}
388
389uint32_t
390SBBreakpoint::GetThreadIndex() const
391{
Greg Claytona6253872010-12-15 20:50:06 +0000392 uint32_t thread_idx = UINT32_MAX;
Greg Clayton63094e02010-06-23 01:19:29 +0000393 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000394 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000395 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
396 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000397 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000398 thread_idx = thread_spec->GetIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000399 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000400 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000401 if (log)
Greg Claytona6253872010-12-15 20:50:06 +0000402 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000403
Johnny Chenb3e71812010-12-15 21:39:37 +0000404 return thread_idx;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000405}
406
407
408void
409SBBreakpoint::SetThreadName (const char *thread_name)
410{
Greg Claytone005f2c2010-11-06 01:53:30 +0000411 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000412 if (log)
413 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
414
Greg Clayton63094e02010-06-23 01:19:29 +0000415 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000416 {
417 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000418 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000419 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000420}
421
422const char *
423SBBreakpoint::GetThreadName () const
424{
Greg Claytona66ba462010-10-30 04:51:46 +0000425 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000426 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000427 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000428 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
429 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000430 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000431 name = thread_spec->GetName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000432 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000433 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000434 if (log)
435 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
436
437 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000438}
439
440void
441SBBreakpoint::SetQueueName (const char *queue_name)
442{
Greg Claytone005f2c2010-11-06 01:53:30 +0000443 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000444 if (log)
445 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton63094e02010-06-23 01:19:29 +0000446 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000447 {
448 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000449 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000450 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000451}
452
453const char *
454SBBreakpoint::GetQueueName () const
455{
Greg Claytona66ba462010-10-30 04:51:46 +0000456 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000457 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000458 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000459 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
460 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
461 if (thread_spec)
Greg Claytona66ba462010-10-30 04:51:46 +0000462 name = thread_spec->GetQueueName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000463 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000464 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000465 if (log)
466 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
467
468 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000469}
470
Chris Lattner24943d22010-06-08 16:52:24 +0000471size_t
472SBBreakpoint::GetNumResolvedLocations() const
473{
Greg Claytona66ba462010-10-30 04:51:46 +0000474 size_t num_resolved = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000475 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000476 {
477 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000478 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000479 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000480 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000481 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000482 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_resolved);
Greg Claytona66ba462010-10-30 04:51:46 +0000483 return num_resolved;
Chris Lattner24943d22010-06-08 16:52:24 +0000484}
485
486size_t
487SBBreakpoint::GetNumLocations() const
488{
Greg Claytona66ba462010-10-30 04:51:46 +0000489 size_t num_locs = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000490 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000491 {
492 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000493 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000494 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000495 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000496 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000497 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_locs);
Greg Claytona66ba462010-10-30 04:51:46 +0000498 return num_locs;
Chris Lattner24943d22010-06-08 16:52:24 +0000499}
500
Caroline Tice98f930f2010-09-20 05:20:02 +0000501bool
Greg Claytond8c62532010-10-07 04:19:01 +0000502SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner24943d22010-06-08 16:52:24 +0000503{
Greg Clayton63094e02010-06-23 01:19:29 +0000504 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000505 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000506 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytond8c62532010-10-07 04:19:01 +0000507 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
508 m_opaque_sp->GetResolverDescription (s.get());
509 m_opaque_sp->GetFilterDescription (s.get());
510 const size_t num_locations = m_opaque_sp->GetNumLocations ();
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000511 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
Greg Claytond8c62532010-10-07 04:19:01 +0000512 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000513 }
Greg Claytond8c62532010-10-07 04:19:01 +0000514 s.Printf ("No value");
515 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000516}
517
Chris Lattner24943d22010-06-08 16:52:24 +0000518bool
519SBBreakpoint::PrivateBreakpointHitCallback
520(
521 void *baton,
522 StoppointCallbackContext *ctx,
523 lldb::user_id_t break_id,
524 lldb::user_id_t break_loc_id
525)
526{
Greg Claytonf4124de2012-02-21 00:09:25 +0000527 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
528 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000529 if (baton && bp_sp)
530 {
531 CallbackData *data = (CallbackData *)baton;
532 lldb_private::Breakpoint *bp = bp_sp.get();
533 if (bp && data->callback)
534 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000535 Process *process = exe_ctx.GetProcessPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000536 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +0000537 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000538 SBProcess sb_process (process->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000539 SBThread sb_thread;
540 SBBreakpointLocation sb_location;
541 assert (bp_sp);
542 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Claytonf4124de2012-02-21 00:09:25 +0000543 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000544 if (thread)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000545 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000546
547 return data->callback (data->callback_baton,
548 sb_process,
549 sb_thread,
550 sb_location);
551 }
552 }
553 }
554 return true; // Return true if we should stop at this breakpoint
555}
556
557void
558SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
559{
Greg Claytone005f2c2010-11-06 01:53:30 +0000560 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000561
562 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000563 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Tice7826c882010-10-26 03:11:13 +0000564
Greg Clayton567e7f32011-09-22 04:58:26 +0000565 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000566 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000567 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000568 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton63094e02010-06-23 01:19:29 +0000569 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000570 }
571}
572
573
574lldb_private::Breakpoint *
575SBBreakpoint::operator->() const
576{
Greg Clayton63094e02010-06-23 01:19:29 +0000577 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000578}
579
580lldb_private::Breakpoint *
581SBBreakpoint::get() const
582{
Greg Clayton63094e02010-06-23 01:19:29 +0000583 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000584}
585
586lldb::BreakpointSP &
587SBBreakpoint::operator *()
588{
Greg Clayton63094e02010-06-23 01:19:29 +0000589 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000590}
591
592const lldb::BreakpointSP &
593SBBreakpoint::operator *() const
594{
Greg Clayton63094e02010-06-23 01:19:29 +0000595 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000596}
597
Jim Ingham28e23862012-02-08 05:23:15 +0000598bool
599SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
600{
601 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
602
603}
604
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000605BreakpointEventType
606SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
607{
608 if (event.IsValid())
609 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
610 return eBreakpointEventTypeInvalidType;
611}
612
613SBBreakpoint
614SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
615{
616 SBBreakpoint sb_breakpoint;
617 if (event.IsValid())
618 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
619 return sb_breakpoint;
620}
621
622SBBreakpointLocation
623SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
624{
625 SBBreakpointLocation sb_breakpoint_loc;
626 if (event.IsValid())
627 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
628 return sb_breakpoint_loc;
629}
630
Jim Ingham28e23862012-02-08 05:23:15 +0000631uint32_t
632SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
633{
634 uint32_t num_locations = 0;
635 if (event.IsValid())
636 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
637 return num_locations;
638}
639
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000640