blob: 11ad149fdddcd2a0d7589ba22b1826141f1dda8c [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
Enrico Granata0765e322013-05-03 01:29:27 +0000103bool
104SBBreakpoint::operator != (const lldb::SBBreakpoint& rhs)
105{
106 if (m_opaque_sp && rhs.m_opaque_sp)
107 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
108 return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp);
109}
110
Chris Lattner24943d22010-06-08 16:52:24 +0000111break_id_t
112SBBreakpoint::GetID () const
113{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000114 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000115
Greg Claytonbdcda462010-12-20 20:49:23 +0000116 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000117 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000118 break_id = m_opaque_sp->GetID();
Caroline Tice7826c882010-10-26 03:11:13 +0000119
120 if (log)
Greg Claytonbdcda462010-12-20 20:49:23 +0000121 {
122 if (break_id == LLDB_INVALID_BREAK_ID)
123 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get());
124 else
125 log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id);
126 }
Caroline Tice7826c882010-10-26 03:11:13 +0000127
Greg Claytonbdcda462010-12-20 20:49:23 +0000128 return break_id;
Chris Lattner24943d22010-06-08 16:52:24 +0000129}
130
131
132bool
133SBBreakpoint::IsValid() const
134{
Jim Ingham9880efa2012-08-11 00:35:26 +0000135 return (bool) m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
138void
Chris Lattner24943d22010-06-08 16:52:24 +0000139SBBreakpoint::ClearAllBreakpointSites ()
140{
Greg Clayton63094e02010-06-23 01:19:29 +0000141 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000142 {
143 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000144 m_opaque_sp->ClearAllBreakpointSites ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000145 }
Chris Lattner24943d22010-06-08 16:52:24 +0000146}
147
148SBBreakpointLocation
149SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
150{
151 SBBreakpointLocation sb_bp_location;
152
Greg Clayton63094e02010-06-23 01:19:29 +0000153 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000154 {
155 if (vm_addr != LLDB_INVALID_ADDRESS)
156 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000157 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000158 Address address;
Greg Claytoneea26402010-09-14 23:36:40 +0000159 Target &target = m_opaque_sp->GetTarget();
160 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000161 {
Greg Clayton3508c382012-02-24 01:59:29 +0000162 address.SetRawAddress (vm_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000163 }
Greg Clayton63094e02010-06-23 01:19:29 +0000164 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner24943d22010-06-08 16:52:24 +0000165 }
166 }
167 return sb_bp_location;
168}
169
170break_id_t
171SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
172{
Greg Claytonbdcda462010-12-20 20:49:23 +0000173 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000174
Greg Claytonbdcda462010-12-20 20:49:23 +0000175 if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +0000176 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000177 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
178 Address address;
179 Target &target = m_opaque_sp->GetTarget();
180 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000181 {
Greg Clayton3508c382012-02-24 01:59:29 +0000182 address.SetRawAddress (vm_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000183 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000184 break_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner24943d22010-06-08 16:52:24 +0000185 }
186
Greg Claytonbdcda462010-12-20 20:49:23 +0000187 return break_id;
Chris Lattner24943d22010-06-08 16:52:24 +0000188}
189
190SBBreakpointLocation
191SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
192{
193 SBBreakpointLocation sb_bp_location;
194
Greg Clayton63094e02010-06-23 01:19:29 +0000195 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000196 {
197 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000198 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Greg Claytonbdcda462010-12-20 20:49:23 +0000199 }
Chris Lattner24943d22010-06-08 16:52:24 +0000200
201 return sb_bp_location;
202}
203
204SBBreakpointLocation
205SBBreakpoint::GetLocationAtIndex (uint32_t index)
206{
207 SBBreakpointLocation sb_bp_location;
208
Greg Clayton63094e02010-06-23 01:19:29 +0000209 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000210 {
211 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000212 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Greg Claytonbdcda462010-12-20 20:49:23 +0000213 }
Chris Lattner24943d22010-06-08 16:52:24 +0000214
215 return sb_bp_location;
216}
217
218void
Chris Lattner24943d22010-06-08 16:52:24 +0000219SBBreakpoint::SetEnabled (bool enable)
220{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000221 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000222
223 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000224 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable);
Caroline Tice7826c882010-10-26 03:11:13 +0000225
Greg Clayton63094e02010-06-23 01:19:29 +0000226 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000227 {
228 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000229 m_opaque_sp->SetEnabled (enable);
Greg Claytonbdcda462010-12-20 20:49:23 +0000230 }
Chris Lattner24943d22010-06-08 16:52:24 +0000231}
232
233bool
234SBBreakpoint::IsEnabled ()
235{
Greg Clayton63094e02010-06-23 01:19:29 +0000236 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000237 {
238 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000239 return m_opaque_sp->IsEnabled();
Greg Claytonbdcda462010-12-20 20:49:23 +0000240 }
Chris Lattner24943d22010-06-08 16:52:24 +0000241 else
242 return false;
243}
244
Jim Ingham2753a022012-10-05 19:16:31 +0000245void
246SBBreakpoint::SetOneShot (bool one_shot)
247{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000248 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham2753a022012-10-05 19:16:31 +0000249
250 if (log)
251 log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)", m_opaque_sp.get(), one_shot);
252
253 if (m_opaque_sp)
254 {
255 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
256 m_opaque_sp->SetOneShot (one_shot);
257 }
258}
259
260bool
261SBBreakpoint::IsOneShot () const
262{
263 if (m_opaque_sp)
264 {
265 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
266 return m_opaque_sp->IsOneShot();
267 }
268 else
269 return false;
270}
271
Jim Ingham3fcc2972012-09-25 23:55:19 +0000272bool
273SBBreakpoint::IsInternal ()
274{
275 if (m_opaque_sp)
276 {
277 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
278 return m_opaque_sp->IsInternal();
279 }
280 else
281 return false;
282}
283
Chris Lattner24943d22010-06-08 16:52:24 +0000284void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000285SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner24943d22010-06-08 16:52:24 +0000286{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000287 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000288
289 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000290 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Tice7826c882010-10-26 03:11:13 +0000291
Greg Clayton63094e02010-06-23 01:19:29 +0000292 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000293 {
294 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000295 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonbdcda462010-12-20 20:49:23 +0000296 }
Chris Lattner24943d22010-06-08 16:52:24 +0000297}
298
Jim Inghame3740832010-10-22 01:15:49 +0000299void
300SBBreakpoint::SetCondition (const char *condition)
301{
Greg Claytonbdcda462010-12-20 20:49:23 +0000302 if (m_opaque_sp)
303 {
304 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
305 m_opaque_sp->SetCondition (condition);
306 }
Jim Inghame3740832010-10-22 01:15:49 +0000307}
308
309const char *
310SBBreakpoint::GetCondition ()
311{
Greg Claytonbdcda462010-12-20 20:49:23 +0000312 if (m_opaque_sp)
313 {
314 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
315 return m_opaque_sp->GetConditionText ();
316 }
317 return NULL;
Jim Inghame3740832010-10-22 01:15:49 +0000318}
319
Greg Clayton54e7afa2010-07-09 20:39:50 +0000320uint32_t
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000321SBBreakpoint::GetHitCount () const
322{
Greg Claytona66ba462010-10-30 04:51:46 +0000323 uint32_t count = 0;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000324 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000325 {
326 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000327 count = m_opaque_sp->GetHitCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000328 }
Greg Claytona66ba462010-10-30 04:51:46 +0000329
Greg Clayton952e9dc2013-03-27 23:08:40 +0000330 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000331 if (log)
332 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
333
334 return count;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000335}
336
337uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000338SBBreakpoint::GetIgnoreCount () const
339{
Greg Claytona66ba462010-10-30 04:51:46 +0000340 uint32_t count = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000341 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000342 {
343 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000344 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000345 }
Greg Claytona66ba462010-10-30 04:51:46 +0000346
Greg Clayton952e9dc2013-03-27 23:08:40 +0000347 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000348 if (log)
349 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
350
351 return count;
Chris Lattner24943d22010-06-08 16:52:24 +0000352}
353
354void
Greg Claytona66ba462010-10-30 04:51:46 +0000355SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner24943d22010-06-08 16:52:24 +0000356{
Greg Clayton63094e02010-06-23 01:19:29 +0000357 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000358 {
359 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000360 m_opaque_sp->SetThreadID (tid);
Greg Claytonbdcda462010-12-20 20:49:23 +0000361 }
Greg Clayton952e9dc2013-03-27 23:08:40 +0000362 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000363 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000364 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")", m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000365
Chris Lattner24943d22010-06-08 16:52:24 +0000366}
367
368tid_t
369SBBreakpoint::GetThreadID ()
370{
Greg Claytona66ba462010-10-30 04:51:46 +0000371 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000372 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000373 {
374 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000375 tid = m_opaque_sp->GetThreadID();
Greg Claytonbdcda462010-12-20 20:49:23 +0000376 }
Chris Lattner24943d22010-06-08 16:52:24 +0000377
Greg Clayton952e9dc2013-03-27 23:08:40 +0000378 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000379 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000380 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64, m_opaque_sp.get(), tid);
Greg Claytona66ba462010-10-30 04:51:46 +0000381 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000382}
383
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000384void
385SBBreakpoint::SetThreadIndex (uint32_t index)
386{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000387 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000388 if (log)
389 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton63094e02010-06-23 01:19:29 +0000390 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000391 {
392 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000393 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonbdcda462010-12-20 20:49:23 +0000394 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000395}
396
397uint32_t
398SBBreakpoint::GetThreadIndex() const
399{
Greg Claytona6253872010-12-15 20:50:06 +0000400 uint32_t thread_idx = UINT32_MAX;
Greg Clayton63094e02010-06-23 01:19:29 +0000401 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000402 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000403 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
404 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000405 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000406 thread_idx = thread_spec->GetIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000407 }
Greg Clayton952e9dc2013-03-27 23:08:40 +0000408 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000409 if (log)
Greg Claytona6253872010-12-15 20:50:06 +0000410 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000411
Johnny Chenb3e71812010-12-15 21:39:37 +0000412 return thread_idx;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000413}
414
415
416void
417SBBreakpoint::SetThreadName (const char *thread_name)
418{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000419 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000420 if (log)
421 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
422
Greg Clayton63094e02010-06-23 01:19:29 +0000423 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000424 {
425 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000426 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000427 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000428}
429
430const char *
431SBBreakpoint::GetThreadName () const
432{
Greg Claytona66ba462010-10-30 04:51:46 +0000433 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000434 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000435 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000436 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
437 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000438 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000439 name = thread_spec->GetName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000440 }
Greg Clayton952e9dc2013-03-27 23:08:40 +0000441 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000442 if (log)
443 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
444
445 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000446}
447
448void
449SBBreakpoint::SetQueueName (const char *queue_name)
450{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000451 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000452 if (log)
453 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton63094e02010-06-23 01:19:29 +0000454 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000455 {
456 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000457 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000458 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000459}
460
461const char *
462SBBreakpoint::GetQueueName () const
463{
Greg Claytona66ba462010-10-30 04:51:46 +0000464 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000465 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000466 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000467 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
468 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
469 if (thread_spec)
Greg Claytona66ba462010-10-30 04:51:46 +0000470 name = thread_spec->GetQueueName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000471 }
Greg Clayton952e9dc2013-03-27 23:08:40 +0000472 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000473 if (log)
474 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
475
476 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000477}
478
Chris Lattner24943d22010-06-08 16:52:24 +0000479size_t
480SBBreakpoint::GetNumResolvedLocations() const
481{
Greg Claytona66ba462010-10-30 04:51:46 +0000482 size_t num_resolved = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000483 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000484 {
485 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000486 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000487 }
Greg Clayton952e9dc2013-03-27 23:08:40 +0000488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000489 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000490 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_resolved);
Greg Claytona66ba462010-10-30 04:51:46 +0000491 return num_resolved;
Chris Lattner24943d22010-06-08 16:52:24 +0000492}
493
494size_t
495SBBreakpoint::GetNumLocations() const
496{
Greg Claytona66ba462010-10-30 04:51:46 +0000497 size_t num_locs = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000498 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000499 {
500 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000501 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000502 }
Greg Clayton952e9dc2013-03-27 23:08:40 +0000503 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000504 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000505 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_locs);
Greg Claytona66ba462010-10-30 04:51:46 +0000506 return num_locs;
Chris Lattner24943d22010-06-08 16:52:24 +0000507}
508
Caroline Tice98f930f2010-09-20 05:20:02 +0000509bool
Greg Claytond8c62532010-10-07 04:19:01 +0000510SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner24943d22010-06-08 16:52:24 +0000511{
Greg Clayton63094e02010-06-23 01:19:29 +0000512 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000513 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000514 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytond8c62532010-10-07 04:19:01 +0000515 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
516 m_opaque_sp->GetResolverDescription (s.get());
517 m_opaque_sp->GetFilterDescription (s.get());
518 const size_t num_locations = m_opaque_sp->GetNumLocations ();
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000519 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
Greg Claytond8c62532010-10-07 04:19:01 +0000520 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000521 }
Greg Claytond8c62532010-10-07 04:19:01 +0000522 s.Printf ("No value");
523 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000524}
525
Chris Lattner24943d22010-06-08 16:52:24 +0000526bool
527SBBreakpoint::PrivateBreakpointHitCallback
528(
529 void *baton,
530 StoppointCallbackContext *ctx,
531 lldb::user_id_t break_id,
532 lldb::user_id_t break_loc_id
533)
534{
Greg Claytonf4124de2012-02-21 00:09:25 +0000535 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
536 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000537 if (baton && bp_sp)
538 {
539 CallbackData *data = (CallbackData *)baton;
540 lldb_private::Breakpoint *bp = bp_sp.get();
541 if (bp && data->callback)
542 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000543 Process *process = exe_ctx.GetProcessPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000544 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +0000545 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000546 SBProcess sb_process (process->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000547 SBThread sb_thread;
548 SBBreakpointLocation sb_location;
549 assert (bp_sp);
550 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Claytonf4124de2012-02-21 00:09:25 +0000551 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton567e7f32011-09-22 04:58:26 +0000552 if (thread)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000553 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +0000554
555 return data->callback (data->callback_baton,
556 sb_process,
557 sb_thread,
558 sb_location);
559 }
560 }
561 }
562 return true; // Return true if we should stop at this breakpoint
563}
564
565void
566SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
567{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000568 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000569
570 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000571 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Tice7826c882010-10-26 03:11:13 +0000572
Greg Clayton567e7f32011-09-22 04:58:26 +0000573 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000574 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000575 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000576 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton63094e02010-06-23 01:19:29 +0000577 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000578 }
579}
580
581
582lldb_private::Breakpoint *
583SBBreakpoint::operator->() const
584{
Greg Clayton63094e02010-06-23 01:19:29 +0000585 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000586}
587
588lldb_private::Breakpoint *
589SBBreakpoint::get() const
590{
Greg Clayton63094e02010-06-23 01:19:29 +0000591 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000592}
593
594lldb::BreakpointSP &
595SBBreakpoint::operator *()
596{
Greg Clayton63094e02010-06-23 01:19:29 +0000597 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000598}
599
600const lldb::BreakpointSP &
601SBBreakpoint::operator *() const
602{
Greg Clayton63094e02010-06-23 01:19:29 +0000603 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000604}
605
Jim Ingham28e23862012-02-08 05:23:15 +0000606bool
607SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
608{
609 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
610
611}
612
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000613BreakpointEventType
614SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
615{
616 if (event.IsValid())
617 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
618 return eBreakpointEventTypeInvalidType;
619}
620
621SBBreakpoint
622SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
623{
624 SBBreakpoint sb_breakpoint;
625 if (event.IsValid())
626 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
627 return sb_breakpoint;
628}
629
630SBBreakpointLocation
631SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
632{
633 SBBreakpointLocation sb_breakpoint_loc;
634 if (event.IsValid())
635 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
636 return sb_breakpoint_loc;
637}
638
Jim Ingham28e23862012-02-08 05:23:15 +0000639uint32_t
640SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
641{
642 uint32_t num_locations = 0;
643 if (event.IsValid())
644 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
645 return num_locations;
646}
647
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000648