1 //===-- SBQueueItem.cpp ---------------------------------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/lldb-forward.h" 10 11 #include "SBReproducerPrivate.h" 12 #include "lldb/API/SBAddress.h" 13 #include "lldb/API/SBQueueItem.h" 14 #include "lldb/API/SBThread.h" 15 #include "lldb/Core/Address.h" 16 #include "lldb/Target/Process.h" 17 #include "lldb/Target/QueueItem.h" 18 #include "lldb/Target/Thread.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 // Constructors 24 SBQueueItem::SBQueueItem() : m_queue_item_sp() { 25 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBQueueItem); 26 } 27 28 SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) 29 : m_queue_item_sp(queue_item_sp) { 30 LLDB_RECORD_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &), 31 queue_item_sp); 32 } 33 34 // Destructor 35 SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } 36 37 bool SBQueueItem::IsValid() const { 38 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, IsValid); 39 return this->operator bool(); 40 } 41 SBQueueItem::operator bool() const { 42 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, operator bool); 43 44 return m_queue_item_sp.get() != nullptr; 45 } 46 47 void SBQueueItem::Clear() { 48 LLDB_RECORD_METHOD_NO_ARGS(void, SBQueueItem, Clear); 49 50 m_queue_item_sp.reset(); 51 } 52 53 void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { 54 LLDB_RECORD_METHOD(void, SBQueueItem, SetQueueItem, 55 (const lldb::QueueItemSP &), queue_item_sp); 56 57 m_queue_item_sp = queue_item_sp; 58 } 59 60 lldb::QueueItemKind SBQueueItem::GetKind() const { 61 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::QueueItemKind, SBQueueItem, GetKind); 62 63 QueueItemKind result = eQueueItemKindUnknown; 64 if (m_queue_item_sp) { 65 result = m_queue_item_sp->GetKind(); 66 } 67 return result; 68 } 69 70 void SBQueueItem::SetKind(lldb::QueueItemKind kind) { 71 LLDB_RECORD_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind), kind); 72 73 if (m_queue_item_sp) { 74 m_queue_item_sp->SetKind(kind); 75 } 76 } 77 78 SBAddress SBQueueItem::GetAddress() const { 79 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBQueueItem, GetAddress); 80 81 SBAddress result; 82 if (m_queue_item_sp) { 83 result.SetAddress(&m_queue_item_sp->GetAddress()); 84 } 85 return LLDB_RECORD_RESULT(result); 86 } 87 88 void SBQueueItem::SetAddress(SBAddress addr) { 89 LLDB_RECORD_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress), addr); 90 91 if (m_queue_item_sp) { 92 m_queue_item_sp->SetAddress(addr.ref()); 93 } 94 } 95 96 SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) { 97 LLDB_RECORD_METHOD(lldb::SBThread, SBQueueItem, GetExtendedBacktraceThread, 98 (const char *), type); 99 100 SBThread result; 101 if (m_queue_item_sp) { 102 ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); 103 Process::StopLocker stop_locker; 104 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 105 ThreadSP thread_sp; 106 ConstString type_const(type); 107 thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const); 108 if (thread_sp) { 109 // Save this in the Process' ExtendedThreadList so a strong pointer 110 // retains the object 111 process_sp->GetExtendedThreadList().AddThread(thread_sp); 112 result.SetThread(thread_sp); 113 } 114 } 115 } 116 return LLDB_RECORD_RESULT(result); 117 } 118 119 namespace lldb_private { 120 namespace repro { 121 122 template <> 123 void RegisterMethods<SBQueueItem>(Registry &R) { 124 LLDB_REGISTER_CONSTRUCTOR(SBQueueItem, ()); 125 LLDB_REGISTER_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &)); 126 LLDB_REGISTER_METHOD_CONST(bool, SBQueueItem, IsValid, ()); 127 LLDB_REGISTER_METHOD_CONST(bool, SBQueueItem, operator bool, ()); 128 LLDB_REGISTER_METHOD(void, SBQueueItem, Clear, ()); 129 LLDB_REGISTER_METHOD(void, SBQueueItem, SetQueueItem, 130 (const lldb::QueueItemSP &)); 131 LLDB_REGISTER_METHOD_CONST(lldb::QueueItemKind, SBQueueItem, GetKind, ()); 132 LLDB_REGISTER_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind)); 133 LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBQueueItem, GetAddress, ()); 134 LLDB_REGISTER_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress)); 135 LLDB_REGISTER_METHOD(lldb::SBThread, SBQueueItem, 136 GetExtendedBacktraceThread, (const char *)); 137 } 138 139 } 140 } 141