blob: b2b94484f9c7ef160be91ad5568dd49d6f233426 [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"
49 "=%p) => this.sp = %p (%s)", break_loc_sp.get(), m_opaque_sp.get(), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000050 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051}
52
Greg Claytonefabb122010-11-05 23:17:00 +000053SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
54 m_opaque_sp (rhs.m_opaque_sp)
55{
56}
57
58const SBBreakpointLocation &
59SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
60{
61 if (this != &rhs)
62 m_opaque_sp = rhs.m_opaque_sp;
63 return *this;
64}
65
66
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067SBBreakpointLocation::~SBBreakpointLocation ()
68{
69}
70
71bool
72SBBreakpointLocation::IsValid() const
73{
Greg Clayton66111032010-06-23 01:19:29 +000074 return m_opaque_sp.get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075}
76
Jim Ingham810bf852011-09-24 01:04:57 +000077SBAddress
78SBBreakpointLocation::GetAddress ()
79{
80 if (m_opaque_sp)
81 return SBAddress(&m_opaque_sp->GetAddress());
82 else
83 return SBAddress();
84}
85
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086addr_t
87SBBreakpointLocation::GetLoadAddress ()
88{
89 addr_t ret_addr = LLDB_INVALID_ADDRESS;
90
Greg Clayton66111032010-06-23 01:19:29 +000091 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 {
Greg Claytonaf67cec2010-12-20 20:49:23 +000093 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +000094 ret_addr = m_opaque_sp->GetLoadAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095 }
96
97 return ret_addr;
98}
99
100void
101SBBreakpointLocation::SetEnabled (bool enabled)
102{
Greg Clayton66111032010-06-23 01:19:29 +0000103 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000105 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000106 m_opaque_sp->SetEnabled (enabled);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107 }
108}
109
110bool
111SBBreakpointLocation::IsEnabled ()
112{
Greg Clayton66111032010-06-23 01:19:29 +0000113 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000114 {
115 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000116 return m_opaque_sp->IsEnabled();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000117 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 else
119 return false;
120}
121
Greg Claytonc982c762010-07-09 20:39:50 +0000122uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000123SBBreakpointLocation::GetIgnoreCount ()
124{
Greg Clayton66111032010-06-23 01:19:29 +0000125 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000126 {
127 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000128 return m_opaque_sp->GetIgnoreCount();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000129 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130 else
131 return 0;
132}
133
134void
Greg Claytonc982c762010-07-09 20:39:50 +0000135SBBreakpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136{
Greg Clayton66111032010-06-23 01:19:29 +0000137 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000138 {
139 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000140 m_opaque_sp->SetIgnoreCount (n);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000141 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142}
143
144void
Jim Ingham041a12f2010-10-22 01:15:49 +0000145SBBreakpointLocation::SetCondition (const char *condition)
146{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000147 if (m_opaque_sp)
148 {
149 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
150 m_opaque_sp->SetCondition (condition);
151 }
Jim Ingham041a12f2010-10-22 01:15:49 +0000152}
153
154const char *
155SBBreakpointLocation::GetCondition ()
156{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000157 if (m_opaque_sp)
158 {
159 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
160 return m_opaque_sp->GetConditionText ();
161 }
162 return NULL;
Jim Ingham041a12f2010-10-22 01:15:49 +0000163}
164
165void
Jim Inghamd80102e2014-04-02 01:04:55 +0000166SBBreakpointLocation::SetScriptCallbackFunction (const char *callback_function_name)
167{
168 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
169
170 if (log)
171 log->Printf ("SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)", m_opaque_sp.get(), callback_function_name);
172
173 if (m_opaque_sp)
174 {
175 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
176 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
177 m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options,
178 callback_function_name);
179
180 }
181}
182
183SBError
184SBBreakpointLocation::SetScriptCallbackBody (const char *callback_body_text)
185{
186 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
187
188 if (log)
189 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", m_opaque_sp.get(), callback_body_text);
190
191 SBError sb_error;
192 if (m_opaque_sp)
193 {
194 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
195 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
196 Error error = m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
197 callback_body_text);
198 sb_error.SetError(error);
199 }
200 else
201 sb_error.SetErrorString("invalid breakpoint");
202
203 return sb_error;
204}
205
206void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207SBBreakpointLocation::SetThreadID (tid_t thread_id)
208{
Greg Clayton66111032010-06-23 01:19:29 +0000209 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000210 {
211 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000212 m_opaque_sp->SetThreadID (thread_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216tid_t
217SBBreakpointLocation::GetThreadID ()
218{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000219 tid_t tid = LLDB_INVALID_THREAD_ID;
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->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000223 return m_opaque_sp->GetThreadID();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000224 }
225 return tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226}
227
Jim Ingham62b02c62010-06-18 01:47:08 +0000228void
229SBBreakpointLocation::SetThreadIndex (uint32_t index)
230{
Greg Clayton66111032010-06-23 01:19:29 +0000231 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000232 {
233 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000234 m_opaque_sp->SetThreadIndex (index);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000235 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000236}
237
238uint32_t
239SBBreakpointLocation::GetThreadIndex() const
240{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000241 uint32_t thread_idx = UINT32_MAX;
Greg Clayton66111032010-06-23 01:19:29 +0000242 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000243 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000244 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000245 return m_opaque_sp->GetThreadIndex();
Jim Ingham62b02c62010-06-18 01:47:08 +0000246 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000247 return thread_idx;
Jim Ingham62b02c62010-06-18 01:47:08 +0000248}
249
250
251void
252SBBreakpointLocation::SetThreadName (const char *thread_name)
253{
Greg Clayton66111032010-06-23 01:19:29 +0000254 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000255 {
256 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000257 m_opaque_sp->SetThreadName (thread_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000258 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000259}
260
261const char *
262SBBreakpointLocation::GetThreadName () const
263{
Greg Clayton66111032010-06-23 01:19:29 +0000264 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000265 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000266 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000267 return m_opaque_sp->GetThreadName();
Jim Ingham62b02c62010-06-18 01:47:08 +0000268 }
269 return NULL;
270}
271
272void
273SBBreakpointLocation::SetQueueName (const char *queue_name)
274{
Greg Clayton66111032010-06-23 01:19:29 +0000275 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000276 {
277 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000278 m_opaque_sp->SetQueueName (queue_name);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000279 }
Jim Ingham62b02c62010-06-18 01:47:08 +0000280}
281
282const char *
283SBBreakpointLocation::GetQueueName () const
284{
Greg Clayton66111032010-06-23 01:19:29 +0000285 if (m_opaque_sp)
Jim Ingham62b02c62010-06-18 01:47:08 +0000286 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000287 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000288 m_opaque_sp->GetQueueName ();
Jim Ingham62b02c62010-06-18 01:47:08 +0000289 }
290 return NULL;
291}
292
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293bool
294SBBreakpointLocation::IsResolved ()
295{
Greg Clayton66111032010-06-23 01:19:29 +0000296 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000297 {
298 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000299 return m_opaque_sp->IsResolved();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000300 }
301 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302}
303
304void
305SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
306{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000307 // Uninstall the callbacks?
Greg Clayton66111032010-06-23 01:19:29 +0000308 m_opaque_sp = break_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309}
310
Caroline Ticedde9cff2010-09-20 05:20:02 +0000311bool
Johnny Chenfc87e2d2011-04-25 20:23:05 +0000312SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000314 Stream &strm = description.ref();
315
Greg Clayton66111032010-06-23 01:19:29 +0000316 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000318 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000319 m_opaque_sp->GetDescription (&strm, level);
320 strm.EOL();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000322 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000323 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000324
325 return true;
326}
327
Jim Inghamb08a9442012-05-16 00:51:15 +0000328break_id_t
329SBBreakpointLocation::GetID ()
330{
331 if (m_opaque_sp)
332 {
333 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
334 return m_opaque_sp->GetID ();
335 }
336 else
337 return LLDB_INVALID_BREAK_ID;
338}
339
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340SBBreakpoint
341SBBreakpointLocation::GetBreakpoint ()
342{
Greg Clayton5160ce52013-03-27 23:08:40 +0000343 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000344
Caroline Tice750cd172010-10-26 23:49:36 +0000345 //if (log)
346 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000347
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348 SBBreakpoint sb_bp;
Greg Clayton66111032010-06-23 01:19:29 +0000349 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000350 {
351 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
Greg Claytone1cd1be2012-01-29 20:56:30 +0000352 *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000353 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000354
355 if (log)
356 {
357 SBStream sstr;
358 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000359 log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
Caroline Tice750cd172010-10-26 23:49:36 +0000360 m_opaque_sp.get(), sb_bp.get(), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000361 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362 return sb_bp;
363}
364