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"
15 #include "lldb/API/SBStringList.h"
17 #include "lldb/Breakpoint/Breakpoint.h"
18 #include "lldb/Breakpoint/BreakpointLocation.h"
19 #include "lldb/Core/Debugger.h"
20 #include "lldb/Core/StreamFile.h"
21 #include "lldb/Interpreter/CommandInterpreter.h"
22 #include "lldb/Interpreter/ScriptInterpreter.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/ThreadSpec.h"
25 #include "lldb/Utility/Log.h"
26 #include "lldb/Utility/Stream.h"
27 #include "lldb/lldb-defines.h"
28 #include "lldb/lldb-types.h"
31 using namespace lldb_private;
33 SBBreakpointLocation::SBBreakpointLocation() {}
35 SBBreakpointLocation::SBBreakpointLocation(
36 const lldb::BreakpointLocationSP &break_loc_sp)
37 : m_opaque_wp(break_loc_sp) {
38 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
42 GetDescription(sstr, lldb::eDescriptionLevelBrief);
43 LLDB_LOG(log, "location = {0} ({1})", break_loc_sp.get(), sstr.GetData());
47 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
48 : m_opaque_wp(rhs.m_opaque_wp) {}
50 const SBBreakpointLocation &SBBreakpointLocation::
51 operator=(const SBBreakpointLocation &rhs) {
52 m_opaque_wp = rhs.m_opaque_wp;
56 SBBreakpointLocation::~SBBreakpointLocation() {}
58 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
59 return m_opaque_wp.lock();
62 bool SBBreakpointLocation::IsValid() const { return bool(GetSP()); }
64 SBAddress SBBreakpointLocation::GetAddress() {
65 BreakpointLocationSP loc_sp = GetSP();
67 return SBAddress(&loc_sp->GetAddress());
72 addr_t SBBreakpointLocation::GetLoadAddress() {
73 addr_t ret_addr = LLDB_INVALID_ADDRESS;
74 BreakpointLocationSP loc_sp = GetSP();
77 std::lock_guard<std::recursive_mutex> guard(
78 loc_sp->GetTarget().GetAPIMutex());
79 ret_addr = loc_sp->GetLoadAddress();
85 void SBBreakpointLocation::SetEnabled(bool enabled) {
86 BreakpointLocationSP loc_sp = GetSP();
88 std::lock_guard<std::recursive_mutex> guard(
89 loc_sp->GetTarget().GetAPIMutex());
90 loc_sp->SetEnabled(enabled);
94 bool SBBreakpointLocation::IsEnabled() {
95 BreakpointLocationSP loc_sp = GetSP();
97 std::lock_guard<std::recursive_mutex> guard(
98 loc_sp->GetTarget().GetAPIMutex());
99 return loc_sp->IsEnabled();
104 uint32_t SBBreakpointLocation::GetHitCount() {
105 BreakpointLocationSP loc_sp = GetSP();
107 std::lock_guard<std::recursive_mutex> guard(
108 loc_sp->GetTarget().GetAPIMutex());
109 return loc_sp->GetHitCount();
114 uint32_t SBBreakpointLocation::GetIgnoreCount() {
115 BreakpointLocationSP loc_sp = GetSP();
117 std::lock_guard<std::recursive_mutex> guard(
118 loc_sp->GetTarget().GetAPIMutex());
119 return loc_sp->GetIgnoreCount();
124 void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
125 BreakpointLocationSP loc_sp = GetSP();
127 std::lock_guard<std::recursive_mutex> guard(
128 loc_sp->GetTarget().GetAPIMutex());
129 loc_sp->SetIgnoreCount(n);
133 void SBBreakpointLocation::SetCondition(const char *condition) {
134 BreakpointLocationSP loc_sp = GetSP();
136 std::lock_guard<std::recursive_mutex> guard(
137 loc_sp->GetTarget().GetAPIMutex());
138 loc_sp->SetCondition(condition);
142 const char *SBBreakpointLocation::GetCondition() {
143 BreakpointLocationSP loc_sp = GetSP();
145 std::lock_guard<std::recursive_mutex> guard(
146 loc_sp->GetTarget().GetAPIMutex());
147 return loc_sp->GetConditionText();
152 void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
153 BreakpointLocationSP loc_sp = GetSP();
155 std::lock_guard<std::recursive_mutex> guard(
156 loc_sp->GetTarget().GetAPIMutex());
157 loc_sp->SetAutoContinue(auto_continue);
161 bool SBBreakpointLocation::GetAutoContinue() {
162 BreakpointLocationSP loc_sp = GetSP();
164 std::lock_guard<std::recursive_mutex> guard(
165 loc_sp->GetTarget().GetAPIMutex());
166 return loc_sp->IsAutoContinue();
171 void SBBreakpointLocation::SetScriptCallbackFunction(
172 const char *callback_function_name) {
173 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
174 BreakpointLocationSP loc_sp = GetSP();
175 LLDB_LOG(log, "location = {0}, callback = {1}", loc_sp.get(),
176 callback_function_name);
179 std::lock_guard<std::recursive_mutex> guard(
180 loc_sp->GetTarget().GetAPIMutex());
181 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
182 loc_sp->GetBreakpoint()
185 .GetCommandInterpreter()
186 .GetScriptInterpreter()
187 ->SetBreakpointCommandCallbackFunction(bp_options,
188 callback_function_name);
193 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
194 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
195 BreakpointLocationSP loc_sp = GetSP();
196 LLDB_LOG(log, "location = {0}: callback body:\n{1}", loc_sp.get(),
201 std::lock_guard<std::recursive_mutex> guard(
202 loc_sp->GetTarget().GetAPIMutex());
203 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
205 loc_sp->GetBreakpoint()
208 .GetCommandInterpreter()
209 .GetScriptInterpreter()
210 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
211 sb_error.SetError(error);
213 sb_error.SetErrorString("invalid breakpoint");
218 void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
219 BreakpointLocationSP loc_sp = GetSP();
222 if (commands.GetSize() == 0)
225 std::lock_guard<std::recursive_mutex> guard(
226 loc_sp->GetTarget().GetAPIMutex());
227 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
228 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
230 loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
233 bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
234 BreakpointLocationSP loc_sp = GetSP();
237 StringList command_list;
239 loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
241 commands.AppendList(command_list);
245 void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
246 BreakpointLocationSP loc_sp = GetSP();
248 std::lock_guard<std::recursive_mutex> guard(
249 loc_sp->GetTarget().GetAPIMutex());
250 loc_sp->SetThreadID(thread_id);
254 tid_t SBBreakpointLocation::GetThreadID() {
255 tid_t tid = LLDB_INVALID_THREAD_ID;
256 BreakpointLocationSP loc_sp = GetSP();
258 std::lock_guard<std::recursive_mutex> guard(
259 loc_sp->GetTarget().GetAPIMutex());
260 return loc_sp->GetThreadID();
265 void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
266 BreakpointLocationSP loc_sp = GetSP();
268 std::lock_guard<std::recursive_mutex> guard(
269 loc_sp->GetTarget().GetAPIMutex());
270 loc_sp->SetThreadIndex(index);
274 uint32_t SBBreakpointLocation::GetThreadIndex() const {
275 uint32_t thread_idx = UINT32_MAX;
276 BreakpointLocationSP loc_sp = GetSP();
278 std::lock_guard<std::recursive_mutex> guard(
279 loc_sp->GetTarget().GetAPIMutex());
280 return loc_sp->GetThreadIndex();
285 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
286 BreakpointLocationSP loc_sp = GetSP();
288 std::lock_guard<std::recursive_mutex> guard(
289 loc_sp->GetTarget().GetAPIMutex());
290 loc_sp->SetThreadName(thread_name);
294 const char *SBBreakpointLocation::GetThreadName() const {
295 BreakpointLocationSP loc_sp = GetSP();
297 std::lock_guard<std::recursive_mutex> guard(
298 loc_sp->GetTarget().GetAPIMutex());
299 return loc_sp->GetThreadName();
304 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
305 BreakpointLocationSP loc_sp = GetSP();
307 std::lock_guard<std::recursive_mutex> guard(
308 loc_sp->GetTarget().GetAPIMutex());
309 loc_sp->SetQueueName(queue_name);
313 const char *SBBreakpointLocation::GetQueueName() const {
314 BreakpointLocationSP loc_sp = GetSP();
316 std::lock_guard<std::recursive_mutex> guard(
317 loc_sp->GetTarget().GetAPIMutex());
318 loc_sp->GetQueueName();
323 bool SBBreakpointLocation::IsResolved() {
324 BreakpointLocationSP loc_sp = GetSP();
326 std::lock_guard<std::recursive_mutex> guard(
327 loc_sp->GetTarget().GetAPIMutex());
328 return loc_sp->IsResolved();
333 void SBBreakpointLocation::SetLocation(
334 const lldb::BreakpointLocationSP &break_loc_sp) {
335 // Uninstall the callbacks?
336 m_opaque_wp = break_loc_sp;
339 bool SBBreakpointLocation::GetDescription(SBStream &description,
340 DescriptionLevel level) {
341 Stream &strm = description.ref();
342 BreakpointLocationSP loc_sp = GetSP();
345 std::lock_guard<std::recursive_mutex> guard(
346 loc_sp->GetTarget().GetAPIMutex());
347 loc_sp->GetDescription(&strm, level);
350 strm.PutCString("No value");
355 break_id_t SBBreakpointLocation::GetID() {
356 BreakpointLocationSP loc_sp = GetSP();
358 std::lock_guard<std::recursive_mutex> guard(
359 loc_sp->GetTarget().GetAPIMutex());
360 return loc_sp->GetID();
362 return LLDB_INVALID_BREAK_ID;
365 SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
366 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
367 BreakpointLocationSP loc_sp = GetSP();
371 std::lock_guard<std::recursive_mutex> guard(
372 loc_sp->GetTarget().GetAPIMutex());
373 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
378 sb_bp.GetDescription(sstr);
379 LLDB_LOG(log, "location = {0}, breakpoint = {1} ({2})", loc_sp.get(),
380 sb_bp.GetSP().get(), sstr.GetData());