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/StreamFile.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Interpreter/ScriptInterpreter.h"
22 #include "lldb/Target/Target.h"
23 #include "lldb/Target/ThreadSpec.h"
24 #include "lldb/Utility/Log.h"
25 #include "lldb/Utility/Stream.h"
26 #include "lldb/lldb-defines.h"
27 #include "lldb/lldb-types.h"
30 using namespace lldb_private;
32 SBBreakpointLocation::SBBreakpointLocation() {}
34 SBBreakpointLocation::SBBreakpointLocation(
35 const lldb::BreakpointLocationSP &break_loc_sp)
36 : m_opaque_wp(break_loc_sp) {
37 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
41 GetDescription(sstr, lldb::eDescriptionLevelBrief);
42 LLDB_LOG(log, "location = {0} ({1})", break_loc_sp.get(), sstr.GetData());
46 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
47 : m_opaque_wp(rhs.m_opaque_wp) {}
49 const SBBreakpointLocation &SBBreakpointLocation::
50 operator=(const SBBreakpointLocation &rhs) {
51 m_opaque_wp = rhs.m_opaque_wp;
55 SBBreakpointLocation::~SBBreakpointLocation() {}
57 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
58 return m_opaque_wp.lock();
61 bool SBBreakpointLocation::IsValid() const { return bool(GetSP()); }
63 SBAddress SBBreakpointLocation::GetAddress() {
64 BreakpointLocationSP loc_sp = GetSP();
66 return SBAddress(&loc_sp->GetAddress());
71 addr_t SBBreakpointLocation::GetLoadAddress() {
72 addr_t ret_addr = LLDB_INVALID_ADDRESS;
73 BreakpointLocationSP loc_sp = GetSP();
76 std::lock_guard<std::recursive_mutex> guard(
77 loc_sp->GetTarget().GetAPIMutex());
78 ret_addr = loc_sp->GetLoadAddress();
84 void SBBreakpointLocation::SetEnabled(bool enabled) {
85 BreakpointLocationSP loc_sp = GetSP();
87 std::lock_guard<std::recursive_mutex> guard(
88 loc_sp->GetTarget().GetAPIMutex());
89 loc_sp->SetEnabled(enabled);
93 bool SBBreakpointLocation::IsEnabled() {
94 BreakpointLocationSP loc_sp = GetSP();
96 std::lock_guard<std::recursive_mutex> guard(
97 loc_sp->GetTarget().GetAPIMutex());
98 return loc_sp->IsEnabled();
103 uint32_t SBBreakpointLocation::GetIgnoreCount() {
104 BreakpointLocationSP loc_sp = GetSP();
106 std::lock_guard<std::recursive_mutex> guard(
107 loc_sp->GetTarget().GetAPIMutex());
108 return loc_sp->GetIgnoreCount();
113 void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
114 BreakpointLocationSP loc_sp = GetSP();
116 std::lock_guard<std::recursive_mutex> guard(
117 loc_sp->GetTarget().GetAPIMutex());
118 loc_sp->SetIgnoreCount(n);
122 void SBBreakpointLocation::SetCondition(const char *condition) {
123 BreakpointLocationSP loc_sp = GetSP();
125 std::lock_guard<std::recursive_mutex> guard(
126 loc_sp->GetTarget().GetAPIMutex());
127 loc_sp->SetCondition(condition);
131 const char *SBBreakpointLocation::GetCondition() {
132 BreakpointLocationSP loc_sp = GetSP();
134 std::lock_guard<std::recursive_mutex> guard(
135 loc_sp->GetTarget().GetAPIMutex());
136 return loc_sp->GetConditionText();
141 void SBBreakpointLocation::SetScriptCallbackFunction(
142 const char *callback_function_name) {
143 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
144 BreakpointLocationSP loc_sp = GetSP();
145 LLDB_LOG(log, "location = {0}, callback = {1}", loc_sp.get(),
146 callback_function_name);
149 std::lock_guard<std::recursive_mutex> guard(
150 loc_sp->GetTarget().GetAPIMutex());
151 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
152 loc_sp->GetBreakpoint()
155 .GetCommandInterpreter()
156 .GetScriptInterpreter()
157 ->SetBreakpointCommandCallbackFunction(bp_options,
158 callback_function_name);
163 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
164 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
165 BreakpointLocationSP loc_sp = GetSP();
166 LLDB_LOG(log, "location = {0}: callback body:\n{1}", loc_sp.get(),
171 std::lock_guard<std::recursive_mutex> guard(
172 loc_sp->GetTarget().GetAPIMutex());
173 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
175 loc_sp->GetBreakpoint()
178 .GetCommandInterpreter()
179 .GetScriptInterpreter()
180 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
181 sb_error.SetError(error);
183 sb_error.SetErrorString("invalid breakpoint");
188 void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
189 BreakpointLocationSP loc_sp = GetSP();
191 std::lock_guard<std::recursive_mutex> guard(
192 loc_sp->GetTarget().GetAPIMutex());
193 loc_sp->SetThreadID(thread_id);
197 tid_t SBBreakpointLocation::GetThreadID() {
198 tid_t tid = LLDB_INVALID_THREAD_ID;
199 BreakpointLocationSP loc_sp = GetSP();
201 std::lock_guard<std::recursive_mutex> guard(
202 loc_sp->GetTarget().GetAPIMutex());
203 return loc_sp->GetThreadID();
208 void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
209 BreakpointLocationSP loc_sp = GetSP();
211 std::lock_guard<std::recursive_mutex> guard(
212 loc_sp->GetTarget().GetAPIMutex());
213 loc_sp->SetThreadIndex(index);
217 uint32_t SBBreakpointLocation::GetThreadIndex() const {
218 uint32_t thread_idx = UINT32_MAX;
219 BreakpointLocationSP loc_sp = GetSP();
221 std::lock_guard<std::recursive_mutex> guard(
222 loc_sp->GetTarget().GetAPIMutex());
223 return loc_sp->GetThreadIndex();
228 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
229 BreakpointLocationSP loc_sp = GetSP();
231 std::lock_guard<std::recursive_mutex> guard(
232 loc_sp->GetTarget().GetAPIMutex());
233 loc_sp->SetThreadName(thread_name);
237 const char *SBBreakpointLocation::GetThreadName() const {
238 BreakpointLocationSP loc_sp = GetSP();
240 std::lock_guard<std::recursive_mutex> guard(
241 loc_sp->GetTarget().GetAPIMutex());
242 return loc_sp->GetThreadName();
247 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
248 BreakpointLocationSP loc_sp = GetSP();
250 std::lock_guard<std::recursive_mutex> guard(
251 loc_sp->GetTarget().GetAPIMutex());
252 loc_sp->SetQueueName(queue_name);
256 const char *SBBreakpointLocation::GetQueueName() const {
257 BreakpointLocationSP loc_sp = GetSP();
259 std::lock_guard<std::recursive_mutex> guard(
260 loc_sp->GetTarget().GetAPIMutex());
261 loc_sp->GetQueueName();
266 bool SBBreakpointLocation::IsResolved() {
267 BreakpointLocationSP loc_sp = GetSP();
269 std::lock_guard<std::recursive_mutex> guard(
270 loc_sp->GetTarget().GetAPIMutex());
271 return loc_sp->IsResolved();
276 void SBBreakpointLocation::SetLocation(
277 const lldb::BreakpointLocationSP &break_loc_sp) {
278 // Uninstall the callbacks?
279 m_opaque_wp = break_loc_sp;
282 bool SBBreakpointLocation::GetDescription(SBStream &description,
283 DescriptionLevel level) {
284 Stream &strm = description.ref();
285 BreakpointLocationSP loc_sp = GetSP();
288 std::lock_guard<std::recursive_mutex> guard(
289 loc_sp->GetTarget().GetAPIMutex());
290 loc_sp->GetDescription(&strm, level);
293 strm.PutCString("No value");
298 break_id_t SBBreakpointLocation::GetID() {
299 BreakpointLocationSP loc_sp = GetSP();
301 std::lock_guard<std::recursive_mutex> guard(
302 loc_sp->GetTarget().GetAPIMutex());
303 return loc_sp->GetID();
305 return LLDB_INVALID_BREAK_ID;
308 SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
309 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
310 BreakpointLocationSP loc_sp = GetSP();
314 std::lock_guard<std::recursive_mutex> guard(
315 loc_sp->GetTarget().GetAPIMutex());
316 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
321 sb_bp.GetDescription(sstr);
322 LLDB_LOG(log, "location = {0}, breakpoint = {1} ({2})", loc_sp.get(),
323 sb_bp.GetSP().get(), sstr.GetData());