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 "lldb/Utility/ReproducerInstrumentation.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() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBQueueItem); } 25 26 SBQueueItem::SBQueueItem(const QueueItemSP &queue_item_sp) 27 : m_queue_item_sp(queue_item_sp) { 28 LLDB_RECORD_CONSTRUCTOR(SBQueueItem, (const lldb::QueueItemSP &), 29 queue_item_sp); 30 } 31 32 // Destructor 33 SBQueueItem::~SBQueueItem() { m_queue_item_sp.reset(); } 34 35 bool SBQueueItem::IsValid() const { 36 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, IsValid); 37 return this->operator bool(); 38 } 39 SBQueueItem::operator bool() const { 40 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBQueueItem, operator bool); 41 42 return m_queue_item_sp.get() != nullptr; 43 } 44 45 void SBQueueItem::Clear() { 46 LLDB_RECORD_METHOD_NO_ARGS(void, SBQueueItem, Clear); 47 48 m_queue_item_sp.reset(); 49 } 50 51 void SBQueueItem::SetQueueItem(const QueueItemSP &queue_item_sp) { 52 LLDB_RECORD_METHOD(void, SBQueueItem, SetQueueItem, 53 (const lldb::QueueItemSP &), queue_item_sp); 54 55 m_queue_item_sp = queue_item_sp; 56 } 57 58 lldb::QueueItemKind SBQueueItem::GetKind() const { 59 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::QueueItemKind, SBQueueItem, GetKind); 60 61 QueueItemKind result = eQueueItemKindUnknown; 62 if (m_queue_item_sp) { 63 result = m_queue_item_sp->GetKind(); 64 } 65 return result; 66 } 67 68 void SBQueueItem::SetKind(lldb::QueueItemKind kind) { 69 LLDB_RECORD_METHOD(void, SBQueueItem, SetKind, (lldb::QueueItemKind), kind); 70 71 if (m_queue_item_sp) { 72 m_queue_item_sp->SetKind(kind); 73 } 74 } 75 76 SBAddress SBQueueItem::GetAddress() const { 77 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBQueueItem, GetAddress); 78 79 SBAddress result; 80 if (m_queue_item_sp) { 81 result.SetAddress(m_queue_item_sp->GetAddress()); 82 } 83 return LLDB_RECORD_RESULT(result); 84 } 85 86 void SBQueueItem::SetAddress(SBAddress addr) { 87 LLDB_RECORD_METHOD(void, SBQueueItem, SetAddress, (lldb::SBAddress), addr); 88 89 if (m_queue_item_sp) { 90 m_queue_item_sp->SetAddress(addr.ref()); 91 } 92 } 93 94 SBThread SBQueueItem::GetExtendedBacktraceThread(const char *type) { 95 LLDB_RECORD_METHOD(lldb::SBThread, SBQueueItem, GetExtendedBacktraceThread, 96 (const char *), type); 97 98 SBThread result; 99 if (m_queue_item_sp) { 100 ProcessSP process_sp = m_queue_item_sp->GetProcessSP(); 101 Process::StopLocker stop_locker; 102 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 103 ThreadSP thread_sp; 104 ConstString type_const(type); 105 thread_sp = m_queue_item_sp->GetExtendedBacktraceThread(type_const); 106 if (thread_sp) { 107 // Save this in the Process' ExtendedThreadList so a strong pointer 108 // retains the object 109 process_sp->GetExtendedThreadList().AddThread(thread_sp); 110 result.SetThread(thread_sp); 111 } 112 } 113 } 114 return LLDB_RECORD_RESULT(result); 115 } 116