blob: 4390e9ad737a40ccbdb5c6080e11fb17b0aacc07 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBBreakpointLocation.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/SBBreakpointLocation.h"
11#include "lldb/API/SBDefines.h"
Greg Claytonf644ddf2011-09-24 01:37:21 +000012#include "lldb/API/SBAddress.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/API/SBDebugger.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
16#include "lldb/lldb-types.h"
17#include "lldb/lldb-defines.h"
Greg Clayton4e78f602010-11-18 18:52:36 +000018#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000020#include "lldb/Core/Debugger.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/Stream.h"
23#include "lldb/Core/StreamFile.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000024#include "lldb/Interpreter/CommandInterpreter.h"
25#include "lldb/Interpreter/ScriptInterpreter.h"
26#include "lldb/Target/ThreadSpec.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000027#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000028#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
30using namespace lldb;
31using namespace lldb_private;
32
33
Greg Claytonefabb122010-11-05 23:17:00 +000034SBBreakpointLocation::SBBreakpointLocation () :
35 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036{
37}
38
39SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
Greg Clayton66111032010-06-23 01:19:29 +000040 m_opaque_sp (break_loc_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041{
Greg Clayton5160ce52013-03-27 23:08:40 +000042 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000043
44 if (log)
45 {
46 SBStream sstr;
Johnny Chenfc87e2d2011-04-25 20:23:05 +000047 GetDescription (sstr, lldb::eDescriptionLevelBrief);
Caroline Tice750cd172010-10-26 23:49:36 +000048 log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp"
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000049 "=%p) => this.sp = %p (%s)",
50 static_cast<void*>(break_loc_sp.get()),
51 static_cast<void*>(m_opaque_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000052 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053}
54
Greg Claytonefabb122010-11-05 23:17:00 +000055SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
56 m_opaque_sp (rhs.m_opaque_sp)
57{
58}
59
60const SBBreakpointLocation &
61SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
62{
63 if (this != &rhs)
64 m_opaque_sp = rhs.m_opaque_sp;
65 return *this;
66}
67
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069SBBreakpointLocation::~SBBreakpointLocation ()
70{
71}
72
73bool
74SBBreakpointLocation::IsValid() const
75{
Greg Clayton66111032010-06-23 01:19:29 +000076 return m_opaque_sp.get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077}
78
Jim Ingham810bf852011-09-24 01:04:57 +000079SBAddress
80SBBreakpointLocation::GetAddress ()
81{
82 if (m_opaque_sp)
83 return SBAddress(&m_opaque_sp->GetAddress());
84 else
85 return SBAddress();
86}
87
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088addr_t
89SBBreakpointLocation::GetLoadAddress ()
90{
91 addr_t ret_addr = LLDB_INVALID_ADDRESS;
92
Greg Clayton66111032010-06-23 01:19:29 +000093 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094 {
Greg Claytonaf67cec2010-12-20 20:49:23 +000095 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +000096 ret_addr = m_opaque_sp->GetLoadAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097 }
98
99 return ret_addr;
100}
101
102void
103SBBreakpointLocation::SetEnabled (bool enabled)
104{
Greg Clayton66111032010-06-23 01:19:29 +0000105 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000107 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000108 m_opaque_sp->SetEnabled (enabled);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
110}
111
112bool
113SBBreakpointLocation::IsEnabled ()
114{
Greg Clayton66111032010-06-23 01:19:29 +0000115 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000116 {
117 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000118 return m_opaque_sp->IsEnabled();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000119 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120 else
121 return false;
122}
123
Greg Claytonc982c762010-07-09 20:39:50 +0000124uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125SBBreakpointLocation::GetIgnoreCount ()
126{
Greg Clayton66111032010-06-23 01:19:29 +0000127 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000128 {
129 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000130 return m_opaque_sp->GetIgnoreCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000131 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132 else
133 return 0;
134}
135
136void
Greg Claytonc982c762010-07-09 20:39:50 +0000137SBBreakpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138{
Greg Clayton66111032010-06-23 01:19:29 +0000139 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000140 {
141 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000142 m_opaque_sp->SetIgnoreCount (n);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000143 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144}
145
146void
Jim Ingham041a12f2010-10-22 01:15:49 +0000147SBBreakpointLocation::SetCondition (const char *condition)
148{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000149 if (m_opaque_sp)
150 {
151 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
152 m_opaque_sp->SetCondition (condition);
153 }
Jim Ingham041a12f2010-10-22 01:15:49 +0000154}
155
156const char *
157SBBreakpointLocation::GetCondition ()
158{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000159 if (m_opaque_sp)
160 {
161 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
162 return m_opaque_sp->GetConditionText ();
163 }
164 return NULL;
Jim Ingham041a12f2010-10-22 01:15:49 +0000165}
166
167void
Jim Inghamd80102e2014-04-02 01:04:55 +0000168SBBreakpointLocation::SetScriptCallbackFunction (const char *callback_function_name)
169{
170 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000171
Jim Inghamd80102e2014-04-02 01:04:55 +0000172 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000173 log->Printf ("SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)",
174 static_cast<void*>(m_opaque_sp.get()),
175 callback_function_name);
Jim Inghamd80102e2014-04-02 01:04:55 +0000176
177 if (m_opaque_sp)
178 {
179 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
180 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
181 m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options,
182 callback_function_name);
Jim Inghamd80102e2014-04-02 01:04:55 +0000183 }
184}
185
186SBError
187SBBreakpointLocation::SetScriptCallbackBody (const char *callback_body_text)
188{
189 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000190
Jim Inghamd80102e2014-04-02 01:04:55 +0000191 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000192 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
193 static_cast<void*>(m_opaque_sp.get()), callback_body_text);
194
Jim Inghamd80102e2014-04-02 01:04:55 +0000195 SBError sb_error;
196 if (m_opaque_sp)
197 {
198 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
199 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
200 Error error = m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
201 callback_body_text);
202 sb_error.SetError(error);
203 }
204 else
205 sb_error.SetErrorString("invalid breakpoint");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000206
Jim Inghamd80102e2014-04-02 01:04:55 +0000207 return sb_error;
208}
209
210void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211SBBreakpointLocation::SetThreadID (tid_t thread_id)
212{
Greg Clayton66111032010-06-23 01:19:29 +0000213 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000214 {
215 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000216 m_opaque_sp->SetThreadID (thread_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000217 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218}
219
220tid_t
221SBBreakpointLocation::GetThreadID ()
222{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000223 tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton66111032010-06-23 01:19:29 +0000224 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000225 {
226 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000227 return m_opaque_sp->GetThreadID();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000228 }
229 return tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230}
231
Jim Ingham62b02c62010-06-18 01:47:08 +0000232void
233SBBreakpointLocation::SetThreadIndex (uint32_t index)
234{
Greg Clayton66111032010-06-23 01:19:29 +0000235 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000236 {
237 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000238 m_opaque_sp->SetThreadIndex (index);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000239 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000240}
241
242uint32_t
243SBBreakpointLocation::GetThreadIndex() const
244{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000245 uint32_t thread_idx = UINT32_MAX;
Greg Clayton66111032010-06-23 01:19:29 +0000246 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000247 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000248 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000249 return m_opaque_sp->GetThreadIndex();
Jim Ingham62b02c62010-06-18 01:47:08 +0000250 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000251 return thread_idx;
Jim Ingham62b02c62010-06-18 01:47:08 +0000252}
253
254
255void
256SBBreakpointLocation::SetThreadName (const char *thread_name)
257{
Greg Clayton66111032010-06-23 01:19:29 +0000258 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000259 {
260 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000261 m_opaque_sp->SetThreadName (thread_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000262 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000263}
264
265const char *
266SBBreakpointLocation::GetThreadName () const
267{
Greg Clayton66111032010-06-23 01:19:29 +0000268 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000269 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000270 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000271 return m_opaque_sp->GetThreadName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000272 }
273 return NULL;
274}
275
276void
277SBBreakpointLocation::SetQueueName (const char *queue_name)
278{
Greg Clayton66111032010-06-23 01:19:29 +0000279 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000280 {
281 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000282 m_opaque_sp->SetQueueName (queue_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000283 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000284}
285
286const char *
287SBBreakpointLocation::GetQueueName () const
288{
Greg Clayton66111032010-06-23 01:19:29 +0000289 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000290 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000291 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000292 m_opaque_sp->GetQueueName ();
Jim Ingham62b02c62010-06-18 01:47:08 +0000293 }
294 return NULL;
295}
296
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000297bool
298SBBreakpointLocation::IsResolved ()
299{
Greg Clayton66111032010-06-23 01:19:29 +0000300 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000301 {
302 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000303 return m_opaque_sp->IsResolved();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000304 }
305 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306}
307
308void
309SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
310{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000311 // Uninstall the callbacks?
Greg Clayton66111032010-06-23 01:19:29 +0000312 m_opaque_sp = break_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313}
314
Caroline Ticedde9cff2010-09-20 05:20:02 +0000315bool
Johnny Chenfc87e2d2011-04-25 20:23:05 +0000316SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000318 Stream &strm = description.ref();
319
Greg Clayton66111032010-06-23 01:19:29 +0000320 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000322 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000323 m_opaque_sp->GetDescription (&strm, level);
324 strm.EOL();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000326 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000327 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000328
329 return true;
330}
331
Jim Inghamb08a9442012-05-16 00:51:15 +0000332break_id_t
333SBBreakpointLocation::GetID ()
334{
335 if (m_opaque_sp)
336 {
337 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
338 return m_opaque_sp->GetID ();
339 }
340 else
341 return LLDB_INVALID_BREAK_ID;
342}
343
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344SBBreakpoint
345SBBreakpointLocation::GetBreakpoint ()
346{
Greg Clayton5160ce52013-03-27 23:08:40 +0000347 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000348
Caroline Tice750cd172010-10-26 23:49:36 +0000349 //if (log)
350 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000351
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352 SBBreakpoint sb_bp;
Greg Clayton66111032010-06-23 01:19:29 +0000353 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000354 {
355 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Claytone1cd1be2012-01-29 20:56:30 +0000356 *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000357 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000358
359 if (log)
360 {
361 SBStream sstr;
362 sb_bp.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000363 log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
364 static_cast<void*>(m_opaque_sp.get()),
365 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000366 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367 return sb_bp;
368}
369