1 //===-- SBBreakpointLocation.cpp --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBBreakpointLocation.h"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBDebugger.h"
13 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBStream.h"
16 #include "lldb/Breakpoint/Breakpoint.h"
17 #include "lldb/Breakpoint/BreakpointLocation.h"
18 #include "lldb/Core/Debugger.h"
19 #include "lldb/Core/Log.h"
20 #include "lldb/Core/Stream.h"
21 #include "lldb/Core/StreamFile.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Interpreter/ScriptInterpreter.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Target/ThreadSpec.h"
26 #include "lldb/Target/ThreadSpec.h"
27 #include "lldb/lldb-defines.h"
28 #include "lldb/lldb-types.h"
31 using namespace lldb_private;
33 SBBreakpointLocation::SBBreakpointLocation() : m_opaque_sp() {}
35 SBBreakpointLocation::SBBreakpointLocation(
36 const lldb::BreakpointLocationSP &break_loc_sp)
37 : m_opaque_sp(break_loc_sp) {
38 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
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());
51 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
52 : m_opaque_sp(rhs.m_opaque_sp) {}
54 const SBBreakpointLocation &SBBreakpointLocation::
55 operator=(const SBBreakpointLocation &rhs) {
57 m_opaque_sp = rhs.m_opaque_sp;
61 SBBreakpointLocation::~SBBreakpointLocation() {}
63 bool SBBreakpointLocation::IsValid() const { return m_opaque_sp.get() != NULL; }
65 SBAddress SBBreakpointLocation::GetAddress() {
67 return SBAddress(&m_opaque_sp->GetAddress());
72 addr_t SBBreakpointLocation::GetLoadAddress() {
73 addr_t ret_addr = LLDB_INVALID_ADDRESS;
76 std::lock_guard<std::recursive_mutex> guard(
77 m_opaque_sp->GetTarget().GetAPIMutex());
78 ret_addr = m_opaque_sp->GetLoadAddress();
84 void SBBreakpointLocation::SetEnabled(bool enabled) {
86 std::lock_guard<std::recursive_mutex> guard(
87 m_opaque_sp->GetTarget().GetAPIMutex());
88 m_opaque_sp->SetEnabled(enabled);
92 bool SBBreakpointLocation::IsEnabled() {
94 std::lock_guard<std::recursive_mutex> guard(
95 m_opaque_sp->GetTarget().GetAPIMutex());
96 return m_opaque_sp->IsEnabled();
101 uint32_t SBBreakpointLocation::GetIgnoreCount() {
103 std::lock_guard<std::recursive_mutex> guard(
104 m_opaque_sp->GetTarget().GetAPIMutex());
105 return m_opaque_sp->GetIgnoreCount();
110 void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
112 std::lock_guard<std::recursive_mutex> guard(
113 m_opaque_sp->GetTarget().GetAPIMutex());
114 m_opaque_sp->SetIgnoreCount(n);
118 void SBBreakpointLocation::SetCondition(const char *condition) {
120 std::lock_guard<std::recursive_mutex> guard(
121 m_opaque_sp->GetTarget().GetAPIMutex());
122 m_opaque_sp->SetCondition(condition);
126 const char *SBBreakpointLocation::GetCondition() {
128 std::lock_guard<std::recursive_mutex> guard(
129 m_opaque_sp->GetTarget().GetAPIMutex());
130 return m_opaque_sp->GetConditionText();
135 void SBBreakpointLocation::SetScriptCallbackFunction(
136 const char *callback_function_name) {
137 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
141 "SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)",
142 static_cast<void *>(m_opaque_sp.get()), callback_function_name);
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()
151 .GetCommandInterpreter()
152 .GetScriptInterpreter()
153 ->SetBreakpointCommandCallbackFunction(bp_options,
154 callback_function_name);
159 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
160 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
163 log->Printf("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
164 static_cast<void *>(m_opaque_sp.get()), callback_body_text);
168 std::lock_guard<std::recursive_mutex> guard(
169 m_opaque_sp->GetTarget().GetAPIMutex());
170 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
172 m_opaque_sp->GetBreakpoint()
175 .GetCommandInterpreter()
176 .GetScriptInterpreter()
177 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
178 sb_error.SetError(error);
180 sb_error.SetErrorString("invalid breakpoint");
185 void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
187 std::lock_guard<std::recursive_mutex> guard(
188 m_opaque_sp->GetTarget().GetAPIMutex());
189 m_opaque_sp->SetThreadID(thread_id);
193 tid_t SBBreakpointLocation::GetThreadID() {
194 tid_t tid = LLDB_INVALID_THREAD_ID;
196 std::lock_guard<std::recursive_mutex> guard(
197 m_opaque_sp->GetTarget().GetAPIMutex());
198 return m_opaque_sp->GetThreadID();
203 void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
205 std::lock_guard<std::recursive_mutex> guard(
206 m_opaque_sp->GetTarget().GetAPIMutex());
207 m_opaque_sp->SetThreadIndex(index);
211 uint32_t SBBreakpointLocation::GetThreadIndex() const {
212 uint32_t thread_idx = UINT32_MAX;
214 std::lock_guard<std::recursive_mutex> guard(
215 m_opaque_sp->GetTarget().GetAPIMutex());
216 return m_opaque_sp->GetThreadIndex();
221 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
223 std::lock_guard<std::recursive_mutex> guard(
224 m_opaque_sp->GetTarget().GetAPIMutex());
225 m_opaque_sp->SetThreadName(thread_name);
229 const char *SBBreakpointLocation::GetThreadName() const {
231 std::lock_guard<std::recursive_mutex> guard(
232 m_opaque_sp->GetTarget().GetAPIMutex());
233 return m_opaque_sp->GetThreadName();
238 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
240 std::lock_guard<std::recursive_mutex> guard(
241 m_opaque_sp->GetTarget().GetAPIMutex());
242 m_opaque_sp->SetQueueName(queue_name);
246 const char *SBBreakpointLocation::GetQueueName() const {
248 std::lock_guard<std::recursive_mutex> guard(
249 m_opaque_sp->GetTarget().GetAPIMutex());
250 m_opaque_sp->GetQueueName();
255 bool SBBreakpointLocation::IsResolved() {
257 std::lock_guard<std::recursive_mutex> guard(
258 m_opaque_sp->GetTarget().GetAPIMutex());
259 return m_opaque_sp->IsResolved();
264 void SBBreakpointLocation::SetLocation(
265 const lldb::BreakpointLocationSP &break_loc_sp) {
266 // Uninstall the callbacks?
267 m_opaque_sp = break_loc_sp;
270 bool SBBreakpointLocation::GetDescription(SBStream &description,
271 DescriptionLevel level) {
272 Stream &strm = description.ref();
275 std::lock_guard<std::recursive_mutex> guard(
276 m_opaque_sp->GetTarget().GetAPIMutex());
277 m_opaque_sp->GetDescription(&strm, level);
280 strm.PutCString("No value");
285 break_id_t SBBreakpointLocation::GetID() {
287 std::lock_guard<std::recursive_mutex> guard(
288 m_opaque_sp->GetTarget().GetAPIMutex());
289 return m_opaque_sp->GetID();
291 return LLDB_INVALID_BREAK_ID;
294 SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
295 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
298 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
302 std::lock_guard<std::recursive_mutex> guard(
303 m_opaque_sp->GetTarget().GetAPIMutex());
304 *sb_bp = m_opaque_sp->GetBreakpoint().shared_from_this();
309 sb_bp.GetDescription(sstr);
311 "SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
312 static_cast<void *>(m_opaque_sp.get()),
313 static_cast<void *>(sb_bp.get()), sstr.GetData());