blob: a950ca934c68b27276ef919704160edba5b8a37a [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"
Jim Inghamd80102e2014-04-02 01:04:55 +000022#include "lldb/Core/Debugger.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/Stream.h"
25#include "lldb/Core/StreamFile.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000026#include "lldb/Interpreter/CommandInterpreter.h"
27#include "lldb/Interpreter/ScriptInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000029#include "lldb/Target/SectionLoadList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000031#include "lldb/Target/Thread.h"
32#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
34
35#include "lldb/lldb-enumerations.h"
36
37using namespace lldb;
38using namespace lldb_private;
39
40struct CallbackData
41{
42 SBBreakpoint::BreakpointHitCallback callback;
43 void *callback_baton;
44};
45
46class SBBreakpointCallbackBaton : public Baton
47{
48public:
49
50 SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) :
51 Baton (new CallbackData)
52 {
53 CallbackData *data = (CallbackData *)m_data;
54 data->callback = callback;
55 data->callback_baton = baton;
56 }
57
58 virtual ~SBBreakpointCallbackBaton()
59 {
60 CallbackData *data = (CallbackData *)m_data;
61
62 if (data)
63 {
64 delete data;
65 m_data = NULL;
66 }
67 }
68};
69
70
71SBBreakpoint::SBBreakpoint () :
Greg Clayton66111032010-06-23 01:19:29 +000072 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073{
74}
75
76SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000077 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078{
79}
80
81
82SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) :
Greg Clayton66111032010-06-23 01:19:29 +000083 m_opaque_sp (bp_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084{
85}
86
87SBBreakpoint::~SBBreakpoint()
88{
89}
90
91const SBBreakpoint &
92SBBreakpoint::operator = (const SBBreakpoint& rhs)
93{
94 if (this != &rhs)
Greg Clayton66111032010-06-23 01:19:29 +000095 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096 return *this;
97}
98
Greg Claytonac2eb9b2010-12-12 19:25:26 +000099bool
100SBBreakpoint::operator == (const lldb::SBBreakpoint& rhs)
101{
102 if (m_opaque_sp && rhs.m_opaque_sp)
103 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
104 return false;
105}
106
Enrico Granatac3387332013-05-03 01:29:27 +0000107bool
108SBBreakpoint::operator != (const lldb::SBBreakpoint& rhs)
109{
110 if (m_opaque_sp && rhs.m_opaque_sp)
111 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
112 return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp);
113}
114
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115break_id_t
116SBBreakpoint::GetID () const
117{
Greg Clayton5160ce52013-03-27 23:08:40 +0000118 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000119
Greg Claytonaf67cec2010-12-20 20:49:23 +0000120 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000121 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000122 break_id = m_opaque_sp->GetID();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000123
124 if (log)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000125 {
126 if (break_id == LLDB_INVALID_BREAK_ID)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000127 log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID",
128 static_cast<void*>(m_opaque_sp.get()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000129 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000130 log->Printf ("SBBreakpoint(%p)::GetID () => %u",
131 static_cast<void*>(m_opaque_sp.get()), break_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000132 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000133
Greg Claytonaf67cec2010-12-20 20:49:23 +0000134 return break_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135}
136
137
138bool
139SBBreakpoint::IsValid() const
140{
Jim Inghame029fa52014-07-02 18:44:43 +0000141 if (!m_opaque_sp)
142 return false;
143 else if (m_opaque_sp->GetTarget().GetBreakpointByID(m_opaque_sp->GetID()))
144 return true;
145 else
146 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147}
148
149void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150SBBreakpoint::ClearAllBreakpointSites ()
151{
Greg Clayton66111032010-06-23 01:19:29 +0000152 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000153 {
154 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000155 m_opaque_sp->ClearAllBreakpointSites ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000156 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157}
158
159SBBreakpointLocation
160SBBreakpoint::FindLocationByAddress (addr_t vm_addr)
161{
162 SBBreakpointLocation sb_bp_location;
163
Greg Clayton66111032010-06-23 01:19:29 +0000164 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 {
166 if (vm_addr != LLDB_INVALID_ADDRESS)
167 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000168 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169 Address address;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000170 Target &target = m_opaque_sp->GetTarget();
171 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000173 address.SetRawAddress (vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174 }
Greg Clayton66111032010-06-23 01:19:29 +0000175 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176 }
177 }
178 return sb_bp_location;
179}
180
181break_id_t
182SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr)
183{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000184 break_id_t break_id = LLDB_INVALID_BREAK_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000185
Greg Claytonaf67cec2010-12-20 20:49:23 +0000186 if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000188 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
189 Address address;
190 Target &target = m_opaque_sp->GetTarget();
191 if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000193 address.SetRawAddress (vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000195 break_id = m_opaque_sp->FindLocationIDByAddress (address);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196 }
197
Greg Claytonaf67cec2010-12-20 20:49:23 +0000198 return break_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199}
200
201SBBreakpointLocation
202SBBreakpoint::FindLocationByID (break_id_t bp_loc_id)
203{
204 SBBreakpointLocation sb_bp_location;
205
Greg Clayton66111032010-06-23 01:19:29 +0000206 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000207 {
208 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000209 sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000210 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211
212 return sb_bp_location;
213}
214
215SBBreakpointLocation
216SBBreakpoint::GetLocationAtIndex (uint32_t index)
217{
218 SBBreakpointLocation sb_bp_location;
219
Greg Clayton66111032010-06-23 01:19:29 +0000220 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000221 {
222 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000223 sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225
226 return sb_bp_location;
227}
228
229void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230SBBreakpoint::SetEnabled (bool enable)
231{
Greg Clayton5160ce52013-03-27 23:08:40 +0000232 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000233
234 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000235 log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)",
236 static_cast<void*>(m_opaque_sp.get()), enable);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000237
Greg Clayton66111032010-06-23 01:19:29 +0000238 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000239 {
240 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000241 m_opaque_sp->SetEnabled (enable);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000242 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243}
244
245bool
246SBBreakpoint::IsEnabled ()
247{
Greg Clayton66111032010-06-23 01:19:29 +0000248 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000249 {
250 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000251 return m_opaque_sp->IsEnabled();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000252 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253 else
254 return false;
255}
256
Jim Inghamca36cd12012-10-05 19:16:31 +0000257void
258SBBreakpoint::SetOneShot (bool one_shot)
259{
Greg Clayton5160ce52013-03-27 23:08:40 +0000260 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamca36cd12012-10-05 19:16:31 +0000261
262 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000263 log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)",
264 static_cast<void*>(m_opaque_sp.get()), one_shot);
Jim Inghamca36cd12012-10-05 19:16:31 +0000265
266 if (m_opaque_sp)
267 {
268 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
269 m_opaque_sp->SetOneShot (one_shot);
270 }
271}
272
273bool
274SBBreakpoint::IsOneShot () const
275{
276 if (m_opaque_sp)
277 {
278 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
279 return m_opaque_sp->IsOneShot();
280 }
281 else
282 return false;
283}
284
Jim Ingham11c81082012-09-25 23:55:19 +0000285bool
286SBBreakpoint::IsInternal ()
287{
288 if (m_opaque_sp)
289 {
290 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
291 return m_opaque_sp->IsInternal();
292 }
293 else
294 return false;
295}
296
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000297void
Greg Claytonc982c762010-07-09 20:39:50 +0000298SBBreakpoint::SetIgnoreCount (uint32_t count)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299{
Greg Clayton5160ce52013-03-27 23:08:40 +0000300 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000301
302 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000303 log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)",
304 static_cast<void*>(m_opaque_sp.get()), count);
305
Greg Clayton66111032010-06-23 01:19:29 +0000306 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000307 {
308 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000309 m_opaque_sp->SetIgnoreCount (count);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000310 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311}
312
Jim Ingham041a12f2010-10-22 01:15:49 +0000313void
314SBBreakpoint::SetCondition (const char *condition)
315{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000316 if (m_opaque_sp)
317 {
318 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
319 m_opaque_sp->SetCondition (condition);
320 }
Jim Ingham041a12f2010-10-22 01:15:49 +0000321}
322
323const char *
324SBBreakpoint::GetCondition ()
325{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000326 if (m_opaque_sp)
327 {
328 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
329 return m_opaque_sp->GetConditionText ();
330 }
331 return NULL;
Jim Ingham041a12f2010-10-22 01:15:49 +0000332}
333
Greg Claytonc982c762010-07-09 20:39:50 +0000334uint32_t
Greg Clayton9fed0d82010-07-23 23:33:17 +0000335SBBreakpoint::GetHitCount () const
336{
Greg Clayton48381312010-10-30 04:51:46 +0000337 uint32_t count = 0;
Greg Clayton9fed0d82010-07-23 23:33:17 +0000338 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000339 {
340 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000341 count = m_opaque_sp->GetHitCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000342 }
Greg Clayton48381312010-10-30 04:51:46 +0000343
Greg Clayton5160ce52013-03-27 23:08:40 +0000344 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000345 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000346 log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u",
347 static_cast<void*>(m_opaque_sp.get()), count);
Greg Clayton48381312010-10-30 04:51:46 +0000348
349 return count;
Greg Clayton9fed0d82010-07-23 23:33:17 +0000350}
351
352uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353SBBreakpoint::GetIgnoreCount () const
354{
Greg Clayton48381312010-10-30 04:51:46 +0000355 uint32_t count = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000356 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000357 {
358 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000359 count = m_opaque_sp->GetIgnoreCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000360 }
Greg Clayton48381312010-10-30 04:51:46 +0000361
Greg Clayton5160ce52013-03-27 23:08:40 +0000362 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000363 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000364 log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u",
365 static_cast<void*>(m_opaque_sp.get()), count);
Greg Clayton48381312010-10-30 04:51:46 +0000366
367 return count;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368}
369
370void
Greg Clayton48381312010-10-30 04:51:46 +0000371SBBreakpoint::SetThreadID (tid_t tid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372{
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 m_opaque_sp->SetThreadID (tid);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000377 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000378 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000379 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000380 log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")",
381 static_cast<void*>(m_opaque_sp.get()), tid);
Greg Clayton48381312010-10-30 04:51:46 +0000382
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383}
384
385tid_t
386SBBreakpoint::GetThreadID ()
387{
Greg Clayton48381312010-10-30 04:51:46 +0000388 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000389 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000390 {
391 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000392 tid = m_opaque_sp->GetThreadID();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000393 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394
Greg Clayton5160ce52013-03-27 23:08:40 +0000395 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000396 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000397 log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64,
398 static_cast<void*>(m_opaque_sp.get()), tid);
Greg Clayton48381312010-10-30 04:51:46 +0000399 return tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400}
401
Jim Ingham62b02c62010-06-18 01:47:08 +0000402void
403SBBreakpoint::SetThreadIndex (uint32_t index)
404{
Greg Clayton5160ce52013-03-27 23:08:40 +0000405 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000406 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000407 log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)",
408 static_cast<void*>(m_opaque_sp.get()), index);
Greg Clayton66111032010-06-23 01:19:29 +0000409 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000410 {
411 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000412 m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000413 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000414}
415
416uint32_t
417SBBreakpoint::GetThreadIndex() const
418{
Greg Claytonbdf4c6a2010-12-15 20:50:06 +0000419 uint32_t thread_idx = UINT32_MAX;
Greg Clayton66111032010-06-23 01:19:29 +0000420 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000421 {
Greg Claytonaf67cec2010-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();
Johnny Chen763d1a12010-12-15 21:39:37 +0000424 if (thread_spec != NULL)
Greg Clayton48381312010-10-30 04:51:46 +0000425 thread_idx = thread_spec->GetIndex();
Jim Ingham62b02c62010-06-18 01:47:08 +0000426 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000427 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000428 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000429 log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u",
430 static_cast<void*>(m_opaque_sp.get()), thread_idx);
Greg Clayton48381312010-10-30 04:51:46 +0000431
Johnny Chen763d1a12010-12-15 21:39:37 +0000432 return thread_idx;
Jim Ingham62b02c62010-06-18 01:47:08 +0000433}
Jim Ingham62b02c62010-06-18 01:47:08 +0000434
435void
436SBBreakpoint::SetThreadName (const char *thread_name)
437{
Greg Clayton5160ce52013-03-27 23:08:40 +0000438 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000439 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000440 log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)",
441 static_cast<void*>(m_opaque_sp.get()), thread_name);
Greg Clayton48381312010-10-30 04:51:46 +0000442
Greg Clayton66111032010-06-23 01:19:29 +0000443 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000444 {
445 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000446 m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000447 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000448}
449
450const char *
451SBBreakpoint::GetThreadName () const
452{
Greg Clayton48381312010-10-30 04:51:46 +0000453 const char *name = NULL;
Greg Clayton66111032010-06-23 01:19:29 +0000454 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000455 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000456 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
457 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
Johnny Chen763d1a12010-12-15 21:39:37 +0000458 if (thread_spec != NULL)
Greg Clayton48381312010-10-30 04:51:46 +0000459 name = thread_spec->GetName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000460 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000461 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000462 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000463 log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s",
464 static_cast<void*>(m_opaque_sp.get()), name);
Greg Clayton48381312010-10-30 04:51:46 +0000465
466 return name;
Jim Ingham62b02c62010-06-18 01:47:08 +0000467}
468
469void
470SBBreakpoint::SetQueueName (const char *queue_name)
471{
Greg Clayton5160ce52013-03-27 23:08:40 +0000472 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000473 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000474 log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)",
475 static_cast<void*>(m_opaque_sp.get()), queue_name);
Greg Clayton66111032010-06-23 01:19:29 +0000476 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000477 {
478 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000479 m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000480 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000481}
482
483const char *
484SBBreakpoint::GetQueueName () const
485{
Greg Clayton48381312010-10-30 04:51:46 +0000486 const char *name = NULL;
Greg Clayton66111032010-06-23 01:19:29 +0000487 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000488 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000489 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
490 const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate();
491 if (thread_spec)
Greg Clayton48381312010-10-30 04:51:46 +0000492 name = thread_spec->GetQueueName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000493 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000494 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000495 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000496 log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s",
497 static_cast<void*>(m_opaque_sp.get()), name);
Greg Clayton48381312010-10-30 04:51:46 +0000498
499 return name;
Jim Ingham62b02c62010-06-18 01:47:08 +0000500}
501
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502size_t
503SBBreakpoint::GetNumResolvedLocations() const
504{
Greg Clayton48381312010-10-30 04:51:46 +0000505 size_t num_resolved = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000506 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000507 {
508 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000509 num_resolved = m_opaque_sp->GetNumResolvedLocations();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000510 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000511 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000512 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000513 log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64,
514 static_cast<void*>(m_opaque_sp.get()),
515 static_cast<uint64_t>(num_resolved));
Greg Clayton48381312010-10-30 04:51:46 +0000516 return num_resolved;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517}
518
519size_t
520SBBreakpoint::GetNumLocations() const
521{
Greg Clayton48381312010-10-30 04:51:46 +0000522 size_t num_locs = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000523 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000524 {
525 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton48381312010-10-30 04:51:46 +0000526 num_locs = m_opaque_sp->GetNumLocations();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000527 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000528 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000529 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000530 log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64,
531 static_cast<void*>(m_opaque_sp.get()),
532 static_cast<uint64_t>(num_locs));
Greg Clayton48381312010-10-30 04:51:46 +0000533 return num_locs;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534}
535
Caroline Ticedde9cff2010-09-20 05:20:02 +0000536bool
Greg Clayton05faeb72010-10-07 04:19:01 +0000537SBBreakpoint::GetDescription (SBStream &s)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538{
Greg Clayton66111032010-06-23 01:19:29 +0000539 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000541 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Greg Clayton05faeb72010-10-07 04:19:01 +0000542 s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID());
543 m_opaque_sp->GetResolverDescription (s.get());
544 m_opaque_sp->GetFilterDescription (s.get());
545 const size_t num_locations = m_opaque_sp->GetNumLocations ();
Daniel Malead01b2952012-11-29 21:49:15 +0000546 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
Greg Clayton05faeb72010-10-07 04:19:01 +0000547 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 }
Greg Clayton05faeb72010-10-07 04:19:01 +0000549 s.Printf ("No value");
550 return false;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000551}
552
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553bool
554SBBreakpoint::PrivateBreakpointHitCallback
555(
556 void *baton,
557 StoppointCallbackContext *ctx,
558 lldb::user_id_t break_id,
559 lldb::user_id_t break_loc_id
560)
561{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000562 ExecutionContext exe_ctx (ctx->exe_ctx_ref);
563 BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 if (baton && bp_sp)
565 {
566 CallbackData *data = (CallbackData *)baton;
567 lldb_private::Breakpoint *bp = bp_sp.get();
568 if (bp && data->callback)
569 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000570 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonc14ee322011-09-22 04:58:26 +0000571 if (process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572 {
Greg Claytone1cd1be2012-01-29 20:56:30 +0000573 SBProcess sb_process (process->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 SBThread sb_thread;
575 SBBreakpointLocation sb_location;
576 assert (bp_sp);
577 sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id));
Greg Clayton1ac04c32012-02-21 00:09:25 +0000578 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonc14ee322011-09-22 04:58:26 +0000579 if (thread)
Greg Claytone1cd1be2012-01-29 20:56:30 +0000580 sb_thread.SetThread(thread->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581
582 return data->callback (data->callback_baton,
583 sb_process,
584 sb_thread,
585 sb_location);
586 }
587 }
588 }
589 return true; // Return true if we should stop at this breakpoint
590}
591
592void
593SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton)
594{
Greg Clayton5160ce52013-03-27 23:08:40 +0000595 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000596
Caroline Ticeceb6b132010-10-26 03:11:13 +0000597 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000598 {
599 void *pointer = &callback;
600 log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)",
601 static_cast<void*>(m_opaque_sp.get()),
602 *static_cast<void**>(&pointer), static_cast<void*>(baton));
603 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000604
Greg Claytonc14ee322011-09-22 04:58:26 +0000605 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000607 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608 BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000609 m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 }
611}
612
Jim Inghamd80102e2014-04-02 01:04:55 +0000613void
614SBBreakpoint::SetScriptCallbackFunction (const char *callback_function_name)
615{
616 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000617
Jim Inghamd80102e2014-04-02 01:04:55 +0000618 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000619 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackFunction (callback=%s)",
620 static_cast<void*>(m_opaque_sp.get()),
621 callback_function_name);
Jim Inghamd80102e2014-04-02 01:04:55 +0000622
623 if (m_opaque_sp)
624 {
625 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
626 BreakpointOptions *bp_options = m_opaque_sp->GetOptions();
627 m_opaque_sp->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options,
628 callback_function_name);
629 }
630}
631
632SBError
633SBBreakpoint::SetScriptCallbackBody (const char *callback_body_text)
634{
635 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000636
Jim Inghamd80102e2014-04-02 01:04:55 +0000637 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000638 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
639 static_cast<void*>(m_opaque_sp.get()), callback_body_text);
Jim Inghamd80102e2014-04-02 01:04:55 +0000640
641 SBError sb_error;
642 if (m_opaque_sp)
643 {
644 Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
645 BreakpointOptions *bp_options = m_opaque_sp->GetOptions();
646 Error error = m_opaque_sp->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
647 callback_body_text);
648 sb_error.SetError(error);
649 }
650 else
651 sb_error.SetErrorString("invalid breakpoint");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000652
Jim Inghamd80102e2014-04-02 01:04:55 +0000653 return sb_error;
654}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655
656lldb_private::Breakpoint *
657SBBreakpoint::operator->() const
658{
Greg Clayton66111032010-06-23 01:19:29 +0000659 return m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660}
661
662lldb_private::Breakpoint *
663SBBreakpoint::get() const
664{
Greg Clayton66111032010-06-23 01:19:29 +0000665 return m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000666}
667
668lldb::BreakpointSP &
669SBBreakpoint::operator *()
670{
Greg Clayton66111032010-06-23 01:19:29 +0000671 return m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672}
673
674const lldb::BreakpointSP &
675SBBreakpoint::operator *() const
676{
Greg Clayton66111032010-06-23 01:19:29 +0000677 return m_opaque_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678}
679
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000680bool
681SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event)
682{
683 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != NULL;
684
685}
686
Greg Clayton9fed0d82010-07-23 23:33:17 +0000687BreakpointEventType
688SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event)
689{
690 if (event.IsValid())
691 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP());
692 return eBreakpointEventTypeInvalidType;
693}
694
695SBBreakpoint
696SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event)
697{
698 SBBreakpoint sb_breakpoint;
699 if (event.IsValid())
700 sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP());
701 return sb_breakpoint;
702}
703
704SBBreakpointLocation
705SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx)
706{
707 SBBreakpointLocation sb_breakpoint_loc;
708 if (event.IsValid())
709 sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx));
710 return sb_breakpoint_loc;
711}
712
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000713uint32_t
714SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event)
715{
716 uint32_t num_locations = 0;
717 if (event.IsValid())
718 num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP()));
719 return num_locations;
720}
721
Greg Clayton9fed0d82010-07-23 23:33:17 +0000722