blob: 8be67046ef42d202fb9665d0f336f25c9bcf42e3 [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 Ingham3fcc2972012-09-25 23:55:19 +0000237bool
238SBBreakpoint::IsInternal ()
239{
240 if (m_opaque_sp)
241 {
242 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
243 return m_opaque_sp->IsInternal();
244 }
245 else
246 return false;
247}
248
Chris Lattner24943d22010-06-08 16:52:24 +0000249void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000250SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner24943d22010-06-08 16:52:24 +0000251{
Greg Claytone005f2c2010-11-06 01:53:30 +0000252 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000253
254 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000255 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Tice7826c882010-10-26 03:11:13 +0000256
Greg Clayton63094e02010-06-23 01:19:29 +0000257 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000258 {
259 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000260 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonbdcda462010-12-20 20:49:23 +0000261 }
Chris Lattner24943d22010-06-08 16:52:24 +0000262}
263
Jim Inghame3740832010-10-22 01:15:49 +0000264void
265SBBreakpoint::SetCondition (const char *condition)
266{
Greg Claytonbdcda462010-12-20 20:49:23 +0000267 if (m_opaque_sp)
268 {
269 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
270 m_opaque_sp->SetCondition (condition);
271 }
Jim Inghame3740832010-10-22 01:15:49 +0000272}
273
274const char *
275SBBreakpoint::GetCondition ()
276{
Greg Claytonbdcda462010-12-20 20:49:23 +0000277 if (m_opaque_sp)
278 {
279 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
280 return m_opaque_sp->GetConditionText ();
281 }
282 return NULL;
Jim Inghame3740832010-10-22 01:15:49 +0000283}
284
Greg Clayton54e7afa2010-07-09 20:39:50 +0000285uint32_t
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000286SBBreakpoint::GetHitCount () const
287{
Greg Claytona66ba462010-10-30 04:51:46 +0000288 uint32_t count = 0;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000289 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000290 {
291 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000292 count = m_opaque_sp->GetHitCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000293 }
Greg Claytona66ba462010-10-30 04:51:46 +0000294
Greg Claytone005f2c2010-11-06 01:53:30 +0000295 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000296 if (log)
297 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
298
299 return count;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000300}
301
302uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000303SBBreakpoint::GetIgnoreCount () const
304{
Greg Claytona66ba462010-10-30 04:51:46 +0000305 uint32_t count = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000306 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000307 {
308 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000309 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000310 }
Greg Claytona66ba462010-10-30 04:51:46 +0000311
Greg Claytone005f2c2010-11-06 01:53:30 +0000312 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000313 if (log)
314 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
315
316 return count;
Chris Lattner24943d22010-06-08 16:52:24 +0000317}
318
319void
Greg Claytona66ba462010-10-30 04:51:46 +0000320SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner24943d22010-06-08 16:52:24 +0000321{
Greg Clayton63094e02010-06-23 01:19:29 +0000322 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000323 {
324 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000325 m_opaque_sp->SetThreadID (tid);
Greg Claytonbdcda462010-12-20 20:49:23 +0000326 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000327 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000328 if (log)
Greg Claytond9919d32011-12-01 23:28:38 +0000329 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4llx)", m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000330
Chris Lattner24943d22010-06-08 16:52:24 +0000331}
332
333tid_t
334SBBreakpoint::GetThreadID ()
335{
Greg Claytona66ba462010-10-30 04:51:46 +0000336 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000337 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000338 {
339 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000340 tid = m_opaque_sp->GetThreadID();
Greg Claytonbdcda462010-12-20 20:49:23 +0000341 }
Chris Lattner24943d22010-06-08 16:52:24 +0000342
Greg Claytone005f2c2010-11-06 01:53:30 +0000343 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000344 if (log)
Greg Claytond9919d32011-12-01 23:28:38 +0000345 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4llx", m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000346 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000347}
348
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000349void
350SBBreakpoint::SetThreadIndex (uint32_t index)
351{
Greg Claytone005f2c2010-11-06 01:53:30 +0000352 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000353 if (log)
354 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton63094e02010-06-23 01:19:29 +0000355 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000356 {
357 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000358 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonbdcda462010-12-20 20:49:23 +0000359 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000360}
361
362uint32_t
363SBBreakpoint::GetThreadIndex() const
364{
Greg Claytona6253872010-12-15 20:50:06 +0000365 uint32_t thread_idx = UINT32_MAX;
Greg Clayton63094e02010-06-23 01:19:29 +0000366 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000367 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000368 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
369 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000370 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000371 thread_idx = thread_spec->GetIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000372 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000373 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000374 if (log)
Greg Claytona6253872010-12-15 20:50:06 +0000375 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000376
Johnny Chenb3e71812010-12-15 21:39:37 +0000377 return thread_idx;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000378}
379
380
381void
382SBBreakpoint::SetThreadName (const char *thread_name)
383{
Greg Claytone005f2c2010-11-06 01:53:30 +0000384 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000385 if (log)
386 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
387
Greg Clayton63094e02010-06-23 01:19:29 +0000388 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000389 {
390 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000391 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000392 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000393}
394
395const char *
396SBBreakpoint::GetThreadName () const
397{
Greg Claytona66ba462010-10-30 04:51:46 +0000398 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000399 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000400 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000401 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
402 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000403 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000404 name = thread_spec->GetName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000405 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000406 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000407 if (log)
408 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
409
410 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000411}
412
413void
414SBBreakpoint::SetQueueName (const char *queue_name)
415{
Greg Claytone005f2c2010-11-06 01:53:30 +0000416 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000417 if (log)
418 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton63094e02010-06-23 01:19:29 +0000419 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000420 {
421 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000422 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000423 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000424}
425
426const char *
427SBBreakpoint::GetQueueName () const
428{
Greg Claytona66ba462010-10-30 04:51:46 +0000429 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000430 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000431 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000432 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
433 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
434 if (thread_spec)
Greg Claytona66ba462010-10-30 04:51:46 +0000435 name = thread_spec->GetQueueName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000436 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000437 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000438 if (log)
439 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
440
441 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000442}
443
Chris Lattner24943d22010-06-08 16:52:24 +0000444size_t
445SBBreakpoint::GetNumResolvedLocations() const
446{
Greg Claytona66ba462010-10-30 04:51:46 +0000447 size_t num_resolved = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000448 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000449 {
450 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000451 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000452 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000453 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000454 if (log)
Greg Clayton851e30e2012-09-18 18:04:04 +0000455 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %llu", m_opaque_sp.get(), (uint64_t)num_resolved);
Greg Claytona66ba462010-10-30 04:51:46 +0000456 return num_resolved;
Chris Lattner24943d22010-06-08 16:52:24 +0000457}
458
459size_t
460SBBreakpoint::GetNumLocations() const
461{
Greg Claytona66ba462010-10-30 04:51:46 +0000462 size_t num_locs = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000463 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000464 {
465 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000466 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000467 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000468 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000469 if (log)
Greg Clayton851e30e2012-09-18 18:04:04 +0000470 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %llu", m_opaque_sp.get(), (uint64_t)num_locs);
Greg Claytona66ba462010-10-30 04:51:46 +0000471 return num_locs;
Chris Lattner24943d22010-06-08 16:52:24 +0000472}
473
Caroline Tice98f930f2010-09-20 05:20:02 +0000474bool
Greg Claytond8c62532010-10-07 04:19:01 +0000475SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner24943d22010-06-08 16:52:24 +0000476{
Greg Clayton63094e02010-06-23 01:19:29 +0000477 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000478 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000479 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytond8c62532010-10-07 04:19:01 +0000480 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
481 m_opaque_sp->GetResolverDescription (s.get());
482 m_opaque_sp->GetFilterDescription (s.get());
483 const size_t num_locations = m_opaque_sp->GetNumLocations ();
Greg Clayton851e30e2012-09-18 18:04:04 +0000484 s.Printf(", locations = %llu", (uint64_t)num_locations);
Greg Claytond8c62532010-10-07 04:19:01 +0000485 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000486 }
Greg Claytond8c62532010-10-07 04:19:01 +0000487 s.Printf ("No value");
488 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000489}
490
Chris Lattner24943d22010-06-08 16:52:24 +0000491bool
492SBBreakpoint::PrivateBreakpointHitCallback
493(
494 void *baton,
495 StoppointCallbackContext *ctx,
496 lldb::user_id_t break_id,
497 lldb::user_id_t break_loc_id
498)
499{
Greg Claytonf4124de2012-02-21 00:09:25 +0000500 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
501 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000502 if (baton && bp_sp)
503 {
504 CallbackData *data = (CallbackData *)baton;
505 lldb_private::Breakpoint *bp = bp_sp.get();
506 if (bp && data->callback)
507 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000508 Process *process = exe_ctx.GetProcessPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000509 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +0000510 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000511 SBProcess sb_process (process->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000512 SBThread sb_thread;
513 SBBreakpointLocation sb_location;
514 assert (bp_sp);
515 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Claytonf4124de2012-02-21 00:09:25 +0000516 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000517 if (thread)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000518 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000519
520 return data->callback (data->callback_baton,
521 sb_process,
522 sb_thread,
523 sb_location);
524 }
525 }
526 }
527 return true; // Return true if we should stop at this breakpoint
528}
529
530void
531SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
532{
Greg Claytone005f2c2010-11-06 01:53:30 +0000533 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000534
535 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000536 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Tice7826c882010-10-26 03:11:13 +0000537
Greg Clayton567e7f32011-09-22 04:58:26 +0000538 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000539 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000540 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000541 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton63094e02010-06-23 01:19:29 +0000542 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000543 }
544}
545
546
547lldb_private::Breakpoint *
548SBBreakpoint::operator->() const
549{
Greg Clayton63094e02010-06-23 01:19:29 +0000550 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000551}
552
553lldb_private::Breakpoint *
554SBBreakpoint::get() const
555{
Greg Clayton63094e02010-06-23 01:19:29 +0000556 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000557}
558
559lldb::BreakpointSP &
560SBBreakpoint::operator *()
561{
Greg Clayton63094e02010-06-23 01:19:29 +0000562 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000563}
564
565const lldb::BreakpointSP &
566SBBreakpoint::operator *() const
567{
Greg Clayton63094e02010-06-23 01:19:29 +0000568 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000569}
570
Jim Ingham28e23862012-02-08 05:23:15 +0000571bool
572SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
573{
574 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
575
576}
577
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000578BreakpointEventType
579SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
580{
581 if (event.IsValid())
582 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
583 return eBreakpointEventTypeInvalidType;
584}
585
586SBBreakpoint
587SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
588{
589 SBBreakpoint sb_breakpoint;
590 if (event.IsValid())
591 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
592 return sb_breakpoint;
593}
594
595SBBreakpointLocation
596SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
597{
598 SBBreakpointLocation sb_breakpoint_loc;
599 if (event.IsValid())
600 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
601 return sb_breakpoint_loc;
602}
603
Jim Ingham28e23862012-02-08 05:23:15 +0000604uint32_t
605SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
606{
607 uint32_t num_locations = 0;
608 if (event.IsValid())
609 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
610 return num_locations;
611}
612
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000613