blob: dd4c80caf45d5a1de55a588f1b3f2f904693facc [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"
Jim Ingham5e09c8c2014-12-16 23:40:14 +000016#include "lldb/API/SBStringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/API/SBThread.h"
18
19#include "lldb/Breakpoint/Breakpoint.h"
20#include "lldb/Breakpoint/BreakpointLocation.h"
21#include "lldb/Breakpoint/StoppointCallbackContext.h"
22#include "lldb/Core/Address.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000023#include "lldb/Core/Debugger.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Stream.h"
26#include "lldb/Core/StreamFile.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000027#include "lldb/Interpreter/CommandInterpreter.h"
28#include "lldb/Interpreter/ScriptInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000030#include "lldb/Target/SectionLoadList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000032#include "lldb/Target/Thread.h"
33#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
35
36#include "lldb/lldb-enumerations.h"
37
38using namespace lldb;
39using namespace lldb_private;
40
41struct CallbackData
42{
43 SBBreakpoint::BreakpointHitCallback callback;
44 void *callback_baton;
45};
46
47class SBBreakpointCallbackBaton : public Baton
48{
49public:
50
51 SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
52 Baton (new CallbackData)
53 {
54 CallbackData *data = (CallbackData *)m_data;
55 data->callback = callback;
56 data->callback_baton = baton;
57 }
58
59 virtual ~SBBreakpointCallbackBaton()
60 {
61 CallbackData *data = (CallbackData *)m_data;
62
63 if (data)
64 {
65 delete data;
66 m_data = NULL;
67 }
68 }
69};
70
71
72SBBreakpoint::SBBreakpoint () :
Greg Clayton66111032010-06-23 01:19:29 +000073 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074{
75}
76
77SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000078 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079{
80}
81
82
83SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
Greg Clayton66111032010-06-23 01:19:29 +000084 m_opaque_sp (bp_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085{
86}
87
88SBBreakpoint::~SBBreakpoint()
89{
90}
91
92const SBBreakpoint &
93SBBreakpoint::operator = (const SBBreakpoint& rhs)
94{
95 if (this != &rhs)
Greg Clayton66111032010-06-23 01:19:29 +000096 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097 return *this;
98}
99
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000100bool
101SBBreakpoint::operator == (const lldb::SBBreakpoint& rhs)
102{
103 if (m_opaque_sp && rhs.m_opaque_sp)
104 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
105 return false;
106}
107
Enrico Granatac3387332013-05-03 01:29:27 +0000108bool
109SBBreakpoint::operator != (const lldb::SBBreakpoint& rhs)
110{
111 if (m_opaque_sp && rhs.m_opaque_sp)
112 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
113 return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp);
114}
115
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116break_id_t
117SBBreakpoint::GetID () const
118{
Greg Clayton5160ce52013-03-27 23:08:40 +0000119 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000120
Greg Claytonaf67cec2010-12-20 20:49:23 +0000121 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000122 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000123 break_id = m_opaque_sp->GetID();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000124
125 if (log)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000126 {
127 if (break_id == LLDB_INVALID_BREAK_ID)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000128 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID",
129 static_cast<void*>(m_opaque_sp.get()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000130 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000131 log->Printf ("SBBreakpoint(%p)::GetID () => %u",
132 static_cast<void*>(m_opaque_sp.get()), break_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000133 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000134
Greg Claytonaf67cec2010-12-20 20:49:23 +0000135 return break_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136}
137
138
139bool
140SBBreakpoint::IsValid() const
141{
Jim Inghame029fa52014-07-02 18:44:43 +0000142 if (!m_opaque_sp)
143 return false;
144 else if (m_opaque_sp->GetTarget().GetBreakpointByID(m_opaque_sp->GetID()))
145 return true;
146 else
147 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148}
149
150void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151SBBreakpoint::ClearAllBreakpointSites ()
152{
Greg Clayton66111032010-06-23 01:19:29 +0000153 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000154 {
155 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000156 m_opaque_sp->ClearAllBreakpointSites ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000157 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158}
159
160SBBreakpointLocation
161SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
162{
163 SBBreakpointLocation sb_bp_location;
164
Greg Clayton66111032010-06-23 01:19:29 +0000165 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166 {
167 if (vm_addr != LLDB_INVALID_ADDRESS)
168 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000169 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170 Address address;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000171 Target &target = m_opaque_sp->GetTarget();
172 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000174 address.SetRawAddress (vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175 }
Greg Clayton66111032010-06-23 01:19:29 +0000176 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177 }
178 }
179 return sb_bp_location;
180}
181
182break_id_t
183SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
184{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000185 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186
Greg Claytonaf67cec2010-12-20 20:49:23 +0000187 if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000189 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
190 Address address;
191 Target &target = m_opaque_sp->GetTarget();
192 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000194 address.SetRawAddress (vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000196 break_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 }
198
Greg Claytonaf67cec2010-12-20 20:49:23 +0000199 return break_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200}
201
202SBBreakpointLocation
203SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
204{
205 SBBreakpointLocation sb_bp_location;
206
Greg Clayton66111032010-06-23 01:19:29 +0000207 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000208 {
209 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000210 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000211 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212
213 return sb_bp_location;
214}
215
216SBBreakpointLocation
217SBBreakpoint::GetLocationAtIndex (uint32_t index)
218{
219 SBBreakpointLocation sb_bp_location;
220
Greg Clayton66111032010-06-23 01:19:29 +0000221 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000222 {
223 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000224 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000225 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226
227 return sb_bp_location;
228}
229
230void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231SBBreakpoint::SetEnabled (bool enable)
232{
Greg Clayton5160ce52013-03-27 23:08:40 +0000233 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000234
235 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000236 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)",
237 static_cast<void*>(m_opaque_sp.get()), enable);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000238
Greg Clayton66111032010-06-23 01:19:29 +0000239 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000240 {
241 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000242 m_opaque_sp->SetEnabled (enable);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000243 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244}
245
246bool
247SBBreakpoint::IsEnabled ()
248{
Greg Clayton66111032010-06-23 01:19:29 +0000249 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000250 {
251 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000252 return m_opaque_sp->IsEnabled();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000253 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254 else
255 return false;
256}
257
Jim Inghamca36cd12012-10-05 19:16:31 +0000258void
259SBBreakpoint::SetOneShot (bool one_shot)
260{
Greg Clayton5160ce52013-03-27 23:08:40 +0000261 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamca36cd12012-10-05 19:16:31 +0000262
263 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000264 log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)",
265 static_cast<void*>(m_opaque_sp.get()), one_shot);
Jim Inghamca36cd12012-10-05 19:16:31 +0000266
267 if (m_opaque_sp)
268 {
269 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
270 m_opaque_sp->SetOneShot (one_shot);
271 }
272}
273
274bool
275SBBreakpoint::IsOneShot () const
276{
277 if (m_opaque_sp)
278 {
279 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
280 return m_opaque_sp->IsOneShot();
281 }
282 else
283 return false;
284}
285
Jim Ingham11c81082012-09-25 23:55:19 +0000286bool
287SBBreakpoint::IsInternal ()
288{
289 if (m_opaque_sp)
290 {
291 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
292 return m_opaque_sp->IsInternal();
293 }
294 else
295 return false;
296}
297
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298void
Greg Claytonc982c762010-07-09 20:39:50 +0000299SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300{
Greg Clayton5160ce52013-03-27 23:08:40 +0000301 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000302
303 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000304 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)",
305 static_cast<void*>(m_opaque_sp.get()), count);
306
Greg Clayton66111032010-06-23 01:19:29 +0000307 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000308 {
309 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000310 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000311 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312}
313
Jim Ingham041a12f2010-10-22 01:15:49 +0000314void
315SBBreakpoint::SetCondition (const char *condition)
316{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000317 if (m_opaque_sp)
318 {
319 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
320 m_opaque_sp->SetCondition (condition);
321 }
Jim Ingham041a12f2010-10-22 01:15:49 +0000322}
323
324const char *
325SBBreakpoint::GetCondition ()
326{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000327 if (m_opaque_sp)
328 {
329 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
330 return m_opaque_sp->GetConditionText ();
331 }
332 return NULL;
Jim Ingham041a12f2010-10-22 01:15:49 +0000333}
334
Greg Claytonc982c762010-07-09 20:39:50 +0000335uint32_t
Greg Clayton9fed0d82010-07-23 23:33:17 +0000336SBBreakpoint::GetHitCount () const
337{
Greg Clayton48381312010-10-30 04:51:46 +0000338 uint32_t count = 0;
Greg Clayton9fed0d82010-07-23 23:33:17 +0000339 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000340 {
341 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000342 count = m_opaque_sp->GetHitCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000343 }
Greg Clayton48381312010-10-30 04:51:46 +0000344
Greg Clayton5160ce52013-03-27 23:08:40 +0000345 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000346 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000347 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u",
348 static_cast<void*>(m_opaque_sp.get()), count);
Greg Clayton48381312010-10-30 04:51:46 +0000349
350 return count;
Greg Clayton9fed0d82010-07-23 23:33:17 +0000351}
352
353uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354SBBreakpoint::GetIgnoreCount () const
355{
Greg Clayton48381312010-10-30 04:51:46 +0000356 uint32_t count = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000357 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000358 {
359 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000360 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000361 }
Greg Clayton48381312010-10-30 04:51:46 +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)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000365 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u",
366 static_cast<void*>(m_opaque_sp.get()), count);
Greg Clayton48381312010-10-30 04:51:46 +0000367
368 return count;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369}
370
371void
Greg Clayton48381312010-10-30 04:51:46 +0000372SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373{
Greg Clayton66111032010-06-23 01:19:29 +0000374 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000375 {
376 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000377 m_opaque_sp->SetThreadID (tid);
Greg Claytonaf67cec2010-12-20 20:49:23 +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)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000381 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")",
382 static_cast<void*>(m_opaque_sp.get()), tid);
Greg Clayton48381312010-10-30 04:51:46 +0000383
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384}
385
386tid_t
387SBBreakpoint::GetThreadID ()
388{
Greg Clayton48381312010-10-30 04:51:46 +0000389 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000390 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000391 {
392 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000393 tid = m_opaque_sp->GetThreadID();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000394 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395
Greg Clayton5160ce52013-03-27 23:08:40 +0000396 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000397 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000398 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64,
399 static_cast<void*>(m_opaque_sp.get()), tid);
Greg Clayton48381312010-10-30 04:51:46 +0000400 return tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401}
402
Jim Ingham62b02c62010-06-18 01:47:08 +0000403void
404SBBreakpoint::SetThreadIndex (uint32_t index)
405{
Greg Clayton5160ce52013-03-27 23:08:40 +0000406 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000407 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000408 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)",
409 static_cast<void*>(m_opaque_sp.get()), index);
Greg Clayton66111032010-06-23 01:19:29 +0000410 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000411 {
412 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000413 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000414 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000415}
416
417uint32_t
418SBBreakpoint::GetThreadIndex() const
419{
Greg Claytonbdf4c6a2010-12-15 20:50:06 +0000420 uint32_t thread_idx = UINT32_MAX;
Greg Clayton66111032010-06-23 01:19:29 +0000421 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000422 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000423 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
424 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chen763d1a12010-12-15 21:39:37 +0000425 if (thread_spec != NULL)
Greg Clayton48381312010-10-30 04:51:46 +0000426 thread_idx = thread_spec->GetIndex();
Jim Ingham62b02c62010-06-18 01:47:08 +0000427 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000428 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000429 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000430 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u",
431 static_cast<void*>(m_opaque_sp.get()), thread_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000432
Johnny Chen763d1a12010-12-15 21:39:37 +0000433 return thread_idx;
Jim Ingham62b02c62010-06-18 01:47:08 +0000434}
Jim Ingham62b02c62010-06-18 01:47:08 +0000435
436void
437SBBreakpoint::SetThreadName (const char *thread_name)
438{
Greg Clayton5160ce52013-03-27 23:08:40 +0000439 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000440 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000441 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)",
442 static_cast<void*>(m_opaque_sp.get()), thread_name);
Greg Clayton48381312010-10-30 04:51:46 +0000443
Greg Clayton66111032010-06-23 01:19:29 +0000444 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000445 {
446 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000447 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000448 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000449}
450
451const char *
452SBBreakpoint::GetThreadName () const
453{
Greg Clayton48381312010-10-30 04:51:46 +0000454 const char *name = NULL;
Greg Clayton66111032010-06-23 01:19:29 +0000455 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000456 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000457 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
458 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chen763d1a12010-12-15 21:39:37 +0000459 if (thread_spec != NULL)
Greg Clayton48381312010-10-30 04:51:46 +0000460 name = thread_spec->GetName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000461 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000462 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000463 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000464 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s",
465 static_cast<void*>(m_opaque_sp.get()), name);
Greg Clayton48381312010-10-30 04:51:46 +0000466
467 return name;
Jim Ingham62b02c62010-06-18 01:47:08 +0000468}
469
470void
471SBBreakpoint::SetQueueName (const char *queue_name)
472{
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)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000475 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)",
476 static_cast<void*>(m_opaque_sp.get()), queue_name);
Greg Clayton66111032010-06-23 01:19:29 +0000477 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000478 {
479 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000480 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000481 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000482}
483
484const char *
485SBBreakpoint::GetQueueName () const
486{
Greg Clayton48381312010-10-30 04:51:46 +0000487 const char *name = NULL;
Greg Clayton66111032010-06-23 01:19:29 +0000488 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000489 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000490 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
491 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
492 if (thread_spec)
Greg Clayton48381312010-10-30 04:51:46 +0000493 name = thread_spec->GetQueueName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000494 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000495 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000496 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000497 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s",
498 static_cast<void*>(m_opaque_sp.get()), name);
Greg Clayton48381312010-10-30 04:51:46 +0000499
500 return name;
Jim Ingham62b02c62010-06-18 01:47:08 +0000501}
502
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503size_t
504SBBreakpoint::GetNumResolvedLocations() const
505{
Greg Clayton48381312010-10-30 04:51:46 +0000506 size_t num_resolved = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000507 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000508 {
509 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000510 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000511 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000512 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000513 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000514 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64,
515 static_cast<void*>(m_opaque_sp.get()),
516 static_cast<uint64_t>(num_resolved));
Greg Clayton48381312010-10-30 04:51:46 +0000517 return num_resolved;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518}
519
520size_t
521SBBreakpoint::GetNumLocations() const
522{
Greg Clayton48381312010-10-30 04:51:46 +0000523 size_t num_locs = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000524 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000525 {
526 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000527 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000528 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000529 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000530 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000531 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64,
532 static_cast<void*>(m_opaque_sp.get()),
533 static_cast<uint64_t>(num_locs));
Greg Clayton48381312010-10-30 04:51:46 +0000534 return num_locs;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535}
536
Caroline Ticedde9cff2010-09-20 05:20:02 +0000537bool
Greg Clayton05faeb72010-10-07 04:19:01 +0000538SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
Greg Clayton66111032010-06-23 01:19:29 +0000540 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000542 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton05faeb72010-10-07 04:19:01 +0000543 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
544 m_opaque_sp->GetResolverDescription (s.get());
545 m_opaque_sp->GetFilterDescription (s.get());
546 const size_t num_locations = m_opaque_sp->GetNumLocations ();
Daniel Malead01b2952012-11-29 21:49:15 +0000547 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
Greg Clayton05faeb72010-10-07 04:19:01 +0000548 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 }
Greg Clayton05faeb72010-10-07 04:19:01 +0000550 s.Printf ("No value");
551 return false;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000552}
553
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554bool
555SBBreakpoint::PrivateBreakpointHitCallback
556(
557 void *baton,
558 StoppointCallbackContext *ctx,
559 lldb::user_id_t break_id,
560 lldb::user_id_t break_loc_id
561)
562{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000563 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
564 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565 if (baton && bp_sp)
566 {
567 CallbackData *data = (CallbackData *)baton;
568 lldb_private::Breakpoint *bp = bp_sp.get();
569 if (bp && data->callback)
570 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000571 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonc14ee322011-09-22 04:58:26 +0000572 if (process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000574 SBProcess sb_process (process->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 SBThread sb_thread;
576 SBBreakpointLocation sb_location;
577 assert (bp_sp);
578 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Clayton1ac04c32012-02-21 00:09:25 +0000579 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonc14ee322011-09-22 04:58:26 +0000580 if (thread)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000581 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582
583 return data->callback (data->callback_baton,
584 sb_process,
585 sb_thread,
586 sb_location);
587 }
588 }
589 }
590 return true; // Return true if we should stop at this breakpoint
591}
592
593void
594SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
595{
Greg Clayton5160ce52013-03-27 23:08:40 +0000596 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000597
Caroline Ticeceb6b132010-10-26 03:11:13 +0000598 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000599 {
600 void *pointer = &callback;
601 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)",
602 static_cast<void*>(m_opaque_sp.get()),
603 *static_cast<void**>(&pointer), static_cast<void*>(baton));
604 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000605
Greg Claytonc14ee322011-09-22 04:58:26 +0000606 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000608 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000609 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000610 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611 }
612}
613
Jim Inghamd80102e2014-04-02 01:04:55 +0000614void
615SBBreakpoint::SetScriptCallbackFunction (const char *callback_function_name)
616{
617 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000618
Jim Inghamd80102e2014-04-02 01:04:55 +0000619 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000620 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackFunction (callback=%s)",
621 static_cast<void*>(m_opaque_sp.get()),
622 callback_function_name);
Jim Inghamd80102e2014-04-02 01:04:55 +0000623
624 if (m_opaque_sp)
625 {
626 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
627 BreakpointOptions *bp_options = m_opaque_sp->GetOptions();
628 m_opaque_sp->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options,
629 callback_function_name);
630 }
631}
632
633SBError
634SBBreakpoint::SetScriptCallbackBody (const char *callback_body_text)
635{
636 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000637
Jim Inghamd80102e2014-04-02 01:04:55 +0000638 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000639 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
640 static_cast<void*>(m_opaque_sp.get()), callback_body_text);
Jim Inghamd80102e2014-04-02 01:04:55 +0000641
642 SBError sb_error;
643 if (m_opaque_sp)
644 {
645 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
646 BreakpointOptions *bp_options = m_opaque_sp->GetOptions();
647 Error error = m_opaque_sp->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
648 callback_body_text);
649 sb_error.SetError(error);
650 }
651 else
652 sb_error.SetErrorString("invalid breakpoint");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000653
Jim Inghamd80102e2014-04-02 01:04:55 +0000654 return sb_error;
655}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000657bool
658SBBreakpoint::AddName (const char *new_name)
659{
660 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
661
662 if (log)
663 log->Printf ("SBBreakpoint(%p)::AddName (name=%s)",
664 static_cast<void*>(m_opaque_sp.get()),
665 new_name);
666
667 if (m_opaque_sp)
668 {
669 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
670 Error error; // Think I'm just going to swallow the error here, it's probably more annoying to have to provide it.
671 return m_opaque_sp->AddName(new_name, error);
672 }
673
674 return false;
675}
676
677void
678SBBreakpoint::RemoveName (const char *name_to_remove)
679{
680 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
681
682 if (log)
683 log->Printf ("SBBreakpoint(%p)::RemoveName (name=%s)",
684 static_cast<void*>(m_opaque_sp.get()),
685 name_to_remove);
686
687 if (m_opaque_sp)
688 {
689 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
690 m_opaque_sp->RemoveName(name_to_remove);
691 }
692}
693
694bool
695SBBreakpoint::MatchesName (const char *name)
696{
697 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
698
699 if (log)
700 log->Printf ("SBBreakpoint(%p)::MatchesName (name=%s)",
701 static_cast<void*>(m_opaque_sp.get()),
702 name);
703
704 if (m_opaque_sp)
705 {
706 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
707 return m_opaque_sp->MatchesName(name);
708 }
709
710 return false;
711}
712
713void
714SBBreakpoint::GetNames (SBStringList &names)
715{
716 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
717
718 if (log)
719 log->Printf ("SBBreakpoint(%p)::GetNames ()",
720 static_cast<void*>(m_opaque_sp.get()));
721
722 if (m_opaque_sp)
723 {
724 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
725 std::vector<std::string> names_vec;
726 m_opaque_sp->GetNames(names_vec);
727 for (std::string name : names_vec)
728 {
729 names.AppendString (name.c_str());
730 }
731 }
732}
733
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000734lldb_private::Breakpoint *
735SBBreakpoint::operator->() const
736{
Greg Clayton66111032010-06-23 01:19:29 +0000737 return m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738}
739
740lldb_private::Breakpoint *
741SBBreakpoint::get() const
742{
Greg Clayton66111032010-06-23 01:19:29 +0000743 return m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744}
745
746lldb::BreakpointSP &
747SBBreakpoint::operator *()
748{
Greg Clayton66111032010-06-23 01:19:29 +0000749 return m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750}
751
752const lldb::BreakpointSP &
753SBBreakpoint::operator *() const
754{
Greg Clayton66111032010-06-23 01:19:29 +0000755 return m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756}
757
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000758bool
759SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
760{
761 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
762
763}
764
Greg Clayton9fed0d82010-07-23 23:33:17 +0000765BreakpointEventType
766SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
767{
768 if (event.IsValid())
769 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
770 return eBreakpointEventTypeInvalidType;
771}
772
773SBBreakpoint
774SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
775{
776 SBBreakpoint sb_breakpoint;
777 if (event.IsValid())
778 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
779 return sb_breakpoint;
780}
781
782SBBreakpointLocation
783SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
784{
785 SBBreakpointLocation sb_breakpoint_loc;
786 if (event.IsValid())
787 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
788 return sb_breakpoint_loc;
789}
790
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000791uint32_t
792SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
793{
794 uint32_t num_locations = 0;
795 if (event.IsValid())
796 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
797 return num_locations;
798}
799
Greg Clayton9fed0d82010-07-23 23:33:17 +0000800