blob: 3adb031e0362b7a30c9f350877db15f32b3f8e21 [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{
Greg Clayton63094e02010-06-23 01:19:29 +0000127 return 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
237void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000238SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner24943d22010-06-08 16:52:24 +0000239{
Greg Claytone005f2c2010-11-06 01:53:30 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000241
242 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000243 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Tice7826c882010-10-26 03:11:13 +0000244
Greg Clayton63094e02010-06-23 01:19:29 +0000245 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000246 {
247 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000248 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonbdcda462010-12-20 20:49:23 +0000249 }
Chris Lattner24943d22010-06-08 16:52:24 +0000250}
251
Jim Inghame3740832010-10-22 01:15:49 +0000252void
253SBBreakpoint::SetCondition (const char *condition)
254{
Greg Claytonbdcda462010-12-20 20:49:23 +0000255 if (m_opaque_sp)
256 {
257 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
258 m_opaque_sp->SetCondition (condition);
259 }
Jim Inghame3740832010-10-22 01:15:49 +0000260}
261
262const char *
263SBBreakpoint::GetCondition ()
264{
Greg Claytonbdcda462010-12-20 20:49:23 +0000265 if (m_opaque_sp)
266 {
267 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
268 return m_opaque_sp->GetConditionText ();
269 }
270 return NULL;
Jim Inghame3740832010-10-22 01:15:49 +0000271}
272
Greg Clayton54e7afa2010-07-09 20:39:50 +0000273uint32_t
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000274SBBreakpoint::GetHitCount () const
275{
Greg Claytona66ba462010-10-30 04:51:46 +0000276 uint32_t count = 0;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000277 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000278 {
279 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000280 count = m_opaque_sp->GetHitCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000281 }
Greg Claytona66ba462010-10-30 04:51:46 +0000282
Greg Claytone005f2c2010-11-06 01:53:30 +0000283 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000284 if (log)
285 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
286
287 return count;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000288}
289
290uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000291SBBreakpoint::GetIgnoreCount () const
292{
Greg Claytona66ba462010-10-30 04:51:46 +0000293 uint32_t count = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000294 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000295 {
296 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000297 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000298 }
Greg Claytona66ba462010-10-30 04:51:46 +0000299
Greg Claytone005f2c2010-11-06 01:53:30 +0000300 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000301 if (log)
302 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
303
304 return count;
Chris Lattner24943d22010-06-08 16:52:24 +0000305}
306
307void
Greg Claytona66ba462010-10-30 04:51:46 +0000308SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner24943d22010-06-08 16:52:24 +0000309{
Greg Clayton63094e02010-06-23 01:19:29 +0000310 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000311 {
312 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000313 m_opaque_sp->SetThreadID (tid);
Greg Claytonbdcda462010-12-20 20:49:23 +0000314 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000315 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000316 if (log)
Greg Claytond9919d32011-12-01 23:28:38 +0000317 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4llx)", m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000318
Chris Lattner24943d22010-06-08 16:52:24 +0000319}
320
321tid_t
322SBBreakpoint::GetThreadID ()
323{
Greg Claytona66ba462010-10-30 04:51:46 +0000324 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000325 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000326 {
327 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000328 tid = m_opaque_sp->GetThreadID();
Greg Claytonbdcda462010-12-20 20:49:23 +0000329 }
Chris Lattner24943d22010-06-08 16:52:24 +0000330
Greg Claytone005f2c2010-11-06 01:53:30 +0000331 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000332 if (log)
Greg Claytond9919d32011-12-01 23:28:38 +0000333 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4llx", m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000334 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000335}
336
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000337void
338SBBreakpoint::SetThreadIndex (uint32_t index)
339{
Greg Claytone005f2c2010-11-06 01:53:30 +0000340 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000341 if (log)
342 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton63094e02010-06-23 01:19:29 +0000343 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000344 {
345 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000346 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonbdcda462010-12-20 20:49:23 +0000347 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000348}
349
350uint32_t
351SBBreakpoint::GetThreadIndex() const
352{
Greg Claytona6253872010-12-15 20:50:06 +0000353 uint32_t thread_idx = UINT32_MAX;
Greg Clayton63094e02010-06-23 01:19:29 +0000354 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000355 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000356 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
357 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000358 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000359 thread_idx = thread_spec->GetIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000360 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000361 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000362 if (log)
Greg Claytona6253872010-12-15 20:50:06 +0000363 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000364
Johnny Chenb3e71812010-12-15 21:39:37 +0000365 return thread_idx;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000366}
367
368
369void
370SBBreakpoint::SetThreadName (const char *thread_name)
371{
Greg Claytone005f2c2010-11-06 01:53:30 +0000372 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000373 if (log)
374 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
375
Greg Clayton63094e02010-06-23 01:19:29 +0000376 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000377 {
378 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000379 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000380 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000381}
382
383const char *
384SBBreakpoint::GetThreadName () const
385{
Greg Claytona66ba462010-10-30 04:51:46 +0000386 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000387 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000388 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000389 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
390 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000391 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000392 name = thread_spec->GetName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000393 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000394 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000395 if (log)
396 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
397
398 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000399}
400
401void
402SBBreakpoint::SetQueueName (const char *queue_name)
403{
Greg Claytone005f2c2010-11-06 01:53:30 +0000404 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000405 if (log)
406 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton63094e02010-06-23 01:19:29 +0000407 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000408 {
409 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000410 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000411 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000412}
413
414const char *
415SBBreakpoint::GetQueueName () const
416{
Greg Claytona66ba462010-10-30 04:51:46 +0000417 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000418 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000419 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000420 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
421 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
422 if (thread_spec)
Greg Claytona66ba462010-10-30 04:51:46 +0000423 name = thread_spec->GetQueueName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000424 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000425 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000426 if (log)
427 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
428
429 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000430}
431
Chris Lattner24943d22010-06-08 16:52:24 +0000432size_t
433SBBreakpoint::GetNumResolvedLocations() const
434{
Greg Claytona66ba462010-10-30 04:51:46 +0000435 size_t num_resolved = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000436 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000437 {
438 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000439 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000440 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000441 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000442 if (log)
443 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %zu", m_opaque_sp.get(), num_resolved);
444 return num_resolved;
Chris Lattner24943d22010-06-08 16:52:24 +0000445}
446
447size_t
448SBBreakpoint::GetNumLocations() const
449{
Greg Claytona66ba462010-10-30 04:51:46 +0000450 size_t num_locs = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000451 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000452 {
453 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000454 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000455 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000456 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000457 if (log)
458 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %zu", m_opaque_sp.get(), num_locs);
459 return num_locs;
Chris Lattner24943d22010-06-08 16:52:24 +0000460}
461
Caroline Tice98f930f2010-09-20 05:20:02 +0000462bool
Greg Claytond8c62532010-10-07 04:19:01 +0000463SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner24943d22010-06-08 16:52:24 +0000464{
Greg Clayton63094e02010-06-23 01:19:29 +0000465 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000466 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000467 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytond8c62532010-10-07 04:19:01 +0000468 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
469 m_opaque_sp->GetResolverDescription (s.get());
470 m_opaque_sp->GetFilterDescription (s.get());
471 const size_t num_locations = m_opaque_sp->GetNumLocations ();
472 s.Printf(", locations = %zu", num_locations);
473 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000474 }
Greg Claytond8c62532010-10-07 04:19:01 +0000475 s.Printf ("No value");
476 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000477}
478
Chris Lattner24943d22010-06-08 16:52:24 +0000479bool
480SBBreakpoint::PrivateBreakpointHitCallback
481(
482 void *baton,
483 StoppointCallbackContext *ctx,
484 lldb::user_id_t break_id,
485 lldb::user_id_t break_loc_id
486)
487{
Greg Claytonf4124de2012-02-21 00:09:25 +0000488 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
489 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000490 if (baton && bp_sp)
491 {
492 CallbackData *data = (CallbackData *)baton;
493 lldb_private::Breakpoint *bp = bp_sp.get();
494 if (bp && data->callback)
495 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000496 Process *process = exe_ctx.GetProcessPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000497 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +0000498 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000499 SBProcess sb_process (process->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000500 SBThread sb_thread;
501 SBBreakpointLocation sb_location;
502 assert (bp_sp);
503 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Claytonf4124de2012-02-21 00:09:25 +0000504 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000505 if (thread)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000506 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000507
508 return data->callback (data->callback_baton,
509 sb_process,
510 sb_thread,
511 sb_location);
512 }
513 }
514 }
515 return true; // Return true if we should stop at this breakpoint
516}
517
518void
519SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
520{
Greg Claytone005f2c2010-11-06 01:53:30 +0000521 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000522
523 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000524 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Tice7826c882010-10-26 03:11:13 +0000525
Greg Clayton567e7f32011-09-22 04:58:26 +0000526 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000527 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000528 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000529 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton63094e02010-06-23 01:19:29 +0000530 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000531 }
532}
533
534
535lldb_private::Breakpoint *
536SBBreakpoint::operator->() const
537{
Greg Clayton63094e02010-06-23 01:19:29 +0000538 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000539}
540
541lldb_private::Breakpoint *
542SBBreakpoint::get() const
543{
Greg Clayton63094e02010-06-23 01:19:29 +0000544 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000545}
546
547lldb::BreakpointSP &
548SBBreakpoint::operator *()
549{
Greg Clayton63094e02010-06-23 01:19:29 +0000550 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000551}
552
553const lldb::BreakpointSP &
554SBBreakpoint::operator *() const
555{
Greg Clayton63094e02010-06-23 01:19:29 +0000556 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000557}
558
Jim Ingham28e23862012-02-08 05:23:15 +0000559bool
560SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
561{
562 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
563
564}
565
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000566BreakpointEventType
567SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
568{
569 if (event.IsValid())
570 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
571 return eBreakpointEventTypeInvalidType;
572}
573
574SBBreakpoint
575SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
576{
577 SBBreakpoint sb_breakpoint;
578 if (event.IsValid())
579 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
580 return sb_breakpoint;
581}
582
583SBBreakpointLocation
584SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
585{
586 SBBreakpointLocation sb_breakpoint_loc;
587 if (event.IsValid())
588 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
589 return sb_breakpoint_loc;
590}
591
Jim Ingham28e23862012-02-08 05:23:15 +0000592uint32_t
593SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
594{
595 uint32_t num_locations = 0;
596 if (event.IsValid())
597 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
598 return num_locations;
599}
600
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000601