1 //===-- SBBreakpointLocation.cpp --------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBBreakpointLocation.h"
10 #include "SBReproducerPrivate.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/Stream.h"
26 #include "lldb/lldb-defines.h"
27 #include "lldb/lldb-types.h"
30 using namespace lldb_private;
32 SBBreakpointLocation::SBBreakpointLocation() {
33 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpointLocation);
36 SBBreakpointLocation::SBBreakpointLocation(
37 const lldb::BreakpointLocationSP &break_loc_sp)
38 : m_opaque_wp(break_loc_sp) {
39 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
40 (const lldb::BreakpointLocationSP &), break_loc_sp);
43 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
44 : m_opaque_wp(rhs.m_opaque_wp) {
45 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
46 (const lldb::SBBreakpointLocation &), rhs);
49 const SBBreakpointLocation &SBBreakpointLocation::
50 operator=(const SBBreakpointLocation &rhs) {
52 const lldb::SBBreakpointLocation &,
53 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &),
56 m_opaque_wp = rhs.m_opaque_wp;
57 return LLDB_RECORD_RESULT(*this);
60 SBBreakpointLocation::~SBBreakpointLocation() {}
62 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
63 return m_opaque_wp.lock();
66 bool SBBreakpointLocation::IsValid() const {
67 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, IsValid);
68 return this->operator bool();
70 SBBreakpointLocation::operator bool() const {
71 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, operator bool);
76 SBAddress SBBreakpointLocation::GetAddress() {
77 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBBreakpointLocation, GetAddress);
79 BreakpointLocationSP loc_sp = GetSP();
81 return LLDB_RECORD_RESULT(SBAddress(&loc_sp->GetAddress()));
84 return LLDB_RECORD_RESULT(SBAddress());
87 addr_t SBBreakpointLocation::GetLoadAddress() {
88 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBBreakpointLocation,
91 addr_t ret_addr = LLDB_INVALID_ADDRESS;
92 BreakpointLocationSP loc_sp = GetSP();
95 std::lock_guard<std::recursive_mutex> guard(
96 loc_sp->GetTarget().GetAPIMutex());
97 ret_addr = loc_sp->GetLoadAddress();
103 void SBBreakpointLocation::SetEnabled(bool enabled) {
104 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetEnabled, (bool), enabled);
106 BreakpointLocationSP loc_sp = GetSP();
108 std::lock_guard<std::recursive_mutex> guard(
109 loc_sp->GetTarget().GetAPIMutex());
110 loc_sp->SetEnabled(enabled);
114 bool SBBreakpointLocation::IsEnabled() {
115 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsEnabled);
117 BreakpointLocationSP loc_sp = GetSP();
119 std::lock_guard<std::recursive_mutex> guard(
120 loc_sp->GetTarget().GetAPIMutex());
121 return loc_sp->IsEnabled();
126 uint32_t SBBreakpointLocation::GetHitCount() {
127 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetHitCount);
129 BreakpointLocationSP loc_sp = GetSP();
131 std::lock_guard<std::recursive_mutex> guard(
132 loc_sp->GetTarget().GetAPIMutex());
133 return loc_sp->GetHitCount();
138 uint32_t SBBreakpointLocation::GetIgnoreCount() {
139 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetIgnoreCount);
141 BreakpointLocationSP loc_sp = GetSP();
143 std::lock_guard<std::recursive_mutex> guard(
144 loc_sp->GetTarget().GetAPIMutex());
145 return loc_sp->GetIgnoreCount();
150 void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
151 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetIgnoreCount, (uint32_t), n);
153 BreakpointLocationSP loc_sp = GetSP();
155 std::lock_guard<std::recursive_mutex> guard(
156 loc_sp->GetTarget().GetAPIMutex());
157 loc_sp->SetIgnoreCount(n);
161 void SBBreakpointLocation::SetCondition(const char *condition) {
162 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCondition, (const char *),
165 BreakpointLocationSP loc_sp = GetSP();
167 std::lock_guard<std::recursive_mutex> guard(
168 loc_sp->GetTarget().GetAPIMutex());
169 loc_sp->SetCondition(condition);
173 const char *SBBreakpointLocation::GetCondition() {
174 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpointLocation, GetCondition);
176 BreakpointLocationSP loc_sp = GetSP();
178 std::lock_guard<std::recursive_mutex> guard(
179 loc_sp->GetTarget().GetAPIMutex());
180 return loc_sp->GetConditionText();
185 void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
186 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool),
189 BreakpointLocationSP loc_sp = GetSP();
191 std::lock_guard<std::recursive_mutex> guard(
192 loc_sp->GetTarget().GetAPIMutex());
193 loc_sp->SetAutoContinue(auto_continue);
197 bool SBBreakpointLocation::GetAutoContinue() {
198 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, GetAutoContinue);
200 BreakpointLocationSP loc_sp = GetSP();
202 std::lock_guard<std::recursive_mutex> guard(
203 loc_sp->GetTarget().GetAPIMutex());
204 return loc_sp->IsAutoContinue();
209 void SBBreakpointLocation::SetScriptCallbackFunction(
210 const char *callback_function_name) {
211 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
212 (const char *), callback_function_name);
214 BreakpointLocationSP loc_sp = GetSP();
217 std::lock_guard<std::recursive_mutex> guard(
218 loc_sp->GetTarget().GetAPIMutex());
219 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
220 loc_sp->GetBreakpoint()
223 .GetScriptInterpreter()
224 ->SetBreakpointCommandCallbackFunction(bp_options,
225 callback_function_name);
230 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
231 LLDB_RECORD_METHOD(lldb::SBError, SBBreakpointLocation, SetScriptCallbackBody,
232 (const char *), callback_body_text);
234 BreakpointLocationSP loc_sp = GetSP();
238 std::lock_guard<std::recursive_mutex> guard(
239 loc_sp->GetTarget().GetAPIMutex());
240 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
242 loc_sp->GetBreakpoint()
245 .GetScriptInterpreter()
246 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
247 sb_error.SetError(error);
249 sb_error.SetErrorString("invalid breakpoint");
251 return LLDB_RECORD_RESULT(sb_error);
254 void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
255 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
256 (lldb::SBStringList &), commands);
258 BreakpointLocationSP loc_sp = GetSP();
261 if (commands.GetSize() == 0)
264 std::lock_guard<std::recursive_mutex> guard(
265 loc_sp->GetTarget().GetAPIMutex());
266 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
267 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
269 loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
272 bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
273 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
274 (lldb::SBStringList &), commands);
276 BreakpointLocationSP loc_sp = GetSP();
279 StringList command_list;
281 loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
283 commands.AppendList(command_list);
287 void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
288 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadID, (lldb::tid_t),
291 BreakpointLocationSP loc_sp = GetSP();
293 std::lock_guard<std::recursive_mutex> guard(
294 loc_sp->GetTarget().GetAPIMutex());
295 loc_sp->SetThreadID(thread_id);
299 tid_t SBBreakpointLocation::GetThreadID() {
300 LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpointLocation, GetThreadID);
302 tid_t tid = LLDB_INVALID_THREAD_ID;
303 BreakpointLocationSP loc_sp = GetSP();
305 std::lock_guard<std::recursive_mutex> guard(
306 loc_sp->GetTarget().GetAPIMutex());
307 return loc_sp->GetThreadID();
312 void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
313 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadIndex, (uint32_t),
316 BreakpointLocationSP loc_sp = GetSP();
318 std::lock_guard<std::recursive_mutex> guard(
319 loc_sp->GetTarget().GetAPIMutex());
320 loc_sp->SetThreadIndex(index);
324 uint32_t SBBreakpointLocation::GetThreadIndex() const {
325 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpointLocation,
328 uint32_t thread_idx = UINT32_MAX;
329 BreakpointLocationSP loc_sp = GetSP();
331 std::lock_guard<std::recursive_mutex> guard(
332 loc_sp->GetTarget().GetAPIMutex());
333 return loc_sp->GetThreadIndex();
338 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
339 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadName, (const char *),
342 BreakpointLocationSP loc_sp = GetSP();
344 std::lock_guard<std::recursive_mutex> guard(
345 loc_sp->GetTarget().GetAPIMutex());
346 loc_sp->SetThreadName(thread_name);
350 const char *SBBreakpointLocation::GetThreadName() const {
351 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
354 BreakpointLocationSP loc_sp = GetSP();
356 std::lock_guard<std::recursive_mutex> guard(
357 loc_sp->GetTarget().GetAPIMutex());
358 return loc_sp->GetThreadName();
363 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
364 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetQueueName, (const char *),
367 BreakpointLocationSP loc_sp = GetSP();
369 std::lock_guard<std::recursive_mutex> guard(
370 loc_sp->GetTarget().GetAPIMutex());
371 loc_sp->SetQueueName(queue_name);
375 const char *SBBreakpointLocation::GetQueueName() const {
376 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
379 BreakpointLocationSP loc_sp = GetSP();
381 std::lock_guard<std::recursive_mutex> guard(
382 loc_sp->GetTarget().GetAPIMutex());
383 loc_sp->GetQueueName();
388 bool SBBreakpointLocation::IsResolved() {
389 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsResolved);
391 BreakpointLocationSP loc_sp = GetSP();
393 std::lock_guard<std::recursive_mutex> guard(
394 loc_sp->GetTarget().GetAPIMutex());
395 return loc_sp->IsResolved();
400 void SBBreakpointLocation::SetLocation(
401 const lldb::BreakpointLocationSP &break_loc_sp) {
402 // Uninstall the callbacks?
403 m_opaque_wp = break_loc_sp;
406 bool SBBreakpointLocation::GetDescription(SBStream &description,
407 DescriptionLevel level) {
408 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetDescription,
409 (lldb::SBStream &, lldb::DescriptionLevel), description,
412 Stream &strm = description.ref();
413 BreakpointLocationSP loc_sp = GetSP();
416 std::lock_guard<std::recursive_mutex> guard(
417 loc_sp->GetTarget().GetAPIMutex());
418 loc_sp->GetDescription(&strm, level);
421 strm.PutCString("No value");
426 break_id_t SBBreakpointLocation::GetID() {
427 LLDB_RECORD_METHOD_NO_ARGS(lldb::break_id_t, SBBreakpointLocation, GetID);
429 BreakpointLocationSP loc_sp = GetSP();
431 std::lock_guard<std::recursive_mutex> guard(
432 loc_sp->GetTarget().GetAPIMutex());
433 return loc_sp->GetID();
435 return LLDB_INVALID_BREAK_ID;
438 SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
439 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBreakpoint, SBBreakpointLocation,
442 BreakpointLocationSP loc_sp = GetSP();
446 std::lock_guard<std::recursive_mutex> guard(
447 loc_sp->GetTarget().GetAPIMutex());
448 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
451 return LLDB_RECORD_RESULT(sb_bp);
454 namespace lldb_private {
458 void RegisterMethods<SBBreakpointLocation>(Registry &R) {
459 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation, ());
460 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
461 (const lldb::BreakpointLocationSP &));
462 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
463 (const lldb::SBBreakpointLocation &));
464 LLDB_REGISTER_METHOD(
465 const lldb::SBBreakpointLocation &,
466 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &));
467 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, IsValid, ());
468 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, operator bool, ());
469 LLDB_REGISTER_METHOD(lldb::SBAddress, SBBreakpointLocation, GetAddress, ());
470 LLDB_REGISTER_METHOD(lldb::addr_t, SBBreakpointLocation, GetLoadAddress,
472 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetEnabled, (bool));
473 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsEnabled, ());
474 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetHitCount, ());
475 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetIgnoreCount, ());
476 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetIgnoreCount,
478 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCondition,
480 LLDB_REGISTER_METHOD(const char *, SBBreakpointLocation, GetCondition, ());
481 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool));
482 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetAutoContinue, ());
483 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
485 LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointLocation,
486 SetScriptCallbackBody, (const char *));
487 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
488 (lldb::SBStringList &));
489 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
490 (lldb::SBStringList &));
491 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadID,
493 LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpointLocation, GetThreadID, ());
494 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadIndex,
496 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpointLocation, GetThreadIndex,
498 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadName,
500 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation,
502 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetQueueName,
504 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation, GetQueueName,
506 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsResolved, ());
507 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetDescription,
508 (lldb::SBStream &, lldb::DescriptionLevel));
509 LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpointLocation, GetID, ());
510 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointLocation,