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/SBStructuredData.h"
16 #include "lldb/API/SBStringList.h"
18 #include "lldb/Breakpoint/Breakpoint.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/StreamFile.h"
22 #include "lldb/Core/StructuredDataImpl.h"
23 #include "lldb/Interpreter/CommandInterpreter.h"
24 #include "lldb/Interpreter/ScriptInterpreter.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/ThreadSpec.h"
27 #include "lldb/Utility/Stream.h"
28 #include "lldb/lldb-defines.h"
29 #include "lldb/lldb-types.h"
32 using namespace lldb_private;
34 SBBreakpointLocation::SBBreakpointLocation() {
35 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpointLocation);
38 SBBreakpointLocation::SBBreakpointLocation(
39 const lldb::BreakpointLocationSP &break_loc_sp)
40 : m_opaque_wp(break_loc_sp) {
41 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
42 (const lldb::BreakpointLocationSP &), break_loc_sp);
45 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs)
46 : m_opaque_wp(rhs.m_opaque_wp) {
47 LLDB_RECORD_CONSTRUCTOR(SBBreakpointLocation,
48 (const lldb::SBBreakpointLocation &), rhs);
51 const SBBreakpointLocation &SBBreakpointLocation::
52 operator=(const SBBreakpointLocation &rhs) {
54 const lldb::SBBreakpointLocation &,
55 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &),
58 m_opaque_wp = rhs.m_opaque_wp;
59 return LLDB_RECORD_RESULT(*this);
62 SBBreakpointLocation::~SBBreakpointLocation() {}
64 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
65 return m_opaque_wp.lock();
68 bool SBBreakpointLocation::IsValid() const {
69 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, IsValid);
70 return this->operator bool();
72 SBBreakpointLocation::operator bool() const {
73 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpointLocation, operator bool);
78 SBAddress SBBreakpointLocation::GetAddress() {
79 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBBreakpointLocation, GetAddress);
81 BreakpointLocationSP loc_sp = GetSP();
83 return LLDB_RECORD_RESULT(SBAddress(&loc_sp->GetAddress()));
86 return LLDB_RECORD_RESULT(SBAddress());
89 addr_t SBBreakpointLocation::GetLoadAddress() {
90 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBBreakpointLocation,
93 addr_t ret_addr = LLDB_INVALID_ADDRESS;
94 BreakpointLocationSP loc_sp = GetSP();
97 std::lock_guard<std::recursive_mutex> guard(
98 loc_sp->GetTarget().GetAPIMutex());
99 ret_addr = loc_sp->GetLoadAddress();
105 void SBBreakpointLocation::SetEnabled(bool enabled) {
106 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetEnabled, (bool), enabled);
108 BreakpointLocationSP loc_sp = GetSP();
110 std::lock_guard<std::recursive_mutex> guard(
111 loc_sp->GetTarget().GetAPIMutex());
112 loc_sp->SetEnabled(enabled);
116 bool SBBreakpointLocation::IsEnabled() {
117 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsEnabled);
119 BreakpointLocationSP loc_sp = GetSP();
121 std::lock_guard<std::recursive_mutex> guard(
122 loc_sp->GetTarget().GetAPIMutex());
123 return loc_sp->IsEnabled();
128 uint32_t SBBreakpointLocation::GetHitCount() {
129 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetHitCount);
131 BreakpointLocationSP loc_sp = GetSP();
133 std::lock_guard<std::recursive_mutex> guard(
134 loc_sp->GetTarget().GetAPIMutex());
135 return loc_sp->GetHitCount();
140 uint32_t SBBreakpointLocation::GetIgnoreCount() {
141 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBBreakpointLocation, GetIgnoreCount);
143 BreakpointLocationSP loc_sp = GetSP();
145 std::lock_guard<std::recursive_mutex> guard(
146 loc_sp->GetTarget().GetAPIMutex());
147 return loc_sp->GetIgnoreCount();
152 void SBBreakpointLocation::SetIgnoreCount(uint32_t n) {
153 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetIgnoreCount, (uint32_t), n);
155 BreakpointLocationSP loc_sp = GetSP();
157 std::lock_guard<std::recursive_mutex> guard(
158 loc_sp->GetTarget().GetAPIMutex());
159 loc_sp->SetIgnoreCount(n);
163 void SBBreakpointLocation::SetCondition(const char *condition) {
164 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCondition, (const char *),
167 BreakpointLocationSP loc_sp = GetSP();
169 std::lock_guard<std::recursive_mutex> guard(
170 loc_sp->GetTarget().GetAPIMutex());
171 loc_sp->SetCondition(condition);
175 const char *SBBreakpointLocation::GetCondition() {
176 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpointLocation, GetCondition);
178 BreakpointLocationSP loc_sp = GetSP();
180 std::lock_guard<std::recursive_mutex> guard(
181 loc_sp->GetTarget().GetAPIMutex());
182 return loc_sp->GetConditionText();
187 void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
188 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool),
191 BreakpointLocationSP loc_sp = GetSP();
193 std::lock_guard<std::recursive_mutex> guard(
194 loc_sp->GetTarget().GetAPIMutex());
195 loc_sp->SetAutoContinue(auto_continue);
199 bool SBBreakpointLocation::GetAutoContinue() {
200 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, GetAutoContinue);
202 BreakpointLocationSP loc_sp = GetSP();
204 std::lock_guard<std::recursive_mutex> guard(
205 loc_sp->GetTarget().GetAPIMutex());
206 return loc_sp->IsAutoContinue();
211 void SBBreakpointLocation::SetScriptCallbackFunction(
212 const char *callback_function_name) {
213 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
214 (const char *), callback_function_name);
217 SBError SBBreakpointLocation::SetScriptCallbackFunction(
218 const char *callback_function_name,
219 SBStructuredData &extra_args) {
220 LLDB_RECORD_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
221 (const char *, SBStructuredData &),
222 callback_function_name, extra_args);
224 BreakpointLocationSP loc_sp = GetSP();
228 std::lock_guard<std::recursive_mutex> guard(
229 loc_sp->GetTarget().GetAPIMutex());
230 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
231 error = loc_sp->GetBreakpoint()
234 .GetScriptInterpreter()
235 ->SetBreakpointCommandCallbackFunction(bp_options,
236 callback_function_name,
239 sb_error.SetError(error);
241 sb_error.SetErrorString("invalid breakpoint");
243 return LLDB_RECORD_RESULT(sb_error);
247 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
248 LLDB_RECORD_METHOD(lldb::SBError, SBBreakpointLocation, SetScriptCallbackBody,
249 (const char *), callback_body_text);
251 BreakpointLocationSP loc_sp = GetSP();
255 std::lock_guard<std::recursive_mutex> guard(
256 loc_sp->GetTarget().GetAPIMutex());
257 BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
259 loc_sp->GetBreakpoint()
262 .GetScriptInterpreter()
263 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
264 sb_error.SetError(error);
266 sb_error.SetErrorString("invalid breakpoint");
268 return LLDB_RECORD_RESULT(sb_error);
271 void SBBreakpointLocation::SetCommandLineCommands(SBStringList &commands) {
272 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
273 (lldb::SBStringList &), commands);
275 BreakpointLocationSP loc_sp = GetSP();
278 if (commands.GetSize() == 0)
281 std::lock_guard<std::recursive_mutex> guard(
282 loc_sp->GetTarget().GetAPIMutex());
283 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
284 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
286 loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
289 bool SBBreakpointLocation::GetCommandLineCommands(SBStringList &commands) {
290 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
291 (lldb::SBStringList &), commands);
293 BreakpointLocationSP loc_sp = GetSP();
296 StringList command_list;
298 loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
300 commands.AppendList(command_list);
304 void SBBreakpointLocation::SetThreadID(tid_t thread_id) {
305 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadID, (lldb::tid_t),
308 BreakpointLocationSP loc_sp = GetSP();
310 std::lock_guard<std::recursive_mutex> guard(
311 loc_sp->GetTarget().GetAPIMutex());
312 loc_sp->SetThreadID(thread_id);
316 tid_t SBBreakpointLocation::GetThreadID() {
317 LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpointLocation, GetThreadID);
319 tid_t tid = LLDB_INVALID_THREAD_ID;
320 BreakpointLocationSP loc_sp = GetSP();
322 std::lock_guard<std::recursive_mutex> guard(
323 loc_sp->GetTarget().GetAPIMutex());
324 return loc_sp->GetThreadID();
329 void SBBreakpointLocation::SetThreadIndex(uint32_t index) {
330 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadIndex, (uint32_t),
333 BreakpointLocationSP loc_sp = GetSP();
335 std::lock_guard<std::recursive_mutex> guard(
336 loc_sp->GetTarget().GetAPIMutex());
337 loc_sp->SetThreadIndex(index);
341 uint32_t SBBreakpointLocation::GetThreadIndex() const {
342 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpointLocation,
345 uint32_t thread_idx = UINT32_MAX;
346 BreakpointLocationSP loc_sp = GetSP();
348 std::lock_guard<std::recursive_mutex> guard(
349 loc_sp->GetTarget().GetAPIMutex());
350 return loc_sp->GetThreadIndex();
355 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
356 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetThreadName, (const char *),
359 BreakpointLocationSP loc_sp = GetSP();
361 std::lock_guard<std::recursive_mutex> guard(
362 loc_sp->GetTarget().GetAPIMutex());
363 loc_sp->SetThreadName(thread_name);
367 const char *SBBreakpointLocation::GetThreadName() const {
368 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
371 BreakpointLocationSP loc_sp = GetSP();
373 std::lock_guard<std::recursive_mutex> guard(
374 loc_sp->GetTarget().GetAPIMutex());
375 return loc_sp->GetThreadName();
380 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
381 LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetQueueName, (const char *),
384 BreakpointLocationSP loc_sp = GetSP();
386 std::lock_guard<std::recursive_mutex> guard(
387 loc_sp->GetTarget().GetAPIMutex());
388 loc_sp->SetQueueName(queue_name);
392 const char *SBBreakpointLocation::GetQueueName() const {
393 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpointLocation,
396 BreakpointLocationSP loc_sp = GetSP();
398 std::lock_guard<std::recursive_mutex> guard(
399 loc_sp->GetTarget().GetAPIMutex());
400 loc_sp->GetQueueName();
405 bool SBBreakpointLocation::IsResolved() {
406 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpointLocation, IsResolved);
408 BreakpointLocationSP loc_sp = GetSP();
410 std::lock_guard<std::recursive_mutex> guard(
411 loc_sp->GetTarget().GetAPIMutex());
412 return loc_sp->IsResolved();
417 void SBBreakpointLocation::SetLocation(
418 const lldb::BreakpointLocationSP &break_loc_sp) {
419 // Uninstall the callbacks?
420 m_opaque_wp = break_loc_sp;
423 bool SBBreakpointLocation::GetDescription(SBStream &description,
424 DescriptionLevel level) {
425 LLDB_RECORD_METHOD(bool, SBBreakpointLocation, GetDescription,
426 (lldb::SBStream &, lldb::DescriptionLevel), description,
429 Stream &strm = description.ref();
430 BreakpointLocationSP loc_sp = GetSP();
433 std::lock_guard<std::recursive_mutex> guard(
434 loc_sp->GetTarget().GetAPIMutex());
435 loc_sp->GetDescription(&strm, level);
438 strm.PutCString("No value");
443 break_id_t SBBreakpointLocation::GetID() {
444 LLDB_RECORD_METHOD_NO_ARGS(lldb::break_id_t, SBBreakpointLocation, GetID);
446 BreakpointLocationSP loc_sp = GetSP();
448 std::lock_guard<std::recursive_mutex> guard(
449 loc_sp->GetTarget().GetAPIMutex());
450 return loc_sp->GetID();
452 return LLDB_INVALID_BREAK_ID;
455 SBBreakpoint SBBreakpointLocation::GetBreakpoint() {
456 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBreakpoint, SBBreakpointLocation,
459 BreakpointLocationSP loc_sp = GetSP();
463 std::lock_guard<std::recursive_mutex> guard(
464 loc_sp->GetTarget().GetAPIMutex());
465 sb_bp = loc_sp->GetBreakpoint().shared_from_this();
468 return LLDB_RECORD_RESULT(sb_bp);
471 namespace lldb_private {
475 void RegisterMethods<SBBreakpointLocation>(Registry &R) {
476 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation, ());
477 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
478 (const lldb::BreakpointLocationSP &));
479 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointLocation,
480 (const lldb::SBBreakpointLocation &));
481 LLDB_REGISTER_METHOD(
482 const lldb::SBBreakpointLocation &,
483 SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &));
484 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, IsValid, ());
485 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, operator bool, ());
486 LLDB_REGISTER_METHOD(lldb::SBAddress, SBBreakpointLocation, GetAddress, ());
487 LLDB_REGISTER_METHOD(lldb::addr_t, SBBreakpointLocation, GetLoadAddress,
489 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetEnabled, (bool));
490 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsEnabled, ());
491 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetHitCount, ());
492 LLDB_REGISTER_METHOD(uint32_t, SBBreakpointLocation, GetIgnoreCount, ());
493 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetIgnoreCount,
495 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCondition,
497 LLDB_REGISTER_METHOD(const char *, SBBreakpointLocation, GetCondition, ());
498 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetAutoContinue, (bool));
499 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetAutoContinue, ());
500 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
502 LLDB_REGISTER_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
503 (const char *, SBStructuredData &));
504 LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointLocation,
505 SetScriptCallbackBody, (const char *));
506 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
507 (lldb::SBStringList &));
508 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetCommandLineCommands,
509 (lldb::SBStringList &));
510 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadID,
512 LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpointLocation, GetThreadID, ());
513 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadIndex,
515 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpointLocation, GetThreadIndex,
517 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetThreadName,
519 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation,
521 LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetQueueName,
523 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpointLocation, GetQueueName,
525 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, IsResolved, ());
526 LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetDescription,
527 (lldb::SBStream &, lldb::DescriptionLevel));
528 LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpointLocation, GetID, ());
529 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointLocation,