blob: c7fac7688f830d7f658fc54b6db6496b3a00fea9 [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"
Greg Claytonf644ddf2011-09-24 01:37:21 +000011#include "lldb/API/SBAddress.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/API/SBDebugger.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000013#include "lldb/API/SBDefines.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Clayton4e78f602010-11-18 18:52:36 +000016#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000018#include "lldb/Core/Debugger.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000019#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Stream.h"
21#include "lldb/Core/StreamFile.h"
Jim Inghamd80102e2014-04-02 01:04:55 +000022#include "lldb/Interpreter/CommandInterpreter.h"
23#include "lldb/Interpreter/ScriptInterpreter.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000024#include "lldb/Target/Target.h"
Jim Ingham62b02c62010-06-18 01:47:08 +000025#include "lldb/Target/ThreadSpec.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000026#include "lldb/Target/ThreadSpec.h"
27#include "lldb/lldb-defines.h"
28#include "lldb/lldb-types.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
30using namespace lldb;
31using namespace lldb_private;
32
Kate Stoneb9c1b512016-09-06 20:57:50 +000033SBBreakpointLocation::SBBreakpointLocation() : m_opaque_sp() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035SBBreakpointLocation::SBBreakpointLocation(
36 const lldb::BreakpointLocationSP &break_loc_sp)
37 : m_opaque_sp(break_loc_sp) {
38 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
39
40 if (log) {
41 SBStream sstr;
42 GetDescription(sstr, lldb::eDescriptionLevelBrief);
43 log->Printf("SBBreakpointLocation::SBBreakpointLocaiton (const "
44 "lldb::BreakpointLocationsSP &break_loc_sp"
45 "=%p) => this.sp = %p (%s)",
46 static_cast<void *>(break_loc_sp.get()),
47 static_cast<void *>(m_opaque_sp.get()), sstr.GetData());
48 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049}
50
Kate Stoneb9c1b512016-09-06 20:57:50 +000051SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
52 : m_opaque_sp(rhs.m_opaque_sp) {}
Caroline Ticeceb6b132010-10-26 03:11:13 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054const SBBreakpointLocation &SBBreakpointLocation::
55operator=(const SBBreakpointLocation &rhs) {
56 if (this != &rhs)
57 m_opaque_sp = rhs.m_opaque_sp;
58 return *this;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059}
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061SBBreakpointLocation::~SBBreakpointLocation() {}
62
63bool SBBreakpointLocation::IsValid() const { return m_opaque_sp.get() != NULL; }
64
65SBAddress SBBreakpointLocation::GetAddress() {
66 if (m_opaque_sp)
67 return SBAddress(&m_opaque_sp->GetAddress());
68 else
69 return SBAddress();
Greg Claytonefabb122010-11-05 23:17:00 +000070}
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072addr_t SBBreakpointLocation::GetLoadAddress() {
73 addr_t ret_addr = LLDB_INVALID_ADDRESS;
74
75 if (m_opaque_sp) {
76 std::lock_guard<std::recursive_mutex> guard(
77 m_opaque_sp->GetTarget().GetAPIMutex());
78 ret_addr = m_opaque_sp->GetLoadAddress();
79 }
80
81 return ret_addr;
Greg Claytonefabb122010-11-05 23:17:00 +000082}
83
Kate Stoneb9c1b512016-09-06 20:57:50 +000084void SBBreakpointLocation::SetEnabled(bool enabled) {
85 if (m_opaque_sp) {
86 std::lock_guard<std::recursive_mutex> guard(
87 m_opaque_sp->GetTarget().GetAPIMutex());
88 m_opaque_sp->SetEnabled(enabled);
89 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090}
91
Kate Stoneb9c1b512016-09-06 20:57:50 +000092bool SBBreakpointLocation::IsEnabled() {
93 if (m_opaque_sp) {
94 std::lock_guard<std::recursive_mutex> guard(
95 m_opaque_sp->GetTarget().GetAPIMutex());
96 return m_opaque_sp->IsEnabled();
97 } else
Greg Claytonaf67cec2010-12-20 20:49:23 +000098 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099}
100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101uint32_t SBBreakpointLocation::GetIgnoreCount() {
102 if (m_opaque_sp) {
103 std::lock_guard<std::recursive_mutex> guard(
104 m_opaque_sp->GetTarget().GetAPIMutex());
105 return m_opaque_sp->GetIgnoreCount();
106 } else
107 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108}
109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
111 if (m_opaque_sp) {
112 std::lock_guard<std::recursive_mutex> guard(
113 m_opaque_sp->GetTarget().GetAPIMutex());
114 m_opaque_sp->SetIgnoreCount(n);
115 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000116}
117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118void SBBreakpointLocation::SetCondition(const char *condition) {
119 if (m_opaque_sp) {
120 std::lock_guard<std::recursive_mutex> guard(
121 m_opaque_sp->GetTarget().GetAPIMutex());
122 m_opaque_sp->SetCondition(condition);
123 }
Jim Inghamb08a9442012-05-16 00:51:15 +0000124}
125
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126const char *SBBreakpointLocation::GetCondition() {
127 if (m_opaque_sp) {
128 std::lock_guard<std::recursive_mutex> guard(
129 m_opaque_sp->GetTarget().GetAPIMutex());
130 return m_opaque_sp->GetConditionText();
131 }
132 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133}
134
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135void SBBreakpointLocation::SetScriptCallbackFunction(
136 const char *callback_function_name) {
137 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
138
139 if (log)
140 log->Printf(
141 "SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)",
142 static_cast<void *>(m_opaque_sp.get()), callback_function_name);
143
144 if (m_opaque_sp) {
145 std::lock_guard<std::recursive_mutex> guard(
146 m_opaque_sp->GetTarget().GetAPIMutex());
147 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
148 m_opaque_sp->GetBreakpoint()
149 .GetTarget()
150 .GetDebugger()
151 .GetCommandInterpreter()
152 .GetScriptInterpreter()
153 ->SetBreakpointCommandCallbackFunction(bp_options,
154 callback_function_name);
155 }
156}
157
158SBError
159SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
160 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
161
162 if (log)
163 log->Printf("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
164 static_cast<void *>(m_opaque_sp.get()), callback_body_text);
165
166 SBError sb_error;
167 if (m_opaque_sp) {
168 std::lock_guard<std::recursive_mutex> guard(
169 m_opaque_sp->GetTarget().GetAPIMutex());
170 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
171 Error error =
172 m_opaque_sp->GetBreakpoint()
173 .GetTarget()
174 .GetDebugger()
175 .GetCommandInterpreter()
176 .GetScriptInterpreter()
177 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
178 sb_error.SetError(error);
179 } else
180 sb_error.SetErrorString("invalid breakpoint");
181
182 return sb_error;
183}
184
185void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
186 if (m_opaque_sp) {
187 std::lock_guard<std::recursive_mutex> guard(
188 m_opaque_sp->GetTarget().GetAPIMutex());
189 m_opaque_sp->SetThreadID(thread_id);
190 }
191}
192
193tid_t SBBreakpointLocation::GetThreadID() {
194 tid_t tid = LLDB_INVALID_THREAD_ID;
195 if (m_opaque_sp) {
196 std::lock_guard<std::recursive_mutex> guard(
197 m_opaque_sp->GetTarget().GetAPIMutex());
198 return m_opaque_sp->GetThreadID();
199 }
200 return tid;
201}
202
203void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
204 if (m_opaque_sp) {
205 std::lock_guard<std::recursive_mutex> guard(
206 m_opaque_sp->GetTarget().GetAPIMutex());
207 m_opaque_sp->SetThreadIndex(index);
208 }
209}
210
211uint32_t SBBreakpointLocation::GetThreadIndex() const {
212 uint32_t thread_idx = UINT32_MAX;
213 if (m_opaque_sp) {
214 std::lock_guard<std::recursive_mutex> guard(
215 m_opaque_sp->GetTarget().GetAPIMutex());
216 return m_opaque_sp->GetThreadIndex();
217 }
218 return thread_idx;
219}
220
221void SBBreakpointLocation::SetThreadName(const char *thread_name) {
222 if (m_opaque_sp) {
223 std::lock_guard<std::recursive_mutex> guard(
224 m_opaque_sp->GetTarget().GetAPIMutex());
225 m_opaque_sp->SetThreadName(thread_name);
226 }
227}
228
229const char *SBBreakpointLocation::GetThreadName() const {
230 if (m_opaque_sp) {
231 std::lock_guard<std::recursive_mutex> guard(
232 m_opaque_sp->GetTarget().GetAPIMutex());
233 return m_opaque_sp->GetThreadName();
234 }
235 return NULL;
236}
237
238void SBBreakpointLocation::SetQueueName(const char *queue_name) {
239 if (m_opaque_sp) {
240 std::lock_guard<std::recursive_mutex> guard(
241 m_opaque_sp->GetTarget().GetAPIMutex());
242 m_opaque_sp->SetQueueName(queue_name);
243 }
244}
245
246const char *SBBreakpointLocation::GetQueueName() const {
247 if (m_opaque_sp) {
248 std::lock_guard<std::recursive_mutex> guard(
249 m_opaque_sp->GetTarget().GetAPIMutex());
250 m_opaque_sp->GetQueueName();
251 }
252 return NULL;
253}
254
255bool SBBreakpointLocation::IsResolved() {
256 if (m_opaque_sp) {
257 std::lock_guard<std::recursive_mutex> guard(
258 m_opaque_sp->GetTarget().GetAPIMutex());
259 return m_opaque_sp->IsResolved();
260 }
261 return false;
262}
263
264void SBBreakpointLocation::SetLocation(
265 const lldb::BreakpointLocationSP &break_loc_sp) {
266 // Uninstall the callbacks?
267 m_opaque_sp = break_loc_sp;
268}
269
270bool SBBreakpointLocation::GetDescription(SBStream &description,
271 DescriptionLevel level) {
272 Stream &strm = description.ref();
273
274 if (m_opaque_sp) {
275 std::lock_guard<std::recursive_mutex> guard(
276 m_opaque_sp->GetTarget().GetAPIMutex());
277 m_opaque_sp->GetDescription(&strm, level);
278 strm.EOL();
279 } else
280 strm.PutCString("No value");
281
282 return true;
283}
284
285break_id_t SBBreakpointLocation::GetID() {
286 if (m_opaque_sp) {
287 std::lock_guard<std::recursive_mutex> guard(
288 m_opaque_sp->GetTarget().GetAPIMutex());
289 return m_opaque_sp->GetID();
290 } else
291 return LLDB_INVALID_BREAK_ID;
292}
293
294SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
295 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
296
297 // if (log)
298 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
299
300 SBBreakpoint sb_bp;
301 if (m_opaque_sp) {
302 std::lock_guard<std::recursive_mutex> guard(
303 m_opaque_sp->GetTarget().GetAPIMutex());
304 *sb_bp = m_opaque_sp->GetBreakpoint().shared_from_this();
305 }
306
307 if (log) {
308 SBStream sstr;
309 sb_bp.GetDescription(sstr);
310 log->Printf(
311 "SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
312 static_cast<void *>(m_opaque_sp.get()),
313 static_cast<void *>(sb_bp.get()), sstr.GetData());
314 }
315 return sb_bp;
316}