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
56 // up 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
120 BreakpointName *bp_name = GetBreakpointName();
125 SBBreakpointName::SBBreakpointName(SBBreakpoint &sb_bkpt, const char *name)
127 if (!sb_bkpt.IsValid()) {
131 BreakpointSP bkpt_sp = sb_bkpt.GetSP();
132 Target &target = bkpt_sp->GetTarget();
134 m_impl_up.reset(new SBBreakpointNameImpl(target.shared_from_this(), name));
136 // Call FindBreakpointName here to make sure the name is valid, reset if
138 BreakpointName *bp_name = GetBreakpointName();
144 // Now copy over the breakpoint's options:
145 target.ConfigureBreakpointName(*bp_name, *bkpt_sp->GetOptions(),
146 BreakpointName::Permissions());
149 SBBreakpointName::SBBreakpointName(const SBBreakpointName &rhs)
154 m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(),
155 rhs.m_impl_up->GetName()));
158 SBBreakpointName::~SBBreakpointName() = default;
160 const SBBreakpointName &SBBreakpointName::operator=(const SBBreakpointName &rhs)
162 if (!rhs.m_impl_up) {
167 m_impl_up.reset(new SBBreakpointNameImpl(rhs.m_impl_up->GetTarget(),
168 rhs.m_impl_up->GetName()));
172 bool SBBreakpointName::operator==(const lldb::SBBreakpointName &rhs) {
173 return *m_impl_up.get() == *rhs.m_impl_up.get();
176 bool SBBreakpointName::operator!=(const lldb::SBBreakpointName &rhs) {
177 return *m_impl_up.get() != *rhs.m_impl_up.get();
180 bool SBBreakpointName::IsValid() const {
183 return m_impl_up->IsValid();
186 const char *SBBreakpointName::GetName() const {
188 return "<Invalid Breakpoint Name Object>";
189 return m_impl_up->GetName();
192 void SBBreakpointName::SetEnabled(bool enable) {
193 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
195 BreakpointName *bp_name = GetBreakpointName();
199 LLDB_LOG(log, "Name: {0} enabled: {1}\n", bp_name->GetName(), enable);
200 std::lock_guard<std::recursive_mutex> guard(
201 m_impl_up->GetTarget()->GetAPIMutex());
203 bp_name->GetOptions().SetEnabled(enable);
206 void SBBreakpointName::UpdateName(BreakpointName &bp_name) {
210 TargetSP target_sp = m_impl_up->GetTarget();
213 target_sp->ApplyNameToBreakpoints(bp_name);
217 bool SBBreakpointName::IsEnabled() {
218 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
220 BreakpointName *bp_name = GetBreakpointName();
224 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
225 std::lock_guard<std::recursive_mutex> guard(
226 m_impl_up->GetTarget()->GetAPIMutex());
228 return bp_name->GetOptions().IsEnabled();
231 void SBBreakpointName::SetOneShot(bool one_shot) {
232 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
234 BreakpointName *bp_name = GetBreakpointName();
238 LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), one_shot);
239 std::lock_guard<std::recursive_mutex> guard(
240 m_impl_up->GetTarget()->GetAPIMutex());
242 bp_name->GetOptions().SetOneShot(one_shot);
243 UpdateName(*bp_name);
246 bool SBBreakpointName::IsOneShot() const {
247 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
249 const BreakpointName *bp_name = GetBreakpointName();
253 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
254 std::lock_guard<std::recursive_mutex> guard(
255 m_impl_up->GetTarget()->GetAPIMutex());
257 return bp_name->GetOptions().IsOneShot();
260 void SBBreakpointName::SetIgnoreCount(uint32_t count) {
261 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
263 BreakpointName *bp_name = GetBreakpointName();
267 LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(), count);
268 std::lock_guard<std::recursive_mutex> guard(
269 m_impl_up->GetTarget()->GetAPIMutex());
271 bp_name->GetOptions().SetIgnoreCount(count);
272 UpdateName(*bp_name);
275 uint32_t SBBreakpointName::GetIgnoreCount() const {
276 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
278 BreakpointName *bp_name = GetBreakpointName();
282 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
283 std::lock_guard<std::recursive_mutex> guard(
284 m_impl_up->GetTarget()->GetAPIMutex());
286 return bp_name->GetOptions().GetIgnoreCount();
289 void SBBreakpointName::SetCondition(const char *condition) {
290 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
292 BreakpointName *bp_name = GetBreakpointName();
296 LLDB_LOG(log, "Name: {0} one_shot: {1}\n", bp_name->GetName(),
297 condition ? condition : "<NULL>");
299 std::lock_guard<std::recursive_mutex> guard(
300 m_impl_up->GetTarget()->GetAPIMutex());
302 bp_name->GetOptions().SetCondition(condition);
303 UpdateName(*bp_name);
306 const char *SBBreakpointName::GetCondition() {
307 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
309 BreakpointName *bp_name = GetBreakpointName();
313 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
314 std::lock_guard<std::recursive_mutex> guard(
315 m_impl_up->GetTarget()->GetAPIMutex());
317 return bp_name->GetOptions().GetConditionText();
320 void SBBreakpointName::SetAutoContinue(bool auto_continue) {
321 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
323 BreakpointName *bp_name = GetBreakpointName();
327 LLDB_LOG(log, "Name: {0} auto-continue: {1}\n", bp_name->GetName(), auto_continue);
329 std::lock_guard<std::recursive_mutex> guard(
330 m_impl_up->GetTarget()->GetAPIMutex());
332 bp_name->GetOptions().SetAutoContinue(auto_continue);
333 UpdateName(*bp_name);
336 bool SBBreakpointName::GetAutoContinue() {
337 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
339 BreakpointName *bp_name = GetBreakpointName();
343 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
344 std::lock_guard<std::recursive_mutex> guard(
345 m_impl_up->GetTarget()->GetAPIMutex());
347 return bp_name->GetOptions().IsAutoContinue();
350 void SBBreakpointName::SetThreadID(tid_t tid) {
351 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
353 BreakpointName *bp_name = GetBreakpointName();
357 LLDB_LOG(log, "Name: {0} tid: {1:x}\n", bp_name->GetName(), tid);
359 std::lock_guard<std::recursive_mutex> guard(
360 m_impl_up->GetTarget()->GetAPIMutex());
362 bp_name->GetOptions().SetThreadID(tid);
363 UpdateName(*bp_name);
366 tid_t SBBreakpointName::GetThreadID() {
367 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
369 BreakpointName *bp_name = GetBreakpointName();
371 return LLDB_INVALID_THREAD_ID;
373 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
374 std::lock_guard<std::recursive_mutex> guard(
375 m_impl_up->GetTarget()->GetAPIMutex());
377 return bp_name->GetOptions().GetThreadSpec()->GetTID();
380 void SBBreakpointName::SetThreadIndex(uint32_t index) {
381 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
383 BreakpointName *bp_name = GetBreakpointName();
387 LLDB_LOG(log, "Name: {0} thread index: {1}\n", bp_name->GetName(), index);
389 std::lock_guard<std::recursive_mutex> guard(
390 m_impl_up->GetTarget()->GetAPIMutex());
392 bp_name->GetOptions().GetThreadSpec()->SetIndex(index);
393 UpdateName(*bp_name);
396 uint32_t SBBreakpointName::GetThreadIndex() const {
397 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
399 BreakpointName *bp_name = GetBreakpointName();
401 return LLDB_INVALID_THREAD_ID;
403 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
404 std::lock_guard<std::recursive_mutex> guard(
405 m_impl_up->GetTarget()->GetAPIMutex());
407 return bp_name->GetOptions().GetThreadSpec()->GetIndex();
410 void SBBreakpointName::SetThreadName(const char *thread_name) {
411 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
413 BreakpointName *bp_name = GetBreakpointName();
417 LLDB_LOG(log, "Name: {0} thread name: {1}\n", bp_name->GetName(), thread_name);
419 std::lock_guard<std::recursive_mutex> guard(
420 m_impl_up->GetTarget()->GetAPIMutex());
422 bp_name->GetOptions().GetThreadSpec()->SetName(thread_name);
423 UpdateName(*bp_name);
426 const char *SBBreakpointName::GetThreadName() const {
427 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
429 BreakpointName *bp_name = GetBreakpointName();
433 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
434 std::lock_guard<std::recursive_mutex> guard(
435 m_impl_up->GetTarget()->GetAPIMutex());
437 return bp_name->GetOptions().GetThreadSpec()->GetName();
440 void SBBreakpointName::SetQueueName(const char *queue_name) {
441 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
443 BreakpointName *bp_name = GetBreakpointName();
447 LLDB_LOG(log, "Name: {0} queue name: {1}\n", bp_name->GetName(), queue_name);
449 std::lock_guard<std::recursive_mutex> guard(
450 m_impl_up->GetTarget()->GetAPIMutex());
452 bp_name->GetOptions().GetThreadSpec()->SetQueueName(queue_name);
453 UpdateName(*bp_name);
456 const char *SBBreakpointName::GetQueueName() const {
457 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
459 BreakpointName *bp_name = GetBreakpointName();
463 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
464 std::lock_guard<std::recursive_mutex> guard(
465 m_impl_up->GetTarget()->GetAPIMutex());
467 return bp_name->GetOptions().GetThreadSpec()->GetQueueName();
470 void SBBreakpointName::SetCommandLineCommands(SBStringList &commands) {
471 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
472 BreakpointName *bp_name = GetBreakpointName();
475 if (commands.GetSize() == 0)
478 LLDB_LOG(log, "Name: {0} commands\n", bp_name->GetName());
480 std::lock_guard<std::recursive_mutex> guard(
481 m_impl_up->GetTarget()->GetAPIMutex());
482 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
483 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
485 bp_name->GetOptions().SetCommandDataCallback(cmd_data_up);
486 UpdateName(*bp_name);
489 bool SBBreakpointName::GetCommandLineCommands(SBStringList &commands) {
490 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
492 BreakpointName *bp_name = GetBreakpointName();
496 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
497 StringList command_list;
499 bp_name->GetOptions().GetCommandLineCallbacks(command_list);
501 commands.AppendList(command_list);
505 const char *SBBreakpointName::GetHelpString() const {
506 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
508 BreakpointName *bp_name = GetBreakpointName();
512 LLDB_LOG(log, "Help: {0}\n", bp_name->GetHelp());
513 return bp_name->GetHelp();
516 void SBBreakpointName::SetHelpString(const char *help_string) {
517 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
518 BreakpointName *bp_name = GetBreakpointName();
522 LLDB_LOG(log, "Name: {0} help: {1}\n", bp_name->GetName(), help_string);
524 std::lock_guard<std::recursive_mutex> guard(
525 m_impl_up->GetTarget()->GetAPIMutex());
526 bp_name->SetHelp(help_string);
529 bool SBBreakpointName::GetDescription(SBStream &s) {
530 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
532 BreakpointName *bp_name = GetBreakpointName();
535 s.Printf("No value");
539 LLDB_LOG(log, "Name: {0}\n", bp_name->GetName());
540 std::lock_guard<std::recursive_mutex> guard(
541 m_impl_up->GetTarget()->GetAPIMutex());
542 bp_name->GetDescription(s.get(), eDescriptionLevelFull);
546 void SBBreakpointName::SetCallback(SBBreakpointHitCallback callback,
548 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
549 BreakpointName *bp_name = GetBreakpointName();
552 LLDB_LOG(log, "callback = {1}, baton = {2}", callback, baton);
553 std::lock_guard<std::recursive_mutex> guard(
554 m_impl_up->GetTarget()->GetAPIMutex());
556 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
557 bp_name->GetOptions().SetCallback(SBBreakpointCallbackBaton
558 ::PrivateBreakpointHitCallback,
561 UpdateName(*bp_name);
564 void SBBreakpointName::SetScriptCallbackFunction(
565 const char *callback_function_name) {
566 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
568 BreakpointName *bp_name = GetBreakpointName();
572 LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(),
573 callback_function_name);
575 std::lock_guard<std::recursive_mutex> guard(
576 m_impl_up->GetTarget()->GetAPIMutex());
578 BreakpointOptions &bp_options = bp_name->GetOptions();
579 m_impl_up->GetTarget()
581 .GetCommandInterpreter()
582 .GetScriptInterpreter()
583 ->SetBreakpointCommandCallbackFunction(&bp_options,
584 callback_function_name);
585 UpdateName(*bp_name);
588 SBError SBBreakpointName::SetScriptCallbackBody(const char *callback_body_text)
590 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
592 BreakpointName *bp_name = GetBreakpointName();
596 LLDB_LOG(log, "Name: {0} callback: {1}\n", bp_name->GetName(),
599 std::lock_guard<std::recursive_mutex> guard(
600 m_impl_up->GetTarget()->GetAPIMutex());
602 BreakpointOptions &bp_options = bp_name->GetOptions();
604 m_impl_up->GetTarget()
606 .GetCommandInterpreter()
607 .GetScriptInterpreter()
608 ->SetBreakpointCommandCallback(&bp_options, callback_body_text);
609 sb_error.SetError(error);
610 if (!sb_error.Fail())
611 UpdateName(*bp_name);
616 bool SBBreakpointName::GetAllowList() const
618 BreakpointName *bp_name = GetBreakpointName();
621 return bp_name->GetPermissions().GetAllowList();
624 void SBBreakpointName::SetAllowList(bool value)
626 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
628 BreakpointName *bp_name = GetBreakpointName();
632 log->Printf("Setting allow list to %u for %s.", value,
633 bp_name->GetName().AsCString());
634 bp_name->GetPermissions().SetAllowList(value);
637 bool SBBreakpointName::GetAllowDelete()
639 BreakpointName *bp_name = GetBreakpointName();
642 return bp_name->GetPermissions().GetAllowDelete();
645 void SBBreakpointName::SetAllowDelete(bool value)
647 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
649 BreakpointName *bp_name = GetBreakpointName();
653 log->Printf("Setting allow delete to %u for %s.", value,
654 bp_name->GetName().AsCString());
655 bp_name->GetPermissions().SetAllowDelete(value);
658 bool SBBreakpointName::GetAllowDisable()
660 BreakpointName *bp_name = GetBreakpointName();
663 return bp_name->GetPermissions().GetAllowDisable();
666 void SBBreakpointName::SetAllowDisable(bool value)
668 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
670 BreakpointName *bp_name = GetBreakpointName();
674 log->Printf("Setting allow disable to %u for %s.", value,
675 bp_name->GetName().AsCString());
676 bp_name->GetPermissions().SetAllowDisable(value);
679 lldb_private::BreakpointName *SBBreakpointName::GetBreakpointName() const
683 return m_impl_up->GetBreakpointName();