blob: f2dccf9351940aaf6853bf60de6ec0a075a01efa [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 Clayton63094e02010-06-23 01:19:29 +0000108 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000109 {
Greg Claytona66ba462010-10-30 04:51:46 +0000110 break_id_t break_id = m_opaque_sp->GetID();
Caroline Tice7826c882010-10-26 03:11:13 +0000111 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000112 log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id);
113 return break_id;
Caroline Tice7826c882010-10-26 03:11:13 +0000114 }
115
116 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000117 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000118
Chris Lattner24943d22010-06-08 16:52:24 +0000119 return LLDB_INVALID_BREAK_ID;
120}
121
122
123bool
124SBBreakpoint::IsValid() const
125{
Greg Clayton63094e02010-06-23 01:19:29 +0000126 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000127}
128
129void
Chris Lattner24943d22010-06-08 16:52:24 +0000130SBBreakpoint::ClearAllBreakpointSites ()
131{
Greg Clayton63094e02010-06-23 01:19:29 +0000132 if (m_opaque_sp)
133 m_opaque_sp->ClearAllBreakpointSites ();
Chris Lattner24943d22010-06-08 16:52:24 +0000134}
135
136SBBreakpointLocation
137SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
138{
139 SBBreakpointLocation sb_bp_location;
140
Greg Clayton63094e02010-06-23 01:19:29 +0000141 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000142 {
143 if (vm_addr != LLDB_INVALID_ADDRESS)
144 {
145 Address address;
Greg Claytoneea26402010-09-14 23:36:40 +0000146 Target &target = m_opaque_sp->GetTarget();
147 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000148 {
149 address.SetSection (NULL);
150 address.SetOffset (vm_addr);
151 }
Greg Clayton63094e02010-06-23 01:19:29 +0000152 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner24943d22010-06-08 16:52:24 +0000153 }
154 }
155 return sb_bp_location;
156}
157
158break_id_t
159SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
160{
161 break_id_t lldb_id = (break_id_t) 0;
162
Greg Clayton63094e02010-06-23 01:19:29 +0000163 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000164 {
165 if (vm_addr != LLDB_INVALID_ADDRESS)
166 {
167 Address address;
Greg Claytoneea26402010-09-14 23:36:40 +0000168 Target &target = m_opaque_sp->GetTarget();
169 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000170 {
171 address.SetSection (NULL);
172 address.SetOffset (vm_addr);
173 }
Greg Clayton63094e02010-06-23 01:19:29 +0000174 lldb_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner24943d22010-06-08 16:52:24 +0000175 }
176 }
177
178 return lldb_id;
179}
180
181SBBreakpointLocation
182SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
183{
184 SBBreakpointLocation sb_bp_location;
185
Greg Clayton63094e02010-06-23 01:19:29 +0000186 if (m_opaque_sp)
187 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000188
189 return sb_bp_location;
190}
191
192SBBreakpointLocation
193SBBreakpoint::GetLocationAtIndex (uint32_t index)
194{
195 SBBreakpointLocation sb_bp_location;
196
Greg Clayton63094e02010-06-23 01:19:29 +0000197 if (m_opaque_sp)
198 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Chris Lattner24943d22010-06-08 16:52:24 +0000199
200 return sb_bp_location;
201}
202
203void
Chris Lattner24943d22010-06-08 16:52:24 +0000204SBBreakpoint::SetEnabled (bool enable)
205{
Greg Claytone005f2c2010-11-06 01:53:30 +0000206 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000207
208 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000209 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable);
Caroline Tice7826c882010-10-26 03:11:13 +0000210
Greg Clayton63094e02010-06-23 01:19:29 +0000211 if (m_opaque_sp)
212 m_opaque_sp->SetEnabled (enable);
Chris Lattner24943d22010-06-08 16:52:24 +0000213}
214
215bool
216SBBreakpoint::IsEnabled ()
217{
Greg Clayton63094e02010-06-23 01:19:29 +0000218 if (m_opaque_sp)
219 return m_opaque_sp->IsEnabled();
Chris Lattner24943d22010-06-08 16:52:24 +0000220 else
221 return false;
222}
223
224void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000225SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner24943d22010-06-08 16:52:24 +0000226{
Greg Claytone005f2c2010-11-06 01:53:30 +0000227 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000228
229 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000230 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Tice7826c882010-10-26 03:11:13 +0000231
Greg Clayton63094e02010-06-23 01:19:29 +0000232 if (m_opaque_sp)
233 m_opaque_sp->SetIgnoreCount (count);
Chris Lattner24943d22010-06-08 16:52:24 +0000234}
235
Jim Inghame3740832010-10-22 01:15:49 +0000236void
237SBBreakpoint::SetCondition (const char *condition)
238{
239 m_opaque_sp->SetCondition (condition);
240}
241
242const char *
243SBBreakpoint::GetCondition ()
244{
245 return m_opaque_sp->GetConditionText ();
246}
247
Greg Clayton54e7afa2010-07-09 20:39:50 +0000248uint32_t
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000249SBBreakpoint::GetHitCount () const
250{
Greg Claytona66ba462010-10-30 04:51:46 +0000251 uint32_t count = 0;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000252 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000253 count = m_opaque_sp->GetHitCount();
254
Greg Claytone005f2c2010-11-06 01:53:30 +0000255 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000256 if (log)
257 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
258
259 return count;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000260}
261
262uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000263SBBreakpoint::GetIgnoreCount () const
264{
Greg Claytona66ba462010-10-30 04:51:46 +0000265 uint32_t count = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000266 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000267 count = m_opaque_sp->GetIgnoreCount();
268
Greg Claytone005f2c2010-11-06 01:53:30 +0000269 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000270 if (log)
271 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
272
273 return count;
Chris Lattner24943d22010-06-08 16:52:24 +0000274}
275
276void
Greg Claytona66ba462010-10-30 04:51:46 +0000277SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner24943d22010-06-08 16:52:24 +0000278{
Greg Clayton63094e02010-06-23 01:19:29 +0000279 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000280 m_opaque_sp->SetThreadID (tid);
Greg Claytone005f2c2010-11-06 01:53:30 +0000281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000282 if (log)
283 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4x)", m_opaque_sp.get(), tid);
284
Chris Lattner24943d22010-06-08 16:52:24 +0000285}
286
287tid_t
288SBBreakpoint::GetThreadID ()
289{
Greg Claytona66ba462010-10-30 04:51:46 +0000290 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000291 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000292 tid = m_opaque_sp->GetThreadID();
Chris Lattner24943d22010-06-08 16:52:24 +0000293
Greg Claytone005f2c2010-11-06 01:53:30 +0000294 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000295 if (log)
296 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), tid);
297 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000298}
299
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000300void
301SBBreakpoint::SetThreadIndex (uint32_t index)
302{
Greg Claytone005f2c2010-11-06 01:53:30 +0000303 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000304 if (log)
305 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton63094e02010-06-23 01:19:29 +0000306 if (m_opaque_sp)
307 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000308}
309
310uint32_t
311SBBreakpoint::GetThreadIndex() const
312{
Greg Claytona66ba462010-10-30 04:51:46 +0000313 uint32_t thread_idx = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000314 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000315 {
Greg Clayton63094e02010-06-23 01:19:29 +0000316 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000317 if (thread_spec == NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000318 thread_idx = thread_spec->GetIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000319 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000320 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000321 if (log)
322 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), index);
323
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000324 return 0;
325}
326
327
328void
329SBBreakpoint::SetThreadName (const char *thread_name)
330{
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)
333 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
334
Greg Clayton63094e02010-06-23 01:19:29 +0000335 if (m_opaque_sp)
336 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000337}
338
339const char *
340SBBreakpoint::GetThreadName () const
341{
Greg Claytona66ba462010-10-30 04:51:46 +0000342 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000343 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000344 {
Greg Clayton63094e02010-06-23 01:19:29 +0000345 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000346 if (thread_spec == NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000347 name = thread_spec->GetName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000348 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000349 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000350 if (log)
351 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
352
353 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000354}
355
356void
357SBBreakpoint::SetQueueName (const char *queue_name)
358{
Greg Claytone005f2c2010-11-06 01:53:30 +0000359 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000360 if (log)
361 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton63094e02010-06-23 01:19:29 +0000362 if (m_opaque_sp)
363 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000364}
365
366const char *
367SBBreakpoint::GetQueueName () const
368{
Greg Claytona66ba462010-10-30 04:51:46 +0000369 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000370 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000371 {
Greg Clayton63094e02010-06-23 01:19:29 +0000372 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec();
Greg Claytona66ba462010-10-30 04:51:46 +0000373 name = thread_spec->GetQueueName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000374 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000375 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000376 if (log)
377 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
378
379 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000380}
381
Chris Lattner24943d22010-06-08 16:52:24 +0000382size_t
383SBBreakpoint::GetNumResolvedLocations() const
384{
Greg Claytona66ba462010-10-30 04:51:46 +0000385 size_t num_resolved = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000386 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000387 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytone005f2c2010-11-06 01:53:30 +0000388 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000389 if (log)
390 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %zu", m_opaque_sp.get(), num_resolved);
391 return num_resolved;
Chris Lattner24943d22010-06-08 16:52:24 +0000392}
393
394size_t
395SBBreakpoint::GetNumLocations() const
396{
Greg Claytona66ba462010-10-30 04:51:46 +0000397 size_t num_locs = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000398 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000399 num_locs = m_opaque_sp->GetNumLocations();
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)
402 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %zu", m_opaque_sp.get(), num_locs);
403 return num_locs;
Chris Lattner24943d22010-06-08 16:52:24 +0000404}
405
Caroline Tice98f930f2010-09-20 05:20:02 +0000406bool
Greg Claytond8c62532010-10-07 04:19:01 +0000407SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner24943d22010-06-08 16:52:24 +0000408{
Greg Clayton63094e02010-06-23 01:19:29 +0000409 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000410 {
Greg Claytond8c62532010-10-07 04:19:01 +0000411 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
412 m_opaque_sp->GetResolverDescription (s.get());
413 m_opaque_sp->GetFilterDescription (s.get());
414 const size_t num_locations = m_opaque_sp->GetNumLocations ();
415 s.Printf(", locations = %zu", num_locations);
416 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000417 }
Greg Claytond8c62532010-10-07 04:19:01 +0000418 s.Printf ("No value");
419 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000420}
421
Chris Lattner24943d22010-06-08 16:52:24 +0000422bool
423SBBreakpoint::PrivateBreakpointHitCallback
424(
425 void *baton,
426 StoppointCallbackContext *ctx,
427 lldb::user_id_t break_id,
428 lldb::user_id_t break_loc_id
429)
430{
Greg Clayton63094e02010-06-23 01:19:29 +0000431 BreakpointSP bp_sp(ctx->exe_ctx.target->GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000432 if (baton && bp_sp)
433 {
434 CallbackData *data = (CallbackData *)baton;
435 lldb_private::Breakpoint *bp = bp_sp.get();
436 if (bp && data->callback)
437 {
Greg Clayton63094e02010-06-23 01:19:29 +0000438 if (ctx->exe_ctx.process)
Chris Lattner24943d22010-06-08 16:52:24 +0000439 {
Greg Clayton63094e02010-06-23 01:19:29 +0000440 SBProcess sb_process (ctx->exe_ctx.process->GetSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000441 SBThread sb_thread;
442 SBBreakpointLocation sb_location;
443 assert (bp_sp);
444 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Clayton63094e02010-06-23 01:19:29 +0000445 if (ctx->exe_ctx.thread)
446 sb_thread.SetThread(ctx->exe_ctx.thread->GetSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000447
448 return data->callback (data->callback_baton,
449 sb_process,
450 sb_thread,
451 sb_location);
452 }
453 }
454 }
455 return true; // Return true if we should stop at this breakpoint
456}
457
458void
459SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
460{
Greg Claytone005f2c2010-11-06 01:53:30 +0000461 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000462
463 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000464 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Tice7826c882010-10-26 03:11:13 +0000465
Greg Clayton63094e02010-06-23 01:19:29 +0000466 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000467 {
468 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton63094e02010-06-23 01:19:29 +0000469 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000470 }
471}
472
473
474lldb_private::Breakpoint *
475SBBreakpoint::operator->() const
476{
Greg Clayton63094e02010-06-23 01:19:29 +0000477 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000478}
479
480lldb_private::Breakpoint *
481SBBreakpoint::get() const
482{
Greg Clayton63094e02010-06-23 01:19:29 +0000483 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000484}
485
486lldb::BreakpointSP &
487SBBreakpoint::operator *()
488{
Greg Clayton63094e02010-06-23 01:19:29 +0000489 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000490}
491
492const lldb::BreakpointSP &
493SBBreakpoint::operator *() const
494{
Greg Clayton63094e02010-06-23 01:19:29 +0000495 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000496}
497
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000498BreakpointEventType
499SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
500{
501 if (event.IsValid())
502 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
503 return eBreakpointEventTypeInvalidType;
504}
505
506SBBreakpoint
507SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
508{
509 SBBreakpoint sb_breakpoint;
510 if (event.IsValid())
511 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
512 return sb_breakpoint;
513}
514
515SBBreakpointLocation
516SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
517{
518 SBBreakpointLocation sb_breakpoint_loc;
519 if (event.IsValid())
520 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
521 return sb_breakpoint_loc;
522}
523
524