blob: fbdc0e32f4982fe1c21afa6c7374701705d70413 [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Clayton9fed0d82010-07-23 23:33:17 +000013#include "lldb/API/SBEvent.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-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 Ticeceb6b132010-10-26 03:11:13 +000022#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Stream.h"
24#include "lldb/Core/StreamFile.h"
25#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000026#include "lldb/Target/SectionLoadList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000028#include "lldb/Target/Thread.h"
29#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
31
32#include "lldb/lldb-enumerations.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
37struct CallbackData
38{
39 SBBreakpoint::BreakpointHitCallback callback;
40 void *callback_baton;
41};
42
43class SBBreakpointCallbackBaton : public Baton
44{
45public:
46
47 SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
48 Baton (new CallbackData)
49 {
50 CallbackData *data = (CallbackData *)m_data;
51 data->callback = callback;
52 data->callback_baton = baton;
53 }
54
55 virtual ~SBBreakpointCallbackBaton()
56 {
57 CallbackData *data = (CallbackData *)m_data;
58
59 if (data)
60 {
61 delete data;
62 m_data = NULL;
63 }
64 }
65};
66
67
68SBBreakpoint::SBBreakpoint () :
Greg Clayton66111032010-06-23 01:19:29 +000069 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070{
71}
72
73SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000074 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075{
76}
77
78
79SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
Greg Clayton66111032010-06-23 01:19:29 +000080 m_opaque_sp (bp_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081{
82}
83
84SBBreakpoint::~SBBreakpoint()
85{
86}
87
88const SBBreakpoint &
89SBBreakpoint::operator = (const SBBreakpoint& rhs)
90{
91 if (this != &rhs)
Greg Clayton66111032010-06-23 01:19:29 +000092 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093 return *this;
94}
95
Greg Claytonac2eb9b2010-12-12 19:25:26 +000096bool
97SBBreakpoint::operator == (const lldb::SBBreakpoint& rhs)
98{
99 if (m_opaque_sp && rhs.m_opaque_sp)
100 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
101 return false;
102}
103
Enrico Granatac3387332013-05-03 01:29:27 +0000104bool
105SBBreakpoint::operator != (const lldb::SBBreakpoint& rhs)
106{
107 if (m_opaque_sp && rhs.m_opaque_sp)
108 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
109 return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp);
110}
111
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112break_id_t
113SBBreakpoint::GetID () const
114{
Greg Clayton5160ce52013-03-27 23:08:40 +0000115 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000116
Greg Claytonaf67cec2010-12-20 20:49:23 +0000117 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000118 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000119 break_id = m_opaque_sp->GetID();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000120
121 if (log)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000122 {
123 if (break_id == LLDB_INVALID_BREAK_ID)
124 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get());
125 else
126 log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id);
127 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000128
Greg Claytonaf67cec2010-12-20 20:49:23 +0000129 return break_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130}
131
132
133bool
134SBBreakpoint::IsValid() const
135{
Jim Inghamf94e1792012-08-11 00:35:26 +0000136 return (bool) m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137}
138
139void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140SBBreakpoint::ClearAllBreakpointSites ()
141{
Greg Clayton66111032010-06-23 01:19:29 +0000142 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000143 {
144 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000145 m_opaque_sp->ClearAllBreakpointSites ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000146 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147}
148
149SBBreakpointLocation
150SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
151{
152 SBBreakpointLocation sb_bp_location;
153
Greg Clayton66111032010-06-23 01:19:29 +0000154 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155 {
156 if (vm_addr != LLDB_INVALID_ADDRESS)
157 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000158 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159 Address address;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000160 Target &target = m_opaque_sp->GetTarget();
161 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000163 address.SetRawAddress (vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164 }
Greg Clayton66111032010-06-23 01:19:29 +0000165 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166 }
167 }
168 return sb_bp_location;
169}
170
171break_id_t
172SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
173{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000174 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175
Greg Claytonaf67cec2010-12-20 20:49:23 +0000176 if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000178 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
179 Address address;
180 Target &target = m_opaque_sp->GetTarget();
181 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000183 address.SetRawAddress (vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000185 break_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 }
187
Greg Claytonaf67cec2010-12-20 20:49:23 +0000188 return break_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
191SBBreakpointLocation
192SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
193{
194 SBBreakpointLocation sb_bp_location;
195
Greg Clayton66111032010-06-23 01:19:29 +0000196 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000197 {
198 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000199 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201
202 return sb_bp_location;
203}
204
205SBBreakpointLocation
206SBBreakpoint::GetLocationAtIndex (uint32_t index)
207{
208 SBBreakpointLocation sb_bp_location;
209
Greg Clayton66111032010-06-23 01:19:29 +0000210 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000211 {
212 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000213 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000214 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215
216 return sb_bp_location;
217}
218
219void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220SBBreakpoint::SetEnabled (bool enable)
221{
Greg Clayton5160ce52013-03-27 23:08:40 +0000222 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000223
224 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000225 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000226
Greg Clayton66111032010-06-23 01:19:29 +0000227 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000228 {
229 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000230 m_opaque_sp->SetEnabled (enable);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000231 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232}
233
234bool
235SBBreakpoint::IsEnabled ()
236{
Greg Clayton66111032010-06-23 01:19:29 +0000237 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000238 {
239 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000240 return m_opaque_sp->IsEnabled();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000241 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242 else
243 return false;
244}
245
Jim Inghamca36cd12012-10-05 19:16:31 +0000246void
247SBBreakpoint::SetOneShot (bool one_shot)
248{
Greg Clayton5160ce52013-03-27 23:08:40 +0000249 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamca36cd12012-10-05 19:16:31 +0000250
251 if (log)
252 log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)", m_opaque_sp.get(), one_shot);
253
254 if (m_opaque_sp)
255 {
256 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
257 m_opaque_sp->SetOneShot (one_shot);
258 }
259}
260
261bool
262SBBreakpoint::IsOneShot () const
263{
264 if (m_opaque_sp)
265 {
266 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
267 return m_opaque_sp->IsOneShot();
268 }
269 else
270 return false;
271}
272
Jim Ingham11c81082012-09-25 23:55:19 +0000273bool
274SBBreakpoint::IsInternal ()
275{
276 if (m_opaque_sp)
277 {
278 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
279 return m_opaque_sp->IsInternal();
280 }
281 else
282 return false;
283}
284
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285void
Greg Claytonc982c762010-07-09 20:39:50 +0000286SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287{
Greg Clayton5160ce52013-03-27 23:08:40 +0000288 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000289
290 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000291 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000292
Greg Clayton66111032010-06-23 01:19:29 +0000293 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000294 {
295 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000296 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000297 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298}
299
Jim Ingham041a12f2010-10-22 01:15:49 +0000300void
301SBBreakpoint::SetCondition (const char *condition)
302{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000303 if (m_opaque_sp)
304 {
305 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
306 m_opaque_sp->SetCondition (condition);
307 }
Jim Ingham041a12f2010-10-22 01:15:49 +0000308}
309
310const char *
311SBBreakpoint::GetCondition ()
312{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000313 if (m_opaque_sp)
314 {
315 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
316 return m_opaque_sp->GetConditionText ();
317 }
318 return NULL;
Jim Ingham041a12f2010-10-22 01:15:49 +0000319}
320
Greg Claytonc982c762010-07-09 20:39:50 +0000321uint32_t
Greg Clayton9fed0d82010-07-23 23:33:17 +0000322SBBreakpoint::GetHitCount () const
323{
Greg Clayton48381312010-10-30 04:51:46 +0000324 uint32_t count = 0;
Greg Clayton9fed0d82010-07-23 23:33:17 +0000325 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000326 {
327 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000328 count = m_opaque_sp->GetHitCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000329 }
Greg Clayton48381312010-10-30 04:51:46 +0000330
Greg Clayton5160ce52013-03-27 23:08:40 +0000331 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000332 if (log)
333 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
334
335 return count;
Greg Clayton9fed0d82010-07-23 23:33:17 +0000336}
337
338uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000339SBBreakpoint::GetIgnoreCount () const
340{
Greg Clayton48381312010-10-30 04:51:46 +0000341 uint32_t count = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000342 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000343 {
344 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000345 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000346 }
Greg Clayton48381312010-10-30 04:51:46 +0000347
Greg Clayton5160ce52013-03-27 23:08:40 +0000348 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000349 if (log)
350 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
351
352 return count;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353}
354
355void
Greg Clayton48381312010-10-30 04:51:46 +0000356SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357{
Greg Clayton66111032010-06-23 01:19:29 +0000358 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000359 {
360 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000361 m_opaque_sp->SetThreadID (tid);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000362 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000363 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000364 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000365 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")", m_opaque_sp.get(), tid);
Greg Clayton48381312010-10-30 04:51:46 +0000366
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367}
368
369tid_t
370SBBreakpoint::GetThreadID ()
371{
Greg Clayton48381312010-10-30 04:51:46 +0000372 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000373 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000374 {
375 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000376 tid = m_opaque_sp->GetThreadID();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000377 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
Greg Clayton5160ce52013-03-27 23:08:40 +0000379 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000380 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000381 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64, m_opaque_sp.get(), tid);
Greg Clayton48381312010-10-30 04:51:46 +0000382 return tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383}
384
Jim Ingham62b02c62010-06-18 01:47:08 +0000385void
386SBBreakpoint::SetThreadIndex (uint32_t index)
387{
Greg Clayton5160ce52013-03-27 23:08:40 +0000388 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000389 if (log)
390 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton66111032010-06-23 01:19:29 +0000391 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000392 {
393 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000394 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000395 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000396}
397
398uint32_t
399SBBreakpoint::GetThreadIndex() const
400{
Greg Claytonbdf4c6a2010-12-15 20:50:06 +0000401 uint32_t thread_idx = UINT32_MAX;
Greg Clayton66111032010-06-23 01:19:29 +0000402 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000403 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000404 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
405 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chen763d1a12010-12-15 21:39:37 +0000406 if (thread_spec != NULL)
Greg Clayton48381312010-10-30 04:51:46 +0000407 thread_idx = thread_spec->GetIndex();
Jim Ingham62b02c62010-06-18 01:47:08 +0000408 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000409 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000410 if (log)
Greg Claytonbdf4c6a2010-12-15 20:50:06 +0000411 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000412
Johnny Chen763d1a12010-12-15 21:39:37 +0000413 return thread_idx;
Jim Ingham62b02c62010-06-18 01:47:08 +0000414}
415
416
417void
418SBBreakpoint::SetThreadName (const char *thread_name)
419{
Greg Clayton5160ce52013-03-27 23:08:40 +0000420 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000421 if (log)
422 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
423
Greg Clayton66111032010-06-23 01:19:29 +0000424 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000425 {
426 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000427 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000428 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000429}
430
431const char *
432SBBreakpoint::GetThreadName () const
433{
Greg Clayton48381312010-10-30 04:51:46 +0000434 const char *name = NULL;
Greg Clayton66111032010-06-23 01:19:29 +0000435 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000436 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000437 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
438 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chen763d1a12010-12-15 21:39:37 +0000439 if (thread_spec != NULL)
Greg Clayton48381312010-10-30 04:51:46 +0000440 name = thread_spec->GetName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000441 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000442 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000443 if (log)
444 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
445
446 return name;
Jim Ingham62b02c62010-06-18 01:47:08 +0000447}
448
449void
450SBBreakpoint::SetQueueName (const char *queue_name)
451{
Greg Clayton5160ce52013-03-27 23:08:40 +0000452 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000453 if (log)
454 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton66111032010-06-23 01:19:29 +0000455 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000456 {
457 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000458 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000459 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000460}
461
462const char *
463SBBreakpoint::GetQueueName () const
464{
Greg Clayton48381312010-10-30 04:51:46 +0000465 const char *name = NULL;
Greg Clayton66111032010-06-23 01:19:29 +0000466 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000467 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000468 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
469 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
470 if (thread_spec)
Greg Clayton48381312010-10-30 04:51:46 +0000471 name = thread_spec->GetQueueName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000472 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000473 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000474 if (log)
475 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
476
477 return name;
Jim Ingham62b02c62010-06-18 01:47:08 +0000478}
479
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480size_t
481SBBreakpoint::GetNumResolvedLocations() const
482{
Greg Clayton48381312010-10-30 04:51:46 +0000483 size_t num_resolved = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000484 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000485 {
486 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000487 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000488 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000489 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000490 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000491 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_resolved);
Greg Clayton48381312010-10-30 04:51:46 +0000492 return num_resolved;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
495size_t
496SBBreakpoint::GetNumLocations() const
497{
Greg Clayton48381312010-10-30 04:51:46 +0000498 size_t num_locs = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000499 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000500 {
501 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000502 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000503 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000504 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000505 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000506 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64, m_opaque_sp.get(), (uint64_t)num_locs);
Greg Clayton48381312010-10-30 04:51:46 +0000507 return num_locs;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508}
509
Caroline Ticedde9cff2010-09-20 05:20:02 +0000510bool
Greg Clayton05faeb72010-10-07 04:19:01 +0000511SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512{
Greg Clayton66111032010-06-23 01:19:29 +0000513 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000515 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton05faeb72010-10-07 04:19:01 +0000516 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
517 m_opaque_sp->GetResolverDescription (s.get());
518 m_opaque_sp->GetFilterDescription (s.get());
519 const size_t num_locations = m_opaque_sp->GetNumLocations ();
Daniel Malead01b2952012-11-29 21:49:15 +0000520 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
Greg Clayton05faeb72010-10-07 04:19:01 +0000521 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 }
Greg Clayton05faeb72010-10-07 04:19:01 +0000523 s.Printf ("No value");
524 return false;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000525}
526
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527bool
528SBBreakpoint::PrivateBreakpointHitCallback
529(
530 void *baton,
531 StoppointCallbackContext *ctx,
532 lldb::user_id_t break_id,
533 lldb::user_id_t break_loc_id
534)
535{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000536 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
537 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 if (baton && bp_sp)
539 {
540 CallbackData *data = (CallbackData *)baton;
541 lldb_private::Breakpoint *bp = bp_sp.get();
542 if (bp && data->callback)
543 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000544 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonc14ee322011-09-22 04:58:26 +0000545 if (process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000547 SBProcess sb_process (process->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 SBThread sb_thread;
549 SBBreakpointLocation sb_location;
550 assert (bp_sp);
551 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Clayton1ac04c32012-02-21 00:09:25 +0000552 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonc14ee322011-09-22 04:58:26 +0000553 if (thread)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000554 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555
556 return data->callback (data->callback_baton,
557 sb_process,
558 sb_thread,
559 sb_location);
560 }
561 }
562 }
563 return true; // Return true if we should stop at this breakpoint
564}
565
566void
567SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
568{
Greg Clayton5160ce52013-03-27 23:08:40 +0000569 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000570
571 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000572 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000573
Greg Claytonc14ee322011-09-22 04:58:26 +0000574 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000576 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000578 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579 }
580}
581
582
583lldb_private::Breakpoint *
584SBBreakpoint::operator->() const
585{
Greg Clayton66111032010-06-23 01:19:29 +0000586 return m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
588
589lldb_private::Breakpoint *
590SBBreakpoint::get() const
591{
Greg Clayton66111032010-06-23 01:19:29 +0000592 return m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593}
594
595lldb::BreakpointSP &
596SBBreakpoint::operator *()
597{
Greg Clayton66111032010-06-23 01:19:29 +0000598 return m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599}
600
601const lldb::BreakpointSP &
602SBBreakpoint::operator *() const
603{
Greg Clayton66111032010-06-23 01:19:29 +0000604 return m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605}
606
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000607bool
608SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
609{
610 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
611
612}
613
Greg Clayton9fed0d82010-07-23 23:33:17 +0000614BreakpointEventType
615SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
616{
617 if (event.IsValid())
618 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
619 return eBreakpointEventTypeInvalidType;
620}
621
622SBBreakpoint
623SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
624{
625 SBBreakpoint sb_breakpoint;
626 if (event.IsValid())
627 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
628 return sb_breakpoint;
629}
630
631SBBreakpointLocation
632SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
633{
634 SBBreakpointLocation sb_breakpoint_loc;
635 if (event.IsValid())
636 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
637 return sb_breakpoint_loc;
638}
639
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000640uint32_t
641SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
642{
643 uint32_t num_locations = 0;
644 if (event.IsValid())
645 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
646 return num_locations;
647}
648
Greg Clayton9fed0d82010-07-23 23:33:17 +0000649