blob: 9f2e3a1810cf2eab6f29f62e4acadafb93489589 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBBreakpoint.cpp ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBBreakpoint.h"
11#include "lldb/API/SBBreakpointLocation.h"
12#include "lldb/API/SBDebugger.h"
Greg Claytonc7f5d5c2010-07-23 23:33:17 +000013#include "lldb/API/SBEvent.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/API/SBThread.h"
17
18#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
20#include "lldb/Breakpoint/StoppointCallbackContext.h"
21#include "lldb/Core/Address.h"
Caroline Tice7826c882010-10-26 03:11:13 +000022#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Stream.h"
24#include "lldb/Core/StreamFile.h"
25#include "lldb/Target/Process.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Target/Target.h"
Jim Ingham8e5e38f2010-06-18 01:47:08 +000027#include "lldb/Target/Thread.h"
28#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029
30
31#include "lldb/lldb-enumerations.h"
32
33using namespace lldb;
34using namespace lldb_private;
35
36struct CallbackData
37{
38 SBBreakpoint::BreakpointHitCallback callback;
39 void *callback_baton;
40};
41
42class SBBreakpointCallbackBaton : public Baton
43{
44public:
45
46 SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
47 Baton (new CallbackData)
48 {
49 CallbackData *data = (CallbackData *)m_data;
50 data->callback = callback;
51 data->callback_baton = baton;
52 }
53
54 virtual ~SBBreakpointCallbackBaton()
55 {
56 CallbackData *data = (CallbackData *)m_data;
57
58 if (data)
59 {
60 delete data;
61 m_data = NULL;
62 }
63 }
64};
65
66
67SBBreakpoint::SBBreakpoint () :
Greg Clayton63094e02010-06-23 01:19:29 +000068 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000069{
70}
71
72SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000073 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000074{
75}
76
77
78SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000079 m_opaque_sp (bp_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000080{
81}
82
83SBBreakpoint::~SBBreakpoint()
84{
85}
86
87const SBBreakpoint &
88SBBreakpoint::operator = (const SBBreakpoint& rhs)
89{
90 if (this != &rhs)
Greg Clayton63094e02010-06-23 01:19:29 +000091 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000092 return *this;
93}
94
Greg Claytonea49cc72010-12-12 19:25:26 +000095bool
96SBBreakpoint::operator == (const lldb::SBBreakpoint& rhs)
97{
98 if (m_opaque_sp && rhs.m_opaque_sp)
99 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
100 return false;
101}
102
Chris Lattner24943d22010-06-08 16:52:24 +0000103break_id_t
104SBBreakpoint::GetID () const
105{
Greg Claytone005f2c2010-11-06 01:53:30 +0000106 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000107
Greg Claytonbdcda462010-12-20 20:49:23 +0000108 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000109 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000110 break_id = m_opaque_sp->GetID();
Caroline Tice7826c882010-10-26 03:11:13 +0000111
112 if (log)
Greg Claytonbdcda462010-12-20 20:49:23 +0000113 {
114 if (break_id == LLDB_INVALID_BREAK_ID)
115 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get());
116 else
117 log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id);
118 }
Caroline Tice7826c882010-10-26 03:11:13 +0000119
Greg Claytonbdcda462010-12-20 20:49:23 +0000120 return break_id;
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123
124bool
125SBBreakpoint::IsValid() const
126{
Greg Clayton63094e02010-06-23 01:19:29 +0000127 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000128}
129
130void
Chris Lattner24943d22010-06-08 16:52:24 +0000131SBBreakpoint::ClearAllBreakpointSites ()
132{
Greg Clayton63094e02010-06-23 01:19:29 +0000133 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000134 {
135 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000136 m_opaque_sp->ClearAllBreakpointSites ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000137 }
Chris Lattner24943d22010-06-08 16:52:24 +0000138}
139
140SBBreakpointLocation
141SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
142{
143 SBBreakpointLocation sb_bp_location;
144
Greg Clayton63094e02010-06-23 01:19:29 +0000145 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000146 {
147 if (vm_addr != LLDB_INVALID_ADDRESS)
148 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000149 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000150 Address address;
Greg Claytoneea26402010-09-14 23:36:40 +0000151 Target &target = m_opaque_sp->GetTarget();
152 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000153 {
154 address.SetSection (NULL);
155 address.SetOffset (vm_addr);
156 }
Greg Clayton63094e02010-06-23 01:19:29 +0000157 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner24943d22010-06-08 16:52:24 +0000158 }
159 }
160 return sb_bp_location;
161}
162
163break_id_t
164SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
165{
Greg Claytonbdcda462010-12-20 20:49:23 +0000166 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000167
Greg Claytonbdcda462010-12-20 20:49:23 +0000168 if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +0000169 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000170 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
171 Address address;
172 Target &target = m_opaque_sp->GetTarget();
173 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner24943d22010-06-08 16:52:24 +0000174 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000175 address.SetSection (NULL);
176 address.SetOffset (vm_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000177 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000178 break_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner24943d22010-06-08 16:52:24 +0000179 }
180
Greg Claytonbdcda462010-12-20 20:49:23 +0000181 return break_id;
Chris Lattner24943d22010-06-08 16:52:24 +0000182}
183
184SBBreakpointLocation
185SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
186{
187 SBBreakpointLocation sb_bp_location;
188
Greg Clayton63094e02010-06-23 01:19:29 +0000189 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000190 {
191 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000192 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Greg Claytonbdcda462010-12-20 20:49:23 +0000193 }
Chris Lattner24943d22010-06-08 16:52:24 +0000194
195 return sb_bp_location;
196}
197
198SBBreakpointLocation
199SBBreakpoint::GetLocationAtIndex (uint32_t index)
200{
201 SBBreakpointLocation sb_bp_location;
202
Greg Clayton63094e02010-06-23 01:19:29 +0000203 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000204 {
205 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000206 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Greg Claytonbdcda462010-12-20 20:49:23 +0000207 }
Chris Lattner24943d22010-06-08 16:52:24 +0000208
209 return sb_bp_location;
210}
211
212void
Chris Lattner24943d22010-06-08 16:52:24 +0000213SBBreakpoint::SetEnabled (bool enable)
214{
Greg Claytone005f2c2010-11-06 01:53:30 +0000215 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000216
217 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000218 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable);
Caroline Tice7826c882010-10-26 03:11:13 +0000219
Greg Clayton63094e02010-06-23 01:19:29 +0000220 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000221 {
222 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000223 m_opaque_sp->SetEnabled (enable);
Greg Claytonbdcda462010-12-20 20:49:23 +0000224 }
Chris Lattner24943d22010-06-08 16:52:24 +0000225}
226
227bool
228SBBreakpoint::IsEnabled ()
229{
Greg Clayton63094e02010-06-23 01:19:29 +0000230 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000231 {
232 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000233 return m_opaque_sp->IsEnabled();
Greg Claytonbdcda462010-12-20 20:49:23 +0000234 }
Chris Lattner24943d22010-06-08 16:52:24 +0000235 else
236 return false;
237}
238
239void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000240SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner24943d22010-06-08 16:52:24 +0000241{
Greg Claytone005f2c2010-11-06 01:53:30 +0000242 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000243
244 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000245 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count);
Caroline Tice7826c882010-10-26 03:11:13 +0000246
Greg Clayton63094e02010-06-23 01:19:29 +0000247 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000248 {
249 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000250 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonbdcda462010-12-20 20:49:23 +0000251 }
Chris Lattner24943d22010-06-08 16:52:24 +0000252}
253
Jim Inghame3740832010-10-22 01:15:49 +0000254void
255SBBreakpoint::SetCondition (const char *condition)
256{
Greg Claytonbdcda462010-12-20 20:49:23 +0000257 if (m_opaque_sp)
258 {
259 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
260 m_opaque_sp->SetCondition (condition);
261 }
Jim Inghame3740832010-10-22 01:15:49 +0000262}
263
264const char *
265SBBreakpoint::GetCondition ()
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 return m_opaque_sp->GetConditionText ();
271 }
272 return NULL;
Jim Inghame3740832010-10-22 01:15:49 +0000273}
274
Greg Clayton54e7afa2010-07-09 20:39:50 +0000275uint32_t
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000276SBBreakpoint::GetHitCount () const
277{
Greg Claytona66ba462010-10-30 04:51:46 +0000278 uint32_t count = 0;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000279 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000280 {
281 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000282 count = m_opaque_sp->GetHitCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000283 }
Greg Claytona66ba462010-10-30 04:51:46 +0000284
Greg Claytone005f2c2010-11-06 01:53:30 +0000285 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000286 if (log)
287 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count);
288
289 return count;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000290}
291
292uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000293SBBreakpoint::GetIgnoreCount () const
294{
Greg Claytona66ba462010-10-30 04:51:46 +0000295 uint32_t count = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000296 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000297 {
298 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000299 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000300 }
Greg Claytona66ba462010-10-30 04:51:46 +0000301
Greg Claytone005f2c2010-11-06 01:53:30 +0000302 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000303 if (log)
304 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", m_opaque_sp.get(), count);
305
306 return count;
Chris Lattner24943d22010-06-08 16:52:24 +0000307}
308
309void
Greg Claytona66ba462010-10-30 04:51:46 +0000310SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner24943d22010-06-08 16:52:24 +0000311{
Greg Clayton63094e02010-06-23 01:19:29 +0000312 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000313 {
314 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000315 m_opaque_sp->SetThreadID (tid);
Greg Claytonbdcda462010-12-20 20:49:23 +0000316 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000317 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000318 if (log)
319 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4x)", m_opaque_sp.get(), tid);
320
Chris Lattner24943d22010-06-08 16:52:24 +0000321}
322
323tid_t
324SBBreakpoint::GetThreadID ()
325{
Greg Claytona66ba462010-10-30 04:51:46 +0000326 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000327 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000328 {
329 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000330 tid = m_opaque_sp->GetThreadID();
Greg Claytonbdcda462010-12-20 20:49:23 +0000331 }
Chris Lattner24943d22010-06-08 16:52:24 +0000332
Greg Claytone005f2c2010-11-06 01:53:30 +0000333 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000334 if (log)
335 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), tid);
336 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000337}
338
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000339void
340SBBreakpoint::SetThreadIndex (uint32_t index)
341{
Greg Claytone005f2c2010-11-06 01:53:30 +0000342 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000343 if (log)
344 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index);
Greg Clayton63094e02010-06-23 01:19:29 +0000345 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000346 {
347 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000348 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonbdcda462010-12-20 20:49:23 +0000349 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000350}
351
352uint32_t
353SBBreakpoint::GetThreadIndex() const
354{
Greg Claytona6253872010-12-15 20:50:06 +0000355 uint32_t thread_idx = UINT32_MAX;
Greg Clayton63094e02010-06-23 01:19:29 +0000356 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000357 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000358 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
359 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000360 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000361 thread_idx = thread_spec->GetIndex();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000362 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000363 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000364 if (log)
Greg Claytona6253872010-12-15 20:50:06 +0000365 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", m_opaque_sp.get(), thread_idx);
Greg Claytona66ba462010-10-30 04:51:46 +0000366
Johnny Chenb3e71812010-12-15 21:39:37 +0000367 return thread_idx;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000368}
369
370
371void
372SBBreakpoint::SetThreadName (const char *thread_name)
373{
Greg Claytone005f2c2010-11-06 01:53:30 +0000374 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000375 if (log)
376 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name);
377
Greg Clayton63094e02010-06-23 01:19:29 +0000378 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000379 {
380 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000381 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000382 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000383}
384
385const char *
386SBBreakpoint::GetThreadName () const
387{
Greg Claytona66ba462010-10-30 04:51:46 +0000388 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000389 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000390 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000391 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
392 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chenb3e71812010-12-15 21:39:37 +0000393 if (thread_spec != NULL)
Greg Claytona66ba462010-10-30 04:51:46 +0000394 name = thread_spec->GetName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000395 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000396 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000397 if (log)
398 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", m_opaque_sp.get(), name);
399
400 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000401}
402
403void
404SBBreakpoint::SetQueueName (const char *queue_name)
405{
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)::SetQueueName (%s)", m_opaque_sp.get(), queue_name);
Greg Clayton63094e02010-06-23 01:19:29 +0000409 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000410 {
411 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000412 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonbdcda462010-12-20 20:49:23 +0000413 }
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000414}
415
416const char *
417SBBreakpoint::GetQueueName () const
418{
Greg Claytona66ba462010-10-30 04:51:46 +0000419 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000420 if (m_opaque_sp)
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000421 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000422 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
423 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
424 if (thread_spec)
Greg Claytona66ba462010-10-30 04:51:46 +0000425 name = thread_spec->GetQueueName();
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000426 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000427 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000428 if (log)
429 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", m_opaque_sp.get(), name);
430
431 return name;
Jim Ingham8e5e38f2010-06-18 01:47:08 +0000432}
433
Chris Lattner24943d22010-06-08 16:52:24 +0000434size_t
435SBBreakpoint::GetNumResolvedLocations() const
436{
Greg Claytona66ba462010-10-30 04:51:46 +0000437 size_t num_resolved = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000438 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000439 {
440 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000441 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000442 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000443 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000444 if (log)
445 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %zu", m_opaque_sp.get(), num_resolved);
446 return num_resolved;
Chris Lattner24943d22010-06-08 16:52:24 +0000447}
448
449size_t
450SBBreakpoint::GetNumLocations() const
451{
Greg Claytona66ba462010-10-30 04:51:46 +0000452 size_t num_locs = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000453 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000454 {
455 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000456 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonbdcda462010-12-20 20:49:23 +0000457 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000458 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000459 if (log)
460 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %zu", m_opaque_sp.get(), num_locs);
461 return num_locs;
Chris Lattner24943d22010-06-08 16:52:24 +0000462}
463
Caroline Tice98f930f2010-09-20 05:20:02 +0000464bool
Greg Claytond8c62532010-10-07 04:19:01 +0000465SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner24943d22010-06-08 16:52:24 +0000466{
Greg Clayton63094e02010-06-23 01:19:29 +0000467 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000468 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000469 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Claytond8c62532010-10-07 04:19:01 +0000470 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
471 m_opaque_sp->GetResolverDescription (s.get());
472 m_opaque_sp->GetFilterDescription (s.get());
473 const size_t num_locations = m_opaque_sp->GetNumLocations ();
474 s.Printf(", locations = %zu", num_locations);
475 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000476 }
Greg Claytond8c62532010-10-07 04:19:01 +0000477 s.Printf ("No value");
478 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000479}
480
Chris Lattner24943d22010-06-08 16:52:24 +0000481bool
482SBBreakpoint::PrivateBreakpointHitCallback
483(
484 void *baton,
485 StoppointCallbackContext *ctx,
486 lldb::user_id_t break_id,
487 lldb::user_id_t break_loc_id
488)
489{
Greg Clayton63094e02010-06-23 01:19:29 +0000490 BreakpointSP bp_sp(ctx->exe_ctx.target->GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner24943d22010-06-08 16:52:24 +0000491 if (baton && bp_sp)
492 {
493 CallbackData *data = (CallbackData *)baton;
494 lldb_private::Breakpoint *bp = bp_sp.get();
495 if (bp && data->callback)
496 {
Greg Clayton63094e02010-06-23 01:19:29 +0000497 if (ctx->exe_ctx.process)
Chris Lattner24943d22010-06-08 16:52:24 +0000498 {
Greg Clayton63094e02010-06-23 01:19:29 +0000499 SBProcess sb_process (ctx->exe_ctx.process->GetSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000500 SBThread sb_thread;
501 SBBreakpointLocation sb_location;
502 assert (bp_sp);
503 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Clayton63094e02010-06-23 01:19:29 +0000504 if (ctx->exe_ctx.thread)
505 sb_thread.SetThread(ctx->exe_ctx.thread->GetSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000506
507 return data->callback (data->callback_baton,
508 sb_process,
509 sb_thread,
510 sb_location);
511 }
512 }
513 }
514 return true; // Return true if we should stop at this breakpoint
515}
516
517void
518SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
519{
Greg Claytone005f2c2010-11-06 01:53:30 +0000520 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000521
522 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000523 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", m_opaque_sp.get(), callback, baton);
Caroline Tice7826c882010-10-26 03:11:13 +0000524
Greg Clayton63094e02010-06-23 01:19:29 +0000525 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000526 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000527 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000528 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton63094e02010-06-23 01:19:29 +0000529 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000530 }
531}
532
533
534lldb_private::Breakpoint *
535SBBreakpoint::operator->() const
536{
Greg Clayton63094e02010-06-23 01:19:29 +0000537 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000538}
539
540lldb_private::Breakpoint *
541SBBreakpoint::get() const
542{
Greg Clayton63094e02010-06-23 01:19:29 +0000543 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000544}
545
546lldb::BreakpointSP &
547SBBreakpoint::operator *()
548{
Greg Clayton63094e02010-06-23 01:19:29 +0000549 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000550}
551
552const lldb::BreakpointSP &
553SBBreakpoint::operator *() const
554{
Greg Clayton63094e02010-06-23 01:19:29 +0000555 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000556}
557
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000558BreakpointEventType
559SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
560{
561 if (event.IsValid())
562 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
563 return eBreakpointEventTypeInvalidType;
564}
565
566SBBreakpoint
567SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
568{
569 SBBreakpoint sb_breakpoint;
570 if (event.IsValid())
571 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
572 return sb_breakpoint;
573}
574
575SBBreakpointLocation
576SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
577{
578 SBBreakpointLocation sb_breakpoint_loc;
579 if (event.IsValid())
580 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
581 return sb_breakpoint_loc;
582}
583
584