1 //===-- SBBreakpointName.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 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "lldb/API/SBBreakpointName.h"
15 #include "lldb/API/SBDebugger.h"
16 #include "lldb/API/SBError.h"
17 #include "lldb/API/SBStream.h"
18 #include "lldb/API/SBStringList.h"
19 #include "lldb/API/SBTarget.h"
21 #include "lldb/Breakpoint/BreakpointName.h"
22 #include "lldb/Breakpoint/StoppointCallbackContext.h"
23 #include "lldb/Core/Debugger.h"
24 #include "lldb/Interpreter/CommandInterpreter.h"
25 #include "lldb/Interpreter/ScriptInterpreter.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/ThreadSpec.h"
28 #include "lldb/Utility/Log.h"
29 #include "lldb/Utility/Stream.h"
31 #include "SBBreakpointOptionCommon.h"
34 using namespace lldb_private;
38 class SBBreakpointNameImpl {
40 SBBreakpointNameImpl(TargetSP target_sp, const char *name) {
41 if (!name || name[0] == '\0')
48 m_target_wp = target_sp;
51 SBBreakpointNameImpl(SBTarget &sb_target, const char *name);
52 bool operator==(const SBBreakpointNameImpl &rhs);
53 bool operator!=(const SBBreakpointNameImpl &rhs);
55 // For now we take a simple approach and only keep the name, and relook up
56 // the location when we need it.
58 TargetSP GetTarget() const {
59 return m_target_wp.lock();
62 const char *GetName() const {
63 return m_name.c_str();
66 bool IsValid() const {
67 return !m_name.empty() && m_target_wp.lock();
70 lldb_private::BreakpointName *GetBreakpointName() const;
77 SBBreakpointNameImpl::SBBreakpointNameImpl(SBTarget &sb_target,
79 if (!name || name[0] == '\0')
83 if (!sb_target.IsValid())
86 TargetSP target_sp = sb_target.GetSP();
90 m_target_wp = target_sp;
93 bool SBBreakpointNameImpl::operator==(const SBBreakpointNameImpl &rhs) {
94 return m_name == rhs.m_name && m_target_wp.lock() == rhs.m_target_wp.lock();
97 bool SBBreakpointNameImpl::operator!=(const SBBreakpointNameImpl &rhs) {
98 return m_name != rhs.m_name || m_target_wp.lock() != rhs.m_target_wp.lock();
101 lldb_private::BreakpointName *SBBreakpointNameImpl::GetBreakpointName() const {
104 TargetSP target_sp = GetTarget();
108 return target_sp->FindBreakpointName(ConstString(m_name), true, error);
113 SBBreakpointName::SBBreakpointName() {}
115 SBBreakpointName::SBBreakpointName(SBTarget &sb_target, const char *name)
117 m_impl_up.reset(new SBBreakpointNameImpl(sb_target, name));
118 // Call FindBreakpointName here to make sure the name is valid, reset if not:
119 BreakpointName *bp_name = GetBreakpointName();
124 SBBreakpointName::SBBreakpointName(SBBreakpoint &sb_bkpt, const char *name)
126 if (!sb_bkpt.IsValid()) {
130 BreakpointSP bkpt_sp = sb_bkpt.GetSP();
131 Target &target = bkpt_sp->GetTarget();
133 m_impl_up.reset(new SBBreakpointNameImpl(target.shared_from_this(), name));
135 // Call FindBreakpointName here to make sure the name is valid, reset if not:
136 BreakpointName *bp_name = GetBreakpointName();
142 // Now copy over the breakpoint's options:
143 target.ConfigureBreakpointName(*bp_name, *bkpt_sp->GetOptions(),
144 BreakpointName::Permissions());
147 SBBreakpointName::SBBreakpointName(const SBBreakpointName &rhs)
152 m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(),
153 rhs.m_impl_up->GetName()));
156 SBBreakpointName::~SBBreakpointName() = default;
158 const SBBreakpointName &SBBreakpointName::operator=(const SBBreakpointName &rhs)
160 if (!rhs.m_impl_up) {
165 m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(),
166 rhs.m_impl_up->GetName()));
170 bool SBBreakpointName::operator==(const lldb::SBBreakpointName &rhs) {
171 return *m_impl_up.get() == *rhs.m_impl_up.get();
174 bool SBBreakpointName::operator!=(const lldb::SBBreakpointName &rhs) {
175 return *m_impl_up.get() != *rhs.m_impl_up.get();
178 bool SBBreakpointName::IsValid() const {
181 return m_impl_up->IsValid();
184 const char *SBBreakpointName::GetName() const {
186 return "<Invalid Breakpoint Name Object>";
187 return m_impl_up->GetName();
190 void SBBreakpointName::SetEnabled(bool enable) {
191 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
193 BreakpointName *bp_name = GetBreakpointName();
197 LLDB_LOG(log, "Name: {0} enabled: {1}\n", bp_name->GetName(), enable);
198 std::lock_guard<std::recursive_mutex> guard(
199 m_impl_up->GetTarget()->GetAPIMutex());
201 bp_name->GetOptions().SetEnabled(enable);
204 void SBBreakpointName::UpdateName(BreakpointName &bp_name) {
208 TargetSP target_sp = m_impl_up->GetTarget();
211 target_sp->ApplyNameToBreakpoints(bp_name);
215 bool SBBreakpointName::IsEnabled() {
216 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
218 BreakpointName *bp_name = GetBreakpointName();
222 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
223 std::lock_guard<std::recursive_mutex> guard(
224 m_impl_up->GetTarget()->GetAPIMutex());
226 return bp_name->GetOptions().IsEnabled();
229 void SBBreakpointName::SetOneShot(bool one_shot) {
230 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
232 BreakpointName *bp_name = GetBreakpointName();
236 LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), one_shot);
237 std::lock_guard<std::recursive_mutex> guard(
238 m_impl_up->GetTarget()->GetAPIMutex());
240 bp_name->GetOptions().SetOneShot(one_shot);
241 UpdateName(*bp_name);
244 bool SBBreakpointName::IsOneShot() const {
245 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
247 const BreakpointName *bp_name = GetBreakpointName();
251 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
252 std::lock_guard<std::recursive_mutex> guard(
253 m_impl_up->GetTarget()->GetAPIMutex());
255 return bp_name->GetOptions().IsOneShot();
258 void SBBreakpointName::SetIgnoreCount(uint32_t count) {
259 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
261 BreakpointName *bp_name = GetBreakpointName();
265 LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), count);
266 std::lock_guard<std::recursive_mutex> guard(
267 m_impl_up->GetTarget()->GetAPIMutex());
269 bp_name->GetOptions().SetIgnoreCount(count);
270 UpdateName(*bp_name);
273 uint32_t SBBreakpointName::GetIgnoreCount() const {
274 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
276 BreakpointName *bp_name = GetBreakpointName();
280 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
281 std::lock_guard<std::recursive_mutex> guard(
282 m_impl_up->GetTarget()->GetAPIMutex());
284 return bp_name->GetOptions().GetIgnoreCount();
287 void SBBreakpointName::SetCondition(const char *condition) {
288 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
290 BreakpointName *bp_name = GetBreakpointName();
294 LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(),
295 condition ? condition : "<NULL>");
297 std::lock_guard<std::recursive_mutex> guard(
298 m_impl_up->GetTarget()->GetAPIMutex());
300 bp_name->GetOptions().SetCondition(condition);
301 UpdateName(*bp_name);
304 const char *SBBreakpointName::GetCondition() {
305 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
307 BreakpointName *bp_name = GetBreakpointName();
311 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
312 std::lock_guard<std::recursive_mutex> guard(
313 m_impl_up->GetTarget()->GetAPIMutex());
315 return bp_name->GetOptions().GetConditionText();
318 void SBBreakpointName::SetAutoContinue(bool auto_continue) {
319 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
321 BreakpointName *bp_name = GetBreakpointName();
325 LLDB_LOG(log, "Name: {0} auto-continue: {1}\n", bp_name->GetName(), auto_continue);
327 std::lock_guard<std::recursive_mutex> guard(
328 m_impl_up->GetTarget()->GetAPIMutex());
330 bp_name->GetOptions().SetAutoContinue(auto_continue);
331 UpdateName(*bp_name);
334 bool SBBreakpointName::GetAutoContinue() {
335 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
337 BreakpointName *bp_name = GetBreakpointName();
341 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
342 std::lock_guard<std::recursive_mutex> guard(
343 m_impl_up->GetTarget()->GetAPIMutex());
345 return bp_name->GetOptions().IsAutoContinue();
348 void SBBreakpointName::SetThreadID(tid_t tid) {
349 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
351 BreakpointName *bp_name = GetBreakpointName();
355 LLDB_LOG(log, "Name: {0} tid: {1:x}\n", bp_name->GetName(), tid);
357 std::lock_guard<std::recursive_mutex> guard(
358 m_impl_up->GetTarget()->GetAPIMutex());
360 bp_name->GetOptions().SetThreadID(tid);
361 UpdateName(*bp_name);
364 tid_t SBBreakpointName::GetThreadID() {
365 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
367 BreakpointName *bp_name = GetBreakpointName();
369 return LLDB_INVALID_THREAD_ID;
371 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
372 std::lock_guard<std::recursive_mutex> guard(
373 m_impl_up->GetTarget()->GetAPIMutex());
375 return bp_name->GetOptions().GetThreadSpec()->GetTID();
378 void SBBreakpointName::SetThreadIndex(uint32_t index) {
379 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
381 BreakpointName *bp_name = GetBreakpointName();
385 LLDB_LOG(log, "Name: {0} thread index: {1}\n", bp_name->GetName(), index);
387 std::lock_guard<std::recursive_mutex> guard(
388 m_impl_up->GetTarget()->GetAPIMutex());
390 bp_name->GetOptions().GetThreadSpec()->SetIndex(index);
391 UpdateName(*bp_name);
394 uint32_t SBBreakpointName::GetThreadIndex() const {
395 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
397 BreakpointName *bp_name = GetBreakpointName();
399 return LLDB_INVALID_THREAD_ID;
401 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
402 std::lock_guard<std::recursive_mutex> guard(
403 m_impl_up->GetTarget()->GetAPIMutex());
405 return bp_name->GetOptions().GetThreadSpec()->GetIndex();
408 void SBBreakpointName::SetThreadName(const char *thread_name) {
409 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
411 BreakpointName *bp_name = GetBreakpointName();
415 LLDB_LOG(log, "Name: {0} thread name: {1}\n", bp_name->GetName(), thread_name);
417 std::lock_guard<std::recursive_mutex> guard(
418 m_impl_up->GetTarget()->GetAPIMutex());
420 bp_name->GetOptions().GetThreadSpec()->SetName(thread_name);
421 UpdateName(*bp_name);
424 const char *SBBreakpointName::GetThreadName() const {
425 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
427 BreakpointName *bp_name = GetBreakpointName();
431 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
432 std::lock_guard<std::recursive_mutex> guard(
433 m_impl_up->GetTarget()->GetAPIMutex());
435 return bp_name->GetOptions().GetThreadSpec()->GetName();
438 void SBBreakpointName::SetQueueName(const char *queue_name) {
439 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
441 BreakpointName *bp_name = GetBreakpointName();
445 LLDB_LOG(log, "Name: {0} queue name: {1}\n", bp_name->GetName(), queue_name);
447 std::lock_guard<std::recursive_mutex> guard(
448 m_impl_up->GetTarget()->GetAPIMutex());
450 bp_name->GetOptions().GetThreadSpec()->SetQueueName(queue_name);
451 UpdateName(*bp_name);
454 const char *SBBreakpointName::GetQueueName() const {
455 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
457 BreakpointName *bp_name = GetBreakpointName();
461 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
462 std::lock_guard<std::recursive_mutex> guard(
463 m_impl_up->GetTarget()->GetAPIMutex());
465 return bp_name->GetOptions().GetThreadSpec()->GetQueueName();
468 void SBBreakpointName::SetCommandLineCommands(SBStringList &commands) {
469 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
470 BreakpointName *bp_name = GetBreakpointName();
473 if (commands.GetSize() == 0)
476 LLDB_LOG(log, "Name: {0} commands\n", bp_name->GetName());
478 std::lock_guard<std::recursive_mutex> guard(
479 m_impl_up->GetTarget()->GetAPIMutex());
480 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
481 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
483 bp_name->GetOptions().SetCommandDataCallback(cmd_data_up);
484 UpdateName(*bp_name);
487 bool SBBreakpointName::GetCommandLineCommands(SBStringList &commands) {
488 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
490 BreakpointName *bp_name = GetBreakpointName();
494 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
495 StringList command_list;
497 bp_name->GetOptions().GetCommandLineCallbacks(command_list);
499 commands.AppendList(command_list);
503 const char *SBBreakpointName::GetHelpString() const {
504 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
506 BreakpointName *bp_name = GetBreakpointName();
510 LLDB_LOG(log, "Help: {0}\n", bp_name->GetHelp());
511 return bp_name->GetHelp();
514 void SBBreakpointName::SetHelpString(const char *help_string) {
515 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
516 BreakpointName *bp_name = GetBreakpointName();
520 LLDB_LOG(log, "Name: {0} help: {1}\n", bp_name->GetName(), help_string);
522 std::lock_guard<std::recursive_mutex> guard(
523 m_impl_up->GetTarget()->GetAPIMutex());
524 bp_name->SetHelp(help_string);
527 bool SBBreakpointName::GetDescription(SBStream &s) {
528 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
530 BreakpointName *bp_name = GetBreakpointName();
533 s.Printf("No value");
537 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
538 std::lock_guard<std::recursive_mutex> guard(
539 m_impl_up->GetTarget()->GetAPIMutex());
540 bp_name->GetDescription(s.get(), eDescriptionLevelFull);
544 void SBBreakpointName::SetCallback(SBBreakpointHitCallback callback,
546 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
547 BreakpointName *bp_name = GetBreakpointName();
550 LLDB_LOG(log, "callback = {1}, baton = {2}", callback, baton);
551 std::lock_guard<std::recursive_mutex> guard(
552 m_impl_up->GetTarget()->GetAPIMutex());
554 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
555 bp_name->GetOptions().SetCallback(SBBreakpointCallbackBaton
556 ::PrivateBreakpointHitCallback,
559 UpdateName(*bp_name);
562 void SBBreakpointName::SetScriptCallbackFunction(
563 const char *callback_function_name) {
564 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
566 BreakpointName *bp_name = GetBreakpointName();
570 LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(),
571 callback_function_name);
573 std::lock_guard<std::recursive_mutex> guard(
574 m_impl_up->GetTarget()->GetAPIMutex());
576 BreakpointOptions &bp_options = bp_name->GetOptions();
577 m_impl_up->GetTarget()
579 .GetCommandInterpreter()
580 .GetScriptInterpreter()
581 ->SetBreakpointCommandCallbackFunction(&bp_options,
582 callback_function_name);
583 UpdateName(*bp_name);
586 SBError SBBreakpointName::SetScriptCallbackBody(const char *callback_body_text)
588 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
590 BreakpointName *bp_name = GetBreakpointName();
594 LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(),
597 std::lock_guard<std::recursive_mutex> guard(
598 m_impl_up->GetTarget()->GetAPIMutex());
600 BreakpointOptions &bp_options = bp_name->GetOptions();
602 m_impl_up->GetTarget()
604 .GetCommandInterpreter()
605 .GetScriptInterpreter()
606 ->SetBreakpointCommandCallback(&bp_options, callback_body_text);
607 sb_error.SetError(error);
608 if (!sb_error.Fail())
609 UpdateName(*bp_name);
614 bool SBBreakpointName::GetAllowList() const
616 BreakpointName *bp_name = GetBreakpointName();
619 return bp_name->GetPermissions().GetAllowList();
622 void SBBreakpointName::SetAllowList(bool value)
624 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
626 BreakpointName *bp_name = GetBreakpointName();
630 log->Printf("Setting allow list to %u for %s.", value,
631 bp_name->GetName().AsCString());
632 bp_name->GetPermissions().SetAllowList(value);
635 bool SBBreakpointName::GetAllowDelete()
637 BreakpointName *bp_name = GetBreakpointName();
640 return bp_name->GetPermissions().GetAllowDelete();
643 void SBBreakpointName::SetAllowDelete(bool value)
645 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
647 BreakpointName *bp_name = GetBreakpointName();
651 log->Printf("Setting allow delete to %u for %s.", value,
652 bp_name->GetName().AsCString());
653 bp_name->GetPermissions().SetAllowDelete(value);
656 bool SBBreakpointName::GetAllowDisable()
658 BreakpointName *bp_name = GetBreakpointName();
661 return bp_name->GetPermissions().GetAllowDisable();
664 void SBBreakpointName::SetAllowDisable(bool value)
666 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
668 BreakpointName *bp_name = GetBreakpointName();
672 log->Printf("Setting allow disable to %u for %s.", value,
673 bp_name->GetName().AsCString());
674 bp_name->GetPermissions().SetAllowDisable(value);
677 lldb_private::BreakpointName *SBBreakpointName::GetBreakpointName() const
681 return m_impl_up->GetBreakpointName();